pub struct GenericRsaPublicKey<T, M>where
T: UnsignedModularInt,
M: ModulusParams<Modulus = T>,{ /* private fields */ }Expand description
Represents the public part of an RSA key.
Implementations§
Source§impl<T, M> GenericRsaPublicKey<T, M>where
T: UnsignedModularInt,
M: ModulusParams<Modulus = T>,
impl<T, M> GenericRsaPublicKey<T, M>where
T: UnsignedModularInt,
M: ModulusParams<Modulus = T>,
Sourcepub fn from_components(n: T, e: T, n_params: M) -> Result<Self>
pub fn from_components(n: T, e: T, n_params: M) -> Result<Self>
Create a public key from already-validated components and modulus parameters.
This is intended for alternate bigint backends that prepare their own
modular arithmetic context outside the BoxedUint constructors.
Source§impl<T, M> GenericRsaPublicKey<T, M>where
T: UnsignedModularInt,
M: ModulusParams<Modulus = T>,
impl<T, M> GenericRsaPublicKey<T, M>where
T: UnsignedModularInt,
M: ModulusParams<Modulus = T>,
Sourcepub fn encrypt<R: CryptoRng + ?Sized, P: PaddingScheme>(
&self,
rng: &mut R,
padding: P,
msg: &[u8],
) -> Result<Vec<u8>>
Available on crate feature alloc only.
pub fn encrypt<R: CryptoRng + ?Sized, P: PaddingScheme>( &self, rng: &mut R, padding: P, msg: &[u8], ) -> Result<Vec<u8>>
alloc only.Encrypt the given message.
Sourcepub fn verify<S: SignatureScheme>(
&self,
scheme: S,
hashed: &[u8],
sig: &[u8],
) -> Result<()>
pub fn verify<S: SignatureScheme>( &self, scheme: S, hashed: &[u8], sig: &[u8], ) -> Result<()>
Verify a signed message.
hashed must be the result of hashing the input using the hashing function
passed in through hash.
If the message is valid Ok(()) is returned, otherwise an Err indicating failure.
Source§impl GenericRsaPublicKey<BoxedUint, BoxedMontyParams>
impl GenericRsaPublicKey<BoxedUint, BoxedMontyParams>
Sourcepub const MIN_PUB_EXPONENT: u64 = 2
Available on crate feature alloc only.
pub const MIN_PUB_EXPONENT: u64 = 2
alloc only.Minimum value of the public exponent e.
Sourcepub const MAX_PUB_EXPONENT: u64
Available on crate feature alloc only.
pub const MAX_PUB_EXPONENT: u64
alloc only.Maximum value of the public exponent e.
Very large public exponents are a potential denial-of-service vector (a.k.a. “RSADoS”) because they increase the amount of work required for e.g. signature verification. See:
https://www.imperialviolet.org/2012/03/17/rsados.html
The particular constant below has been chosen to align with ring where this value was selected based on the history of this particular issue, API compatibility concerns, and benchmark-driven evaluation. See RustCrypto/RSA#155.
If for some reason you have a legitimate reason to use keys with public exponents larger than this value, use the special APIs:
- [
RsaPublicKey::new_with_large_exp] RsaPrivateKey::from_components_with_large_exponent
Sourcepub const MAX_SIZE: usize = 8192
Available on crate feature alloc only.
pub const MAX_SIZE: usize = 8192
alloc only.Maximum size of the modulus n in bits.
Sourcepub fn new(n: BoxedUint, e: BoxedUint) -> Result<Self>
Available on crate feature alloc only.
pub fn new(n: BoxedUint, e: BoxedUint) -> Result<Self>
alloc only.Create a new public key from its components.
This function accepts public keys with a modulus size up to 8192-bits,
i.e. RsaPublicKey::MAX_SIZE.
Sourcepub fn new_with_max_size(
n: BoxedUint,
e: BoxedUint,
max_size: usize,
) -> Result<Self>
Available on crate feature alloc only.
pub fn new_with_max_size( n: BoxedUint, e: BoxedUint, max_size: usize, ) -> Result<Self>
alloc only.Create a new public key from its components.
Sourcepub fn new_unchecked(n: BoxedUint, e: BoxedUint) -> Self
Available on crate feature alloc only.
pub fn new_unchecked(n: BoxedUint, e: BoxedUint) -> Self
alloc only.Create a new public key, bypassing checks around the modulus and public exponent size.
This method is not recommended, and only intended for unusual use cases.
Most applications should use RsaPublicKey::new or
RsaPublicKey::new_with_max_size instead.
Trait Implementations§
Source§impl AsRef<GenericRsaPublicKey<BoxedUint, BoxedMontyParams>> for RsaPrivateKey
Available on crate feature private-key only.
impl AsRef<GenericRsaPublicKey<BoxedUint, BoxedMontyParams>> for RsaPrivateKey
private-key only.Source§fn as_ref(&self) -> &RsaPublicKey
fn as_ref(&self) -> &RsaPublicKey
Source§impl<D, T, M> AsRef<GenericRsaPublicKey<T, M>> for GenericVerifyingKey<D, T, M>where
D: Digest,
T: UnsignedModularInt,
M: ModulusParams<Modulus = T>,
impl<D, T, M> AsRef<GenericRsaPublicKey<T, M>> for GenericVerifyingKey<D, T, M>where
D: Digest,
T: UnsignedModularInt,
M: ModulusParams<Modulus = T>,
Source§fn as_ref(&self) -> &GenericRsaPublicKey<T, M>
fn as_ref(&self) -> &GenericRsaPublicKey<T, M>
Source§impl<D, T, M> AsRef<GenericRsaPublicKey<T, M>> for GenericVerifyingKey<D, T, M>where
D: Digest,
T: UnsignedModularInt,
M: ModulusParams<Modulus = T>,
impl<D, T, M> AsRef<GenericRsaPublicKey<T, M>> for GenericVerifyingKey<D, T, M>where
D: Digest,
T: UnsignedModularInt,
M: ModulusParams<Modulus = T>,
Source§fn as_ref(&self) -> &GenericRsaPublicKey<T, M>
fn as_ref(&self) -> &GenericRsaPublicKey<T, M>
Source§impl<T, M> Clone for GenericRsaPublicKey<T, M>
impl<T, M> Clone for GenericRsaPublicKey<T, M>
Source§fn clone(&self) -> GenericRsaPublicKey<T, M>
fn clone(&self) -> GenericRsaPublicKey<T, M>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T, M> Debug for GenericRsaPublicKey<T, M>
impl<T, M> Debug for GenericRsaPublicKey<T, M>
Source§impl From<&RsaPrivateKey> for GenericRsaPublicKey<BoxedUint, BoxedMontyParams>
Available on crate feature private-key only.
impl From<&RsaPrivateKey> for GenericRsaPublicKey<BoxedUint, BoxedMontyParams>
private-key only.Source§fn from(private_key: &RsaPrivateKey) -> Self
fn from(private_key: &RsaPrivateKey) -> Self
Source§impl<D, T, M> From<GenericRsaPublicKey<T, M>> for GenericVerifyingKey<D, T, M>
impl<D, T, M> From<GenericRsaPublicKey<T, M>> for GenericVerifyingKey<D, T, M>
Source§fn from(key: GenericRsaPublicKey<T, M>) -> Self
fn from(key: GenericRsaPublicKey<T, M>) -> Self
Source§impl<D, T, M> From<GenericRsaPublicKey<T, M>> for GenericVerifyingKey<D, T, M>where
D: Digest,
T: UnsignedModularInt,
M: ModulusParams<Modulus = T>,
impl<D, T, M> From<GenericRsaPublicKey<T, M>> for GenericVerifyingKey<D, T, M>where
D: Digest,
T: UnsignedModularInt,
M: ModulusParams<Modulus = T>,
Source§fn from(key: GenericRsaPublicKey<T, M>) -> Self
fn from(key: GenericRsaPublicKey<T, M>) -> Self
Source§impl<D, T, M> From<GenericVerifyingKey<D, T, M>> for GenericRsaPublicKey<T, M>where
D: Digest,
T: UnsignedModularInt,
M: ModulusParams<Modulus = T>,
impl<D, T, M> From<GenericVerifyingKey<D, T, M>> for GenericRsaPublicKey<T, M>where
D: Digest,
T: UnsignedModularInt,
M: ModulusParams<Modulus = T>,
Source§fn from(key: GenericVerifyingKey<D, T, M>) -> Self
fn from(key: GenericVerifyingKey<D, T, M>) -> Self
Source§impl<D, T, M> From<GenericVerifyingKey<D, T, M>> for GenericRsaPublicKey<T, M>where
D: Digest,
T: UnsignedModularInt,
M: ModulusParams<Modulus = T>,
impl<D, T, M> From<GenericVerifyingKey<D, T, M>> for GenericRsaPublicKey<T, M>where
D: Digest,
T: UnsignedModularInt,
M: ModulusParams<Modulus = T>,
Source§fn from(key: GenericVerifyingKey<D, T, M>) -> Self
fn from(key: GenericVerifyingKey<D, T, M>) -> Self
Source§impl From<RsaPrivateKey> for GenericRsaPublicKey<BoxedUint, BoxedMontyParams>
Available on crate feature private-key only.
impl From<RsaPrivateKey> for GenericRsaPublicKey<BoxedUint, BoxedMontyParams>
private-key only.Source§fn from(private_key: RsaPrivateKey) -> Self
fn from(private_key: RsaPrivateKey) -> Self
Source§impl<T, M> Hash for GenericRsaPublicKey<T, M>where
T: UnsignedModularInt,
M: ModulusParams<Modulus = T>,
impl<T, M> Hash for GenericRsaPublicKey<T, M>where
T: UnsignedModularInt,
M: ModulusParams<Modulus = T>,
Source§impl<T, M> PartialEq for GenericRsaPublicKey<T, M>where
T: UnsignedModularInt + PartialEq,
M: ModulusParams<Modulus = T>,
impl<T, M> PartialEq for GenericRsaPublicKey<T, M>where
T: UnsignedModularInt + PartialEq,
M: ModulusParams<Modulus = T>,
Source§fn eq(&self, other: &GenericRsaPublicKey<T, M>) -> bool
fn eq(&self, other: &GenericRsaPublicKey<T, M>) -> bool
self and other values to be equal, and is used by ==.Source§impl<T, M> PublicKeyParts<T> for GenericRsaPublicKey<T, M>where
T: UnsignedModularInt,
M: ModulusParams<Modulus = T>,
impl<T, M> PublicKeyParts<T> for GenericRsaPublicKey<T, M>where
T: UnsignedModularInt,
M: ModulusParams<Modulus = T>,
Source§type MontyParams = M
type MontyParams = M
Source§fn size(&self) -> usize
fn size(&self) -> usize
Source§fn n_bits_precision(&self) -> u32
fn n_bits_precision(&self) -> u32
n.impl<T, M> Eq for GenericRsaPublicKey<T, M>where
T: UnsignedModularInt + Eq,
M: ModulusParams<Modulus = T>,
Auto Trait Implementations§
impl<T, M> Freeze for GenericRsaPublicKey<T, M>
impl<T, M> RefUnwindSafe for GenericRsaPublicKey<T, M>where
T: RefUnwindSafe,
M: RefUnwindSafe,
impl<T, M> Send for GenericRsaPublicKey<T, M>
impl<T, M> Sync for GenericRsaPublicKey<T, M>
impl<T, M> Unpin for GenericRsaPublicKey<T, M>
impl<T, M> UnsafeUnpin for GenericRsaPublicKey<T, M>where
T: UnsafeUnpin,
M: UnsafeUnpin,
impl<T, M> UnwindSafe for GenericRsaPublicKey<T, M>where
T: UnwindSafe,
M: UnwindSafe,
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> DecodePublicKey for T
impl<T> DecodePublicKey for T
Source§fn from_public_key_der(bytes: &[u8]) -> Result<T, Error>
fn from_public_key_der(bytes: &[u8]) -> Result<T, Error>
SubjectPublicKeyInfo]
(binary format). Read moreSource§fn from_public_key_pem(s: &str) -> Result<Self, Error>
fn from_public_key_pem(s: &str) -> Result<Self, Error>
pem only.SubjectPublicKeyInfo]. Read more