pub struct GenericRsaPrivateKey<T, M>where
T: UnsignedModularInt + Zeroize,
M: ModulusParams<Modulus = T>,{ /* private fields */ }Expand description
Generic RSA private key — heapless-compatible value type.
Holds the public components plus the secret exponent d — the raw
(n, e, d) form. primes and the precomputed CRT values are
alloc-gated; key generation is behind the keygen feature.
Implementations§
Source§impl<T, M> GenericRsaPrivateKey<T, M>where
T: UnsignedModularInt + Zeroize + RawPrivateKeyConstructible,
M: ModulusParams<Modulus = T>,
impl<T, M> GenericRsaPrivateKey<T, M>where
T: UnsignedModularInt + Zeroize + RawPrivateKeyConstructible,
M: ModulusParams<Modulus = T>,
Sourcepub fn from_public_and_d(
pubkey_components: GenericRsaPublicKey<T, M>,
d: T,
) -> Self
pub fn from_public_and_d( pubkey_components: GenericRsaPublicKey<T, M>, d: T, ) -> Self
Construct from an already-built public key and the private
exponent d. No validation and no CRT precompute — the caller
owns the e·d ≡ 1 mod λ(n) relationship. For validated keys use
the alloc-side RsaPrivateKey::from_components.
Source§impl<T, M> GenericRsaPrivateKey<T, M>where
T: UnsignedModularInt + Zeroize,
M: ModulusParams<Modulus = T>,
impl<T, M> GenericRsaPrivateKey<T, M>where
T: UnsignedModularInt + Zeroize,
M: ModulusParams<Modulus = T>,
Sourcepub fn as_public(&self) -> &GenericRsaPublicKey<T, M>
pub fn as_public(&self) -> &GenericRsaPublicKey<T, M>
Borrow the public-key components.
Source§impl GenericRsaPrivateKey<BoxedUint, BoxedMontyParams>
impl GenericRsaPrivateKey<BoxedUint, BoxedMontyParams>
Sourcepub fn new<R: CryptoRng + ?Sized>(rng: &mut R, bit_size: usize) -> Result<Self>
Available on crate features alloc and keygen only.
pub fn new<R: CryptoRng + ?Sized>(rng: &mut R, bit_size: usize) -> Result<Self>
alloc and keygen only.Generate a new RSA key pair with a modulus of the given bit size using the passed in rng.
§Errors
- If
bit_sizeis lower than the minimum 1024-bits.
Sourcepub fn new_unchecked<R: CryptoRng + ?Sized>(
rng: &mut R,
bit_size: usize,
) -> Result<Self>
Available on crate features alloc and hazmat and keygen only.
pub fn new_unchecked<R: CryptoRng + ?Sized>( rng: &mut R, bit_size: usize, ) -> Result<Self>
alloc and hazmat and keygen only.Generate a new RSA key pair of the given bit size.
#⚠️Warning: Hazmat! This version does not apply minimum key size checks, and as such may generate keys which are insecure!
Sourcepub fn new_with_exp<R: CryptoRng + ?Sized>(
rng: &mut R,
bit_size: usize,
exp: BoxedUint,
) -> Result<RsaPrivateKey>
Available on crate features alloc and keygen only.
pub fn new_with_exp<R: CryptoRng + ?Sized>( rng: &mut R, bit_size: usize, exp: BoxedUint, ) -> Result<RsaPrivateKey>
alloc and keygen only.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 new_with_exp_unchecked<R: CryptoRng + ?Sized>(
rng: &mut R,
bit_size: usize,
exp: BoxedUint,
) -> Result<RsaPrivateKey>
Available on crate features alloc and hazmat and keygen only.
pub fn new_with_exp_unchecked<R: CryptoRng + ?Sized>( rng: &mut R, bit_size: usize, exp: BoxedUint, ) -> Result<RsaPrivateKey>
alloc and hazmat and keygen only.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.
#⚠️Warning: Hazmat! This version does not apply minimum key size checks, and as such may generate keys which are insecure!
Sourcepub fn from_components_with_large_exponent(
n: BoxedUint,
e: BoxedUint,
d: BoxedUint,
primes: Vec<BoxedUint>,
) -> Result<RsaPrivateKey>
Available on crate features alloc and hazmat only.
pub fn from_components_with_large_exponent( n: BoxedUint, e: BoxedUint, d: BoxedUint, primes: Vec<BoxedUint>, ) -> Result<RsaPrivateKey>
alloc and hazmat only.Constructs an RSA key pair from individual components, accepting exponents outside the normal size bounds.
See RsaPrivateKey::from_components for an explanation on the parameters.
§⚠️ Warning: Hazmat!
This method accepts public exponents outside the standard bounds (2 ≤ e ≤ 2^33-1), but still performs full cryptographic validation to ensure the key is mathematically correct (i.e., verifies that de ≡ 1 mod λ(n)).
Note: This method is dangerous as it can be used as a DOS vector if used with untrusted input https://www.imperialviolet.org/2012/03/17/rsados.html
This is intended for interoperating with systems that use non-standard exponents
or loading legacy keys. Use RsaPrivateKey::from_components for standard key
construction.
Sourcepub fn from_components(
n: BoxedUint,
e: BoxedUint,
d: BoxedUint,
primes: Vec<BoxedUint>,
) -> Result<RsaPrivateKey>
Available on crate feature alloc only.
pub fn from_components( n: BoxedUint, e: BoxedUint, d: BoxedUint, primes: Vec<BoxedUint>, ) -> Result<RsaPrivateKey>
alloc only.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: BoxedUint,
q: BoxedUint,
public_exponent: BoxedUint,
) -> Result<RsaPrivateKey>
Available on crate feature alloc only.
pub fn from_p_q( p: BoxedUint, q: BoxedUint, public_exponent: BoxedUint, ) -> Result<RsaPrivateKey>
alloc only.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: Vec<BoxedUint>,
public_exponent: BoxedUint,
) -> Result<RsaPrivateKey>
Available on crate feature alloc only.
pub fn from_primes( primes: Vec<BoxedUint>, public_exponent: BoxedUint, ) -> Result<RsaPrivateKey>
alloc only.Constructs an RSA key pair from its primes.
This will rebuild the private exponent and the modulus.
Sourcepub fn as_public_key(&self) -> &RsaPublicKey
Available on crate feature alloc only.
pub fn as_public_key(&self) -> &RsaPublicKey
alloc only.Get the public key from the private key.
Specific alternative to AsRef::as_ref.
Sourcepub fn to_public_key(&self) -> RsaPublicKey
Available on crate feature alloc only.
pub fn to_public_key(&self) -> RsaPublicKey
alloc only.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<()>
Available on crate feature alloc only.
pub fn precompute(&mut self) -> Result<()>
alloc only.Performs some calculations to speed up private key operations.
Sourcepub fn clear_precomputed(&mut self)
Available on crate feature alloc only.
pub fn clear_precomputed(&mut self)
alloc only.Clears precomputed values by setting to None
Sourcepub fn crt_coefficient(&self) -> Option<BoxedUint>
Available on crate feature alloc only.
pub fn crt_coefficient(&self) -> Option<BoxedUint>
alloc only.Compute CRT coefficient: (1/q) mod p.
Sourcepub fn validate(&self) -> Result<()>
Available on crate feature alloc only.
pub fn validate(&self) -> Result<()>
alloc only.Performs basic sanity checks on the key.
Returns Ok(()) if everything is good, otherwise an appropriate error.
Sourcepub fn decrypt<P: PaddingScheme>(
&self,
padding: P,
ciphertext: &[u8],
) -> Result<Vec<u8>>
Available on crate feature alloc only.
pub fn decrypt<P: PaddingScheme>( &self, padding: P, ciphertext: &[u8], ) -> Result<Vec<u8>>
alloc only.Decrypt the given message.
Sourcepub fn decrypt_blinded<R: CryptoRng + ?Sized, P: PaddingScheme>(
&self,
rng: &mut R,
padding: P,
ciphertext: &[u8],
) -> Result<Vec<u8>>
Available on crate feature alloc only.
pub fn decrypt_blinded<R: CryptoRng + ?Sized, P: PaddingScheme>( &self, rng: &mut R, padding: P, ciphertext: &[u8], ) -> Result<Vec<u8>>
alloc only.Decrypt the given message.
Uses rng to blind the decryption process.
Sourcepub fn sign<S: SignatureScheme>(
&self,
padding: S,
digest_in: &[u8],
) -> Result<Vec<u8>>
Available on crate feature alloc only.
pub fn sign<S: SignatureScheme>( &self, padding: S, digest_in: &[u8], ) -> Result<Vec<u8>>
alloc only.Sign the given digest.
Sourcepub fn sign_with_rng<R: CryptoRng + ?Sized, S: SignatureScheme>(
&self,
rng: &mut R,
padding: S,
digest_in: &[u8],
) -> Result<Vec<u8>>
Available on crate feature alloc only.
pub fn sign_with_rng<R: CryptoRng + ?Sized, S: SignatureScheme>( &self, rng: &mut R, padding: S, digest_in: &[u8], ) -> Result<Vec<u8>>
alloc only.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. UsePss::newfor a standard RSASSA-PSS signature, orPss::new_blindedfor RSA-BSSA blind signatures.
Trait Implementations§
Source§impl<D> AsRef<GenericRsaPrivateKey<BoxedUint, BoxedMontyParams>> for BlindedSigningKey<D>where
D: Digest,
Available on crate feature alloc only.
impl<D> AsRef<GenericRsaPrivateKey<BoxedUint, BoxedMontyParams>> for BlindedSigningKey<D>where
D: Digest,
alloc only.Source§fn as_ref(&self) -> &RsaPrivateKey
fn as_ref(&self) -> &RsaPrivateKey
Source§impl<D, T, M> AsRef<GenericRsaPrivateKey<T, M>> for GenericSigningKey<D, T, M>
impl<D, T, M> AsRef<GenericRsaPrivateKey<T, M>> for GenericSigningKey<D, T, M>
Source§fn as_ref(&self) -> &GenericRsaPrivateKey<T, M>
fn as_ref(&self) -> &GenericRsaPrivateKey<T, M>
Source§impl<D, T, M> AsRef<GenericRsaPrivateKey<T, M>> for GenericSigningKey<D, T, M>
impl<D, T, M> AsRef<GenericRsaPrivateKey<T, M>> for GenericSigningKey<D, T, M>
Source§fn as_ref(&self) -> &GenericRsaPrivateKey<T, M>
fn as_ref(&self) -> &GenericRsaPrivateKey<T, M>
Source§impl<T, M> Clone for GenericRsaPrivateKey<T, M>where
T: UnsignedModularInt + Zeroize + Clone,
M: ModulusParams<Modulus = T> + Clone,
M::MontgomeryForm: Clone,
Available on crate feature alloc only.
impl<T, M> Clone for GenericRsaPrivateKey<T, M>where
T: UnsignedModularInt + Zeroize + Clone,
M: ModulusParams<Modulus = T> + Clone,
M::MontgomeryForm: Clone,
alloc only.Source§impl<T, M> Debug for GenericRsaPrivateKey<T, M>where
T: UnsignedModularInt + Zeroize,
M: ModulusParams<Modulus = T>,
GenericRsaPublicKey<T, M>: Debug,
impl<T, M> Debug for GenericRsaPrivateKey<T, M>where
T: UnsignedModularInt + Zeroize,
M: ModulusParams<Modulus = T>,
GenericRsaPublicKey<T, M>: Debug,
Source§impl<T, M> Drop for GenericRsaPrivateKey<T, M>where
T: UnsignedModularInt + Zeroize,
M: ModulusParams<Modulus = T>,
impl<T, M> Drop for GenericRsaPrivateKey<T, M>where
T: UnsignedModularInt + Zeroize,
M: ModulusParams<Modulus = T>,
Source§impl From<&GenericRsaPrivateKey<BoxedUint, BoxedMontyParams>> for GenericRsaPublicKey<BoxedUint, BoxedMontyParams>
Available on crate feature alloc only.
impl From<&GenericRsaPrivateKey<BoxedUint, BoxedMontyParams>> for GenericRsaPublicKey<BoxedUint, BoxedMontyParams>
alloc only.Source§fn from(private_key: &RsaPrivateKey) -> Self
fn from(private_key: &RsaPrivateKey) -> Self
Source§impl<D> From<GenericRsaPrivateKey<BoxedUint, BoxedMontyParams>> for SigningKey<D>where
D: Digest + AssociatedOid,
Available on crate feature alloc only.
impl<D> From<GenericRsaPrivateKey<BoxedUint, BoxedMontyParams>> for SigningKey<D>where
D: Digest + AssociatedOid,
alloc only.Source§fn from(key: RsaPrivateKey) -> Self
fn from(key: RsaPrivateKey) -> Self
Source§impl<D> From<GenericRsaPrivateKey<BoxedUint, BoxedMontyParams>> for BlindedSigningKey<D>where
D: Digest,
Available on crate feature alloc only.
impl<D> From<GenericRsaPrivateKey<BoxedUint, BoxedMontyParams>> for BlindedSigningKey<D>where
D: Digest,
alloc only.Source§fn from(key: RsaPrivateKey) -> Self
fn from(key: RsaPrivateKey) -> Self
Source§impl<D> From<GenericRsaPrivateKey<BoxedUint, BoxedMontyParams>> for SigningKey<D>where
D: Digest,
Available on crate feature alloc only.
impl<D> From<GenericRsaPrivateKey<BoxedUint, BoxedMontyParams>> for SigningKey<D>where
D: Digest,
alloc only.Source§fn from(key: RsaPrivateKey) -> Self
fn from(key: RsaPrivateKey) -> Self
Source§impl From<GenericRsaPrivateKey<BoxedUint, BoxedMontyParams>> for GenericRsaPublicKey<BoxedUint, BoxedMontyParams>
Available on crate feature alloc only.
impl From<GenericRsaPrivateKey<BoxedUint, BoxedMontyParams>> for GenericRsaPublicKey<BoxedUint, BoxedMontyParams>
alloc only.Source§fn from(private_key: RsaPrivateKey) -> Self
fn from(private_key: RsaPrivateKey) -> Self
Source§impl<T, M> PrivateKeyParts<T> for GenericRsaPrivateKey<T, M>where
T: UnsignedModularInt + Zeroize,
M: ModulusParams<Modulus = T>,
impl<T, M> PrivateKeyParts<T> for GenericRsaPrivateKey<T, M>where
T: UnsignedModularInt + Zeroize,
M: ModulusParams<Modulus = T>,
Source§fn primes(&self) -> &[T]
fn primes(&self) -> &[T]
alloc only.&[] for keys
that don’t store factors.Source§fn dp(&self) -> Option<&T>
fn dp(&self) -> Option<&T>
alloc only.dp = d mod (p - 1) value, if available.
None for keys that didn’t precompute CRT.Source§fn dq(&self) -> Option<&T>
fn dq(&self) -> Option<&T>
alloc only.dq = d mod (q - 1) value, if available.Source§fn qinv(&self) -> Option<&<Self::MontyParams as ModulusParams>::MontgomeryForm>
fn qinv(&self) -> Option<&<Self::MontyParams as ModulusParams>::MontgomeryForm>
alloc only.qinv = q^-1 mod p value, if available.Source§fn p_params(&self) -> Option<&Self::MontyParams>
fn p_params(&self) -> Option<&Self::MontyParams>
alloc only.p, if available.Source§fn q_params(&self) -> Option<&Self::MontyParams>
fn q_params(&self) -> Option<&Self::MontyParams>
alloc only.q, if available.Source§impl<T, M> PublicKeyParts<T> for GenericRsaPrivateKey<T, M>where
T: UnsignedModularInt + Zeroize,
M: ModulusParams<Modulus = T>,
impl<T, M> PublicKeyParts<T> for GenericRsaPrivateKey<T, M>where
T: UnsignedModularInt + Zeroize,
M: ModulusParams<Modulus = T>,
Source§type MontyParams = M
type MontyParams = M
Source§fn n_params(&self) -> &Self::MontyParams
fn n_params(&self) -> &Self::MontyParams
Source§fn size(&self) -> usize
fn size(&self) -> usize
Source§fn n_bits_precision(&self) -> u32
fn n_bits_precision(&self) -> u32
n.Source§impl<T, M> Zeroize for GenericRsaPrivateKey<T, M>where
T: UnsignedModularInt + Zeroize,
M: ModulusParams<Modulus = T>,
impl<T, M> Zeroize for GenericRsaPrivateKey<T, M>where
T: UnsignedModularInt + Zeroize,
M: ModulusParams<Modulus = T>,
impl<T, M> ZeroizeOnDrop for GenericRsaPrivateKey<T, M>where
T: UnsignedModularInt + Zeroize,
M: ModulusParams<Modulus = T>,
Auto Trait Implementations§
impl<T, M> Freeze for GenericRsaPrivateKey<T, M>
impl<T, M> RefUnwindSafe for GenericRsaPrivateKey<T, M>
impl<T, M> Send for GenericRsaPrivateKey<T, M>
impl<T, M> Sync for GenericRsaPrivateKey<T, M>
impl<T, M> Unpin for GenericRsaPrivateKey<T, M>
impl<T, M> UnsafeUnpin for GenericRsaPrivateKey<T, M>
impl<T, M> UnwindSafe for GenericRsaPrivateKey<T, M>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DecodePrivateKey for Twhere
T: for<'a> TryFrom<PrivateKeyInfo<AnyRef<'a>, &'a OctetStringRef, BitStringRef<'a>>, Error = Error>,
impl<T> DecodePrivateKey for Twhere
T: for<'a> TryFrom<PrivateKeyInfo<AnyRef<'a>, &'a OctetStringRef, BitStringRef<'a>>, Error = Error>,
Source§fn from_pkcs8_der(bytes: &[u8]) -> Result<T, Error>
fn from_pkcs8_der(bytes: &[u8]) -> Result<T, Error>
Source§fn from_pkcs8_pem(s: &str) -> Result<Self, Error>
fn from_pkcs8_pem(s: &str) -> Result<Self, Error>
pem only.