opentitanlib::crypto::rsa

Struct RsaPublicKey

Source
pub struct RsaPublicKey { /* private fields */ }
Expand description

RSA Public Key used in OpenTitan signing operations.

This is a wrapper for handling RSA public keys as they’re used in OpenTitan images.

Implementations§

Source§

impl RsaPublicKey

Source

pub fn new(n: Modulus) -> Result<RsaPublicKey>

Construct a new public key with modulus = n and e = 65537.

Source

pub fn from_pkcs1_der_file<P: Into<PathBuf>>( der_file: P, ) -> Result<RsaPublicKey>

Construct a new public key from a PKCS1 encoded DER file.

Source

pub fn to_pkcs1_der_file<P: Into<PathBuf>>(&self, der_file: P) -> Result<()>

Write public key to a PKCS1 encoded DER file.

Source

pub fn from_private_key(private_key: &RsaPrivateKey) -> Self

Extract the public key components from a given private key.

Source

pub fn modulus_num_bits(&self) -> usize

Bit length for this key.

Source

pub fn modulus(&self) -> Modulus

Modulus for this key.

Source

pub fn exponent(&self) -> Exponent

Public exponent for this key.

Source

pub fn n0_inv(&self) -> Result<N0Inv>

Computes the OTBN montgomery parameter: -1 / n[0] mod 2^256.

Source

pub fn rr(&self) -> RR

The montgomery parameter RR.

Source

pub fn verify(&self, digest: &Sha256Digest, signature: &Signature) -> Result<()>

Verify a signature is valid for a given digest under this key.

Methods from Deref<Target = RsaPublicKey>§

pub fn encrypt<R, P>( &self, rng: &mut R, padding: P, msg: &[u8], ) -> Result<Vec<u8>, Error>
where R: CryptoRngCore, P: PaddingScheme,

Encrypt the given message.

pub fn verify<S>( &self, scheme: S, hashed: &[u8], sig: &[u8], ) -> Result<(), Error>
where S: SignatureScheme,

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.

pub const MIN_PUB_EXPONENT: u64 = 2u64

pub const MAX_PUB_EXPONENT: u64 = 8_589_934_591u64

pub const MAX_SIZE: usize = 4_096usize

Trait Implementations§

Source§

impl Debug for RsaPublicKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for RsaPublicKey

Source§

type Target = RsaPublicKey

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl TryFrom<&RsaPublicKey> for RsaRawPublicKey

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(v: &RsaPublicKey) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<RsaPublicKey> for RsaRawPublicKey

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(v: RsaPublicKey) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V