Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Marcus Hoffmann
nettle
Commits
2076e5d9
Commit
2076e5d9
authored
Nov 23, 2015
by
Niels Möller
Browse files
Document rsa_encrypt, rsa_decrypt and rsa_decrypt_tr. Text contributed by Andy Lawrence.
parent
d821bc43
Changes
2
Hide whitespace changes
Inline
Side-by-side
ChangeLog
View file @
2076e5d9
2015-11-23 Niels Möller <nisse@lysator.liu.se>
* nettle.texinfo: Document rsa_encrypt, rsa_decrypt and
rsa_decrypt_tr. Text contributed by Andy Lawrence.
2015-11-15 Niels Möller <nisse@lysator.liu.se>
* rsa.h (_rsa_blind, _rsa_unblind): Mark as deprecated.
...
...
nettle.texinfo
View file @
2076e5d9
...
...
@@ -3693,6 +3693,32 @@ point to a digest of size @code{MD5_DIGEST_SIZE},
@code
{
SHA1
_
DIGEST
_
SIZE
}
, or @code
{
SHA256
_
DIGEST
_
SIZE
}
, respectively.
@end deftypefun
The RSA algorithm can also be used for encryption. RSA encryption uses
the public key @code
{
(n,e)
}
to compute the ciphertext @code
{
m
^
e mod n
}
.
The PKCS#1 padding scheme will use at least 8 random and non-zero
octets, using @var
{
m
}
of the form @code
{
[00 02 padding 00 plaintext]
}
.
It is required that @code
{
m < n
}
, and therefor the plaintext must be
smaller than the octet size of the modulo @code
{
n
}
, with some margin.
The following function is used to encrypt a clear text message using RSA.
@deftypefun int rsa
_
encrypt (const struct rsa
_
public
_
key *@var
{
key
}
, void *@var
{
random
_
ctx
}
, nettle
_
random
_
func *@var
{
random
}
, size
_
t @var
{
length
}
, const uint8
_
t *@var
{
cleartext
}
, mpz
_
t @var
{
ciphertext
}
)
Returns 1 on success, 0 on failure. If the message is too long then this
will lead to a failure.
@end deftypefun
The following function is used to decrypt a cipher text message using RSA.
@deftypefun int rsa
_
decrypt (const struct rsa
_
private
_
key *@var
{
key
}
, size
_
t *@var
{
length
}
, uint8
_
t *@var
{
cleartext
}
, const mpz
_
t @var
{
ciphertext
}
)
Returns 1 on success, 0 on failure. Causes of failure include decryption
failing or the resulting message being to large. The message buffer
pointed to by @var
{
cleartext
}
must be of size *@var
{
length
}
. After
decryption, *@var
{
length
}
will be updated with the size of the
message.
@end deftypefun
There is also a timing resistant version of decryption that utilizes
randomized RSA blinding.
@deftypefun int rsa
_
decrypt
_
tr (const struct rsa
_
public
_
key *@var
{
pub
}
, const struct rsa
_
private
_
key *@var
{
key
}
, void *@var
{
random
_
ctx
}
, nettle
_
random
_
func *@var
{
random
}
, size
_
t *@var
{
length
}
, uint8
_
t *@var
{
message
}
, const mpz
_
t @var
{
ciphertext
}
)
Returns 1 on success, 0 on failure.
@end deftypefun
If you need to use the @acronym
{
RSA
}
trapdoor, the private key, in a way
that isn't supported by the above functions Nettle also includes a
function that computes @code
{
x
^
d mod n
}
and nothing more, using the
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment