embassy-stm32

Crates

git

Versions

stm32wba55hg

Flavors

Pka

Struct Pka 

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

PKA driver

Implementations§

Source§

impl<'d, T: Instance> Pka<'d, T>

Source

pub fn new_blocking( peripheral: Peri<'d, T>, _irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd, ) -> Self

Create a new PKA driver

Source

pub fn ecdsa_verify( &mut self, curve: &EcdsaCurveParams, public_key: &EcdsaPublicKey<'_>, signature: &EcdsaSignature<'_>, message_hash: &[u8], ) -> Result<bool, Error>

Verify an ECDSA signature

Returns Ok(true) if signature is valid, Ok(false) if invalid.

Source

pub fn ecdsa_sign( &mut self, curve: &EcdsaCurveParams, private_key: &[u8], k: &[u8], message_hash: &[u8], signature_r: &mut [u8], signature_s: &mut [u8], ) -> Result<(), Error>

Generate an ECDSA signature

§Arguments
  • curve - Curve parameters
  • private_key - Private key d
  • k - Random nonce (MUST be cryptographically random and unique per signature!)
  • message_hash - Hash of the message to sign
§Returns

Signature (r, s) as byte arrays

§Security Warning

The k value MUST be:

  • Cryptographically random
  • Unique for every signature
  • Never reused or predictable Failure to ensure this will compromise the private key!
Source

pub fn ecc_mul( &mut self, curve: &EcdsaCurveParams, k: &[u8], point_x: &[u8], point_y: &[u8], result: &mut EccPoint, ) -> Result<(), Error>

Perform ECC scalar multiplication: result = k * P

This is the core operation for ECDH key agreement:

  • To generate public key: public = private_key * G (generator point)
  • To compute shared secret: shared = my_private * peer_public
§Arguments
  • curve - Curve parameters
  • k - Scalar multiplier
  • point_x - Input point X coordinate
  • point_y - Input point Y coordinate
  • result - Output point (must be initialized with correct size)
Source

pub fn point_check( &mut self, curve: &EcdsaCurveParams, point_x: &[u8], point_y: &[u8], ) -> Result<bool, Error>

Check if a point is on the curve

This should be called to validate any externally-provided public key before using it in cryptographic operations.

Source

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

Perform modular exponentiation: result = base^exp mod n

This is the core RSA operation:

  • Encryption: ciphertext = plaintext^e mod n
  • Decryption: plaintext = ciphertext^d mod n
  • Signing: signature = hash^d mod n
  • Verification: hash = signature^e mod n
§Arguments
  • base - Base value (plaintext/ciphertext)
  • exponent - Exponent (e for encrypt/verify, d for decrypt/sign)
  • modulus - RSA modulus n
  • result - Output buffer (must be same size as modulus)
Source

pub fn rsa_crt_exp( &mut self, ciphertext: &[u8], params: &RsaCrtParams<'_>, result: &mut [u8], ) -> Result<(), Error>

Perform RSA CRT exponentiation for fast decryption

Uses Chinese Remainder Theorem for ~4x faster RSA private key operations.

§Arguments
  • ciphertext - Encrypted data
  • params - CRT parameters (p, q, dp, dq, qinv)
  • result - Output buffer
Source

pub fn modular_inv( &mut self, a: &[u8], modulus: &[u8], result: &mut [u8], ) -> Result<(), Error>

Compute modular inverse: result = a^(-1) mod n

Source

pub fn modular_add( &mut self, a: &[u8], b: &[u8], modulus: &[u8], result: &mut [u8], ) -> Result<(), Error>

Compute modular addition: result = (a + b) mod n

Source

pub fn modular_sub( &mut self, a: &[u8], b: &[u8], modulus: &[u8], result: &mut [u8], ) -> Result<(), Error>

Compute modular subtraction: result = (a - b) mod n

Source

pub fn arithmetic_mul( &mut self, a: &[u8], b: &[u8], result: &mut [u8], ) -> Result<(), Error>

Compute arithmetic multiplication: result = a * b

Source

pub fn montgomery_param( &mut self, modulus: &[u8], result: &mut [u32], ) -> Result<(), Error>

Compute Montgomery parameter R² mod n

This parameter is required for fast modular exponentiation and other Montgomery-form operations. The result should be stored and reused for multiple operations with the same modulus.

§Arguments
  • modulus - The modulus n
  • result - Output buffer for R² mod n (must be same size as modulus)
Source

pub fn modular_exp_fast( &mut self, base: &[u8], exponent: &[u8], modulus: &[u8], montgomery_param: &[u32], result: &mut [u8], ) -> Result<(), Error>

Perform modular exponentiation with pre-computed Montgomery parameter (fast mode)

This is faster than modular_exp when you have the Montgomery parameter pre-computed (via montgomery_param).

§Arguments
  • base - Base value
  • exponent - Exponent
  • modulus - Modulus n
  • montgomery_param - Pre-computed Montgomery parameter R² mod n
  • result - Output buffer (must be same size as modulus)
Source

pub fn modular_exp_protect( &mut self, params: &ModExpProtectParams<'_>, result: &mut [u8], ) -> Result<(), Error>

Perform modular exponentiation with side-channel protection

This mode provides constant-time execution to protect against timing and power analysis attacks. It requires phi(n) as input.

§Arguments
  • params - Protected mode parameters including phi(n)
  • result - Output buffer (must be same size as modulus)
Source

pub fn montgomery_mul( &mut self, a: &[u8], b: &[u8], modulus: &[u8], result: &mut [u8], ) -> Result<(), Error>

Perform Montgomery multiplication: result = (a * b * R^-1) mod n

This is useful for operations in Montgomery form.

Source

pub fn arithmetic_add( &mut self, a: &[u8], b: &[u8], result: &mut [u8], ) -> Result<(), Error>

Compute arithmetic addition: result = a + b

Note: Result may be one word larger than inputs if there’s overflow.

Source

pub fn arithmetic_sub( &mut self, a: &[u8], b: &[u8], result: &mut [u8], ) -> Result<(), Error>

Compute arithmetic subtraction: result = a - b

Note: If a < b, the result will be the two’s complement.

Source

pub fn comparison( &mut self, a: &[u8], b: &[u8], ) -> Result<ComparisonResult, Error>

Compare two big integers

Returns the comparison result indicating whether a < b, a == b, or a > b.

Source

pub fn modular_red( &mut self, a: &[u8], modulus: &[u8], result: &mut [u8], ) -> Result<(), Error>

Compute modular reduction: result = a mod n

Source

pub fn ecc_complete_add( &mut self, curve: &EcdsaCurveParams, p: &EccProjectivePoint, q: &EccProjectivePoint, result: &mut EccProjectivePoint, ) -> Result<(), Error>

ECC complete point addition in projective coordinates: R = P + Q

This operation adds two points in projective coordinates and handles all edge cases (point at infinity, point doubling, etc.).

§Arguments
  • curve - Curve parameters
  • p - First point in projective coordinates
  • q - Second point in projective coordinates
  • result - Output point in projective coordinates
Source

pub fn double_base_ladder( &mut self, curve: &EcdsaCurveParams, k: &[u8], p: &EccProjectivePoint, m: &[u8], q: &EccProjectivePoint, result: &mut EccPoint, ) -> Result<(), Error>

ECC double base ladder: result = kP + mQ (side-channel resistant)

This operation computes the linear combination of two points using the double base ladder algorithm, which provides side-channel resistance.

§Arguments
  • curve - Curve parameters
  • k - Scalar for point P
  • p - First point in projective coordinates
  • m - Scalar for point Q
  • q - Second point in projective coordinates
  • result - Output point in affine coordinates
Source

pub fn projective_to_affine( &mut self, modulus: &[u8], montgomery_param: &[u32], point: &EccProjectivePoint, result: &mut EccPoint, ) -> Result<(), Error>

Convert a point from projective to affine coordinates

§Arguments
  • modulus - The curve modulus p
  • montgomery_param - Pre-computed Montgomery parameter R² mod p
  • point - Point in projective coordinates
  • result - Output point in affine coordinates

Auto Trait Implementations§

§

impl<'d, T> Freeze for Pka<'d, T>
where T: Freeze,

§

impl<'d, T> RefUnwindSafe for Pka<'d, T>
where T: RefUnwindSafe,

§

impl<'d, T> Send for Pka<'d, T>

§

impl<'d, T> Sync for Pka<'d, T>
where T: Sync,

§

impl<'d, T> Unpin for Pka<'d, T>
where T: Unpin,

§

impl<'d, T> !UnwindSafe for Pka<'d, T>

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