embassy-stm32

Crates

git

Versions

stm32h523re

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

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.