embassy-nrf

Crates

git

Versions

nrf9151-s

Flavors

Skip to main content

Pka

Struct Pka 

Source
pub struct Pka<'d, M: Mode> { /* private fields */ }
Expand description

Driver for the public key accelerator.

See the module documentation.

Implementations§

Source§

impl<'d> Pka<'d, Blocking>

Source

pub fn new_blocking(_peri: Peri<'d, CRYPTO_PKA>) -> Self

Creates a new blocking PKA driver.

Source§

impl<'d, M: Mode> Pka<'d, M>

Source

pub fn blocking_mod_exp( &mut self, base: &[u8], exponent: &[u8], modulus: &[u8], output: &mut [u8], ) -> Result<(), Error>

Computes base ^ exponent mod modulus, the RSA primitive.

With the public exponent this is the RSA public key operation. With the private exponent it is the private key operation. For the latter, prefer Self::blocking_rsa_crt when the CRT parameters are available. It is about four times faster.

  • The modulus must be odd.
  • base and exponent must not be longer than the modulus.
  • base must be smaller than the modulus.
  • output must be as long as the modulus. The result is padded with zeros on the left.

This function does not apply or check any padding scheme. base must already be the encoded message or signature representative.

Errors: InvalidLength, InvalidModulus.

Source

pub fn blocking_rsa_crt( &mut self, input: &[u8], p: &[u8], q: &[u8], dp: &[u8], dq: &[u8], qinv: &[u8], output: &mut [u8], ) -> Result<(), Error>

Computes the RSA private key operation using the Chinese remainder theorem.

  • p, q: the prime factors of the modulus.
  • dp, dq: the private exponent reduced modulo p - 1 and q - 1.
  • qinv: the inverse of q modulo p.

All five must have the same length, half the modulus length. input and output must be as long as the modulus.

On the CryptoCell this operation is limited to a 2560-bit modulus, where Self::blocking_mod_exp still works up to 4096 bits.

Errors: InvalidLength, InvalidModulus.

Source

pub fn blocking_ecc_mul( &mut self, curve: &Curve, scalar: &[u8], point: Point<'_>, output: PointMut<'_>, ) -> Result<(), Error>

Multiplies a curve point by a scalar, the ECDH primitive.

For ECDH, multiply the peer’s public key by your private key. The shared secret is the X coordinate of the result. Hash it before using it as a key.

  • The point must be on the curve, which is checked: a point off the curve would leak the scalar through the result.
  • The scalar must be nonzero and smaller than the curve order.

Errors: InvalidLength, InvalidScalar, InvalidPoint.

Source

pub fn blocking_public_key( &mut self, curve: &Curve, private_key: &[u8], output: PointMut<'_>, ) -> Result<(), Error>

Derives the public key of a private key.

The private key must be nonzero and smaller than the curve order.

Errors: InvalidLength, InvalidScalar.

Source

pub fn blocking_point_check( &mut self, curve: &Curve, point: Point<'_>, ) -> Result<(), Error>

Checks that a point is on the curve and is not the point at infinity.

Do this on every public key that comes from an untrusted source, before using it.

Errors: InvalidLength, InvalidPoint.

Source

pub fn blocking_ecdsa_sign<RM: Mode>( &mut self, curve: &Curve, private_key: &[u8], hash: &[u8], rng: &mut Rng<'_, RM>, signature: SignatureMut<'_>, ) -> Result<(), Error>

Signs a hash with ECDSA.

  • hash is the hash of the message. It may have any length. ECDSA uses its leftmost Curve::order_bits bits.
  • The nonce is drawn from rng, uniformly in 1..n by rejection sampling, and never leaves the driver.

Errors: InvalidLength, InvalidScalar.

Source

pub fn blocking_ecdsa_sign_with_nonce( &mut self, curve: &Curve, private_key: &[u8], k: &[u8], hash: &[u8], signature: SignatureMut<'_>, ) -> Result<(), Error>

Signs a hash with ECDSA and a caller-supplied nonce.

Prefer Self::blocking_ecdsa_sign, which draws the nonce itself. This is for deterministic signatures (RFC 6979) and known-answer tests.

  • hash is the hash of the message. It may have any length. ECDSA uses its leftmost Curve::order_bits bits.
  • k is the nonce. It must be uniformly random, nonzero and smaller than the curve order, fresh for every signature, and secret: signing two messages with the same k, or with a predictable or biased one, reveals the private key.

Errors: InvalidLength, InvalidScalar, and RetryWithNewK if k happens to produce an unusable signature. This is vanishingly unlikely. Draw a new k and sign again.

Source

pub fn blocking_ecdsa_verify( &mut self, curve: &Curve, public_key: Point<'_>, signature: Signature<'_>, hash: &[u8], ) -> Result<(), Error>

Verifies an ECDSA signature over a hash.

  • hash is the hash of the message. It may have any length. ECDSA uses its leftmost Curve::order_bits bits.
  • The public key must be on the curve. This is not checked. Use Self::blocking_point_check on the first use of a key from an untrusted source.

Errors: InvalidLength, and InvalidSignature if the signature does not verify.

Auto Trait Implementations§

§

impl<'d, M> Freeze for Pka<'d, M>
where PhantomData<(&'d (), M)>: Freeze,

§

impl<'d, M> RefUnwindSafe for Pka<'d, M>
where PhantomData<(&'d (), M)>: RefUnwindSafe,

§

impl<'d, M> Send for Pka<'d, M>
where PhantomData<(&'d (), M)>: Send,

§

impl<'d, M> Sync for Pka<'d, M>
where PhantomData<(&'d (), M)>: Sync,

§

impl<'d, M> Unpin for Pka<'d, M>
where PhantomData<(&'d (), M)>: Unpin,

§

impl<'d, M> UnsafeUnpin for Pka<'d, M>
where PhantomData<(&'d (), M)>: UnsafeUnpin,

§

impl<'d, M> UnwindSafe for Pka<'d, M>
where PhantomData<(&'d (), M)>: UnwindSafe,

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> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

Source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
Source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

Source§

fn lossy_into(self) -> Dst

Performs the conversion.
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> StrictAs for T

Source§

fn strict_as<Dst>(self) -> Dst
where T: StrictCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> StrictCastFrom<Src> for Dst
where Src: StrictCast<Dst>,

Source§

fn strict_cast_from(src: Src) -> Dst

Casts the value.
Source§

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

Source§

type Error = !

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.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.