Struct nettle::rsa::PrivateKey
source · pub struct PrivateKey { /* private fields */ }
Expand description
A private RSA key.
Implementations§
source§impl PrivateKey
impl PrivateKey
sourcepub fn new<'a, O: Into<Option<&'a [u8]>>>(
d: &[u8],
p: &[u8],
q: &[u8],
inv: O
) -> Result<Self>
pub fn new<'a, O: Into<Option<&'a [u8]>>>( d: &[u8], p: &[u8], q: &[u8], inv: O ) -> Result<Self>
Creates a new private key with the private exponent d
and
the two primes p
/q
.
If the inverse inv
for q
in Z_p is None
the function
computes it.
Notes
This function does time-variable computation on the private
key that may leak it. See new_crt
for a time-constant way to
create a PrivateKey.
sourcepub fn new_crt<'a, O: Into<Option<&'a [u8]>>>(
dp: &[u8],
dq: &[u8],
p: &[u8],
q: &[u8],
inv: O
) -> Result<Self>
pub fn new_crt<'a, O: Into<Option<&'a [u8]>>>( dp: &[u8], dq: &[u8], p: &[u8], q: &[u8], inv: O ) -> Result<Self>
Creates a new private key with the two primes p
/q
.
The private exponent d
is given as dp = d mod p - 1
and
dq = d mod q - 1
. If the inverse inv
of q
in Z_p is
None
the function computes it.
Notes
If inv
is None
the function does time-variable computation
on the private key that may leak it.
sourcepub fn public_key(&self) -> Result<PublicKey>
pub fn public_key(&self) -> Result<PublicKey>
Computes the public key to this private key.
This only works if the private key was created with new
instead of new_crt
.
Notes
This function does time-variable computation on the private key that may leak it.
sourcepub fn as_rfc4880(&self) -> (Box<[u8]>, Box<[u8]>, Box<[u8]>)
pub fn as_rfc4880(&self) -> (Box<[u8]>, Box<[u8]>, Box<[u8]>)
Returns the tuple a
, b
, c
.
a
and b
are the two RSA primes p
/q
with a
< b
and
c = a^-1 mod b
.