pub struct RsaPrivateKey<T>where
T: UnsignedModularInt,{ /* private fields */ }Expand description
Represents a whole RSA key, public and private parts.
Implementations§
Source§impl<T: UnsignedModularInt> RsaPrivateKey<T>
impl<T: UnsignedModularInt> RsaPrivateKey<T>
Sourcepub fn new<R: CryptoRngCore>(
rng: &mut R,
bit_size: usize,
) -> Result<RsaPrivateKey<T>>
pub fn new<R: CryptoRngCore>( rng: &mut R, bit_size: usize, ) -> Result<RsaPrivateKey<T>>
Generate a new Rsa key pair of the given bit size using the passed in rng.
Sourcepub fn new_with_exp<R: CryptoRngCore>(
rng: &mut R,
bit_size: usize,
exp: T,
) -> Result<RsaPrivateKey<T>>
pub fn new_with_exp<R: CryptoRngCore>( rng: &mut R, bit_size: usize, exp: T, ) -> Result<RsaPrivateKey<T>>
Generate a new RSA key pair of the given bit size and the public exponent
using the passed in rng.
Unless you have specific needs, you should use RsaPrivateKey::new instead.
Sourcepub fn from_components(n: T, e: T, d: T, primes: [T; 4]) -> Result<Self>
pub fn from_components(n: T, e: T, d: T, primes: [T; 4]) -> Result<Self>
Constructs an RSA key pair from individual components:
n: RSA moduluse: public exponent (i.e. encrypting exponent)d: private exponent (i.e. decrypting exponent)primes: prime factors ofn: typically two primespandq. More than two primes can be provided for multiprime RSA, however this is generally not recommended. If noprimesare provided, a prime factor recovery algorithm will be employed to attempt to recover the factors (as described in NIST SP 800-56B Revision 2 Appendix C.2). This algorithm only works if there are just two prime factorspandq(as opposed to multiprime), andeis between 2^16 and 2^256.
Sourcepub fn from_p_q(p: T, q: T, public_exponent: T) -> Result<Self>
pub fn from_p_q(p: T, q: T, public_exponent: T) -> Result<Self>
Constructs an RSA key pair from its two primes p and q.
This will rebuild the private exponent and the modulus.
Private exponent will be rebuilt using the method defined in NIST 800-56B Section 6.2.1.
Sourcepub fn from_primes(primes: [T; 4], public_exponent: T) -> Result<Self>
pub fn from_primes(primes: [T; 4], public_exponent: T) -> Result<Self>
Constructs an RSA key pair from its primes.
This will rebuild the private exponent and the modulus.
Sourcepub fn to_public_key(&self) -> RsaPublicKey<T>
pub fn to_public_key(&self) -> RsaPublicKey<T>
Get the public key from the private key, cloning n and e.
Generally this is not needed since RsaPrivateKey implements the PublicKey trait,
but it can occasionally be useful to discard the private information entirely.
Sourcepub fn precompute(&mut self) -> Result<()>
pub fn precompute(&mut self) -> Result<()>
Performs some calculations to speed up private key operations.
Sourcepub fn clear_precomputed(&mut self)
pub fn clear_precomputed(&mut self)
Clears precomputed values by setting to None
Sourcepub fn crt_coefficient(&self) -> Option<T>
pub fn crt_coefficient(&self) -> Option<T>
Compute CRT coefficient: (1/q) mod p.
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Performs basic sanity checks on the key.
Returns Ok(()) if everything is good, otherwise an appropriate error.
Sourcepub fn decrypt<P: PaddingScheme<T>>(
&self,
padding: P,
ciphertext: &[u8],
storage: &mut [u8],
) -> Result<&[u8]>
pub fn decrypt<P: PaddingScheme<T>>( &self, padding: P, ciphertext: &[u8], storage: &mut [u8], ) -> Result<&[u8]>
Decrypt the given message.
Sourcepub fn decrypt_blinded<R: CryptoRngCore, P: PaddingScheme<T>>(
&self,
rng: &mut R,
padding: P,
ciphertext: &[u8],
storage: &mut [u8],
) -> Result<&[u8]>
pub fn decrypt_blinded<R: CryptoRngCore, P: PaddingScheme<T>>( &self, rng: &mut R, padding: P, ciphertext: &[u8], storage: &mut [u8], ) -> Result<&[u8]>
Decrypt the given message.
Uses rng to blind the decryption process.
Sourcepub fn sign<S: SignatureScheme<T>>(
&self,
padding: S,
digest_in: &[u8],
storage: &mut [u8],
) -> Result<&[u8]>
pub fn sign<S: SignatureScheme<T>>( &self, padding: S, digest_in: &[u8], storage: &mut [u8], ) -> Result<&[u8]>
Sign the given digest.
Sourcepub fn sign_with_rng<R: CryptoRngCore, S: SignatureScheme<T>>(
&self,
rng: &mut R,
padding: S,
digest_in: &[u8],
storage: &mut [u8],
) -> Result<&[u8]>
pub fn sign_with_rng<R: CryptoRngCore, S: SignatureScheme<T>>( &self, rng: &mut R, padding: S, digest_in: &[u8], storage: &mut [u8], ) -> Result<&[u8]>
Sign the given digest using the provided rng, which is used in the
following ways depending on the SignatureScheme:
Pkcs1v15Signpadding: uses the RNG to mask the private key operation with random blinding, which helps mitigate sidechannel attacks.Pssalways requires randomness. Use [Pss::new][crate::Pss::new] for a standard RSASSA-PSS signature, or [Pss::new_blinded][crate::Pss::new_blinded] for RSA-BSSA blind signatures.
Trait Implementations§
Source§impl<D, T> AsRef<RsaPrivateKey<T>> for BlindedSigningKey<D, T>where
D: Digest,
T: UnsignedModularInt,
impl<D, T> AsRef<RsaPrivateKey<T>> for BlindedSigningKey<D, T>where
D: Digest,
T: UnsignedModularInt,
Source§fn as_ref(&self) -> &RsaPrivateKey<T>
fn as_ref(&self) -> &RsaPrivateKey<T>
Source§impl<D, T> AsRef<RsaPrivateKey<T>> for SigningKey<D, T>where
T: UnsignedModularInt,
impl<D, T> AsRef<RsaPrivateKey<T>> for SigningKey<D, T>where
T: UnsignedModularInt,
Source§fn as_ref(&self) -> &RsaPrivateKey<T>
fn as_ref(&self) -> &RsaPrivateKey<T>
Source§impl<T: UnsignedModularInt> AsRef<RsaPublicKey<T>> for RsaPrivateKey<T>
impl<T: UnsignedModularInt> AsRef<RsaPublicKey<T>> for RsaPrivateKey<T>
Source§fn as_ref(&self) -> &RsaPublicKey<T>
fn as_ref(&self) -> &RsaPublicKey<T>
Source§impl<T> Clone for RsaPrivateKey<T>where
T: UnsignedModularInt + Clone,
impl<T> Clone for RsaPrivateKey<T>where
T: UnsignedModularInt + Clone,
Source§fn clone(&self) -> RsaPrivateKey<T>
fn clone(&self) -> RsaPrivateKey<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more