Struct stm32wlxx_hal::pka::Pka

source ·
pub struct Pka { /* private fields */ }
Expand description

PKA driver.

Implementations§

source§

impl Pka

source

pub fn new(pka: PKA, rcc: &mut RCC) -> Pka

Create a new PKA driver from a PKA peripheral.

This will enable clocks and reset the PKA peripheral.

Example
use stm32wlxx_hal::{pac, pka::Pka};

let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
let mut pka = Pka::new(dp.PKA, &mut dp.RCC);
source

pub fn is_enabled(&mut self) -> bool

Returns true if the PKA is enabled.

source

pub fn free(self) -> PKA

Free the PKA peripheral from the driver.

Example
use stm32wlxx_hal::{pac, pka::Pka};

let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
let pka: pac::PKA = dp.PKA;
let pka: Pka = Pka::new(pka, &mut dp.RCC);
// ... use PKA
let pka: pac::PKA = pka.free();
source

pub unsafe fn steal() -> Pka

Steal the PKA peripheral from whatever is currently using it.

This will not initialize the PKA (unlike new).

Safety

This will create a new PKA peripheral, bypassing the singleton checks that normally occur. You are responsible for ensuring that the driver has exclusive access to the PKA peripheral. You are also responsible for ensuring the PKA has been setup correctly.

Example
use stm32wlxx_hal::pka::Pka;

// ... setup happens here

let pka = unsafe { Pka::steal() };
source

pub unsafe fn disable_clock(rcc: &mut RCC)

Disable the PKA clock.

Safety
  1. You are responsible for ensuring the PKA bus is in a state where the clock can be disabled without entering an error state.
  2. You cannot use the PKA bus while the clock is disabled.
  3. You are responsible for re-enabling the clock before resuming use of the PKA bus.
  4. You are responsible for setting up anything that may have lost state while the clock was disabled.
source

pub fn enable_clock(rcc: &mut RCC)

Enable the PKA clock.

source

pub unsafe fn pulse_reset(rcc: &mut RCC)

Reset the PKA.

Safety
  1. The PKA must not be in-use.
  2. You are responsible for setting up the PKA after a reset.
source

pub unsafe fn unmask_irq()

Available on non-crate feature stm32wl5x_cm0p and crate feature rt only.

Unmask the PKA IRQ in the NVIC.

Safety

This can break mask-based critical sections.

Example
unsafe { stm32wlxx_hal::pka::Pka::unmask_irq() };
source

pub fn ecdsa_sign<const MODULUS_SIZE: usize, const PRIME_ORDER_SIZE: usize>( &mut self, curve: &EllipticCurve<MODULUS_SIZE, PRIME_ORDER_SIZE>, nonce: &[u32; PRIME_ORDER_SIZE], priv_key: &[u32; PRIME_ORDER_SIZE], hash: &[u32; PRIME_ORDER_SIZE], r_sign: &mut [u32; MODULUS_SIZE], s_sign: &mut [u32; MODULUS_SIZE] ) -> Result<(), EcdsaSignError>

ECDSA (Elliptic Curve Digital Signature Algorithm) signing.

This is the blocking ECDSA sign method, equivalent to calling ecdsa_sign_start then polling ecdsa_sign_result.

// blocking
pka.ecdsa_sign(&curve, &nonce, &priv_key, &hash, &mut r_sign, &mut s_sign);

// non-blocking
pka.ecdsa_sign_start(&curve, &nonce, &priv_key, &hash)?;
nb::block!(pka.ecdsa_sign_result(&mut r_sign, &mut s_sign))?;
Computation Times
Modulus Length (bits)CyclesSeconds at 48MHz
16017600000.037
19226640000.056
25652490000.109
32090160000.188
384145960000.304
512306180000.638
521355400000.740
source

pub fn ecdsa_sign_start<const MODULUS_SIZE: usize, const PRIME_ORDER_SIZE: usize>( &mut self, curve: &EllipticCurve<MODULUS_SIZE, PRIME_ORDER_SIZE>, nonce: &[u32; PRIME_ORDER_SIZE], priv_key: &[u32; PRIME_ORDER_SIZE], hash: &[u32; PRIME_ORDER_SIZE] ) -> Result<(), EcdsaSignError>

Start an ECDSA signing operation.

This will enable all the PKA IRQs.

Use the ecdsa_sign_result method to poll for completion, or to get the result in an interrupt handler.

source

pub fn ecdsa_sign_result<const MODULUS_SIZE: usize>( &mut self, r_sign: &mut [u32; MODULUS_SIZE], s_sign: &mut [u32; MODULUS_SIZE] ) -> Result<(), EcdsaSignError>

Get the result of an ECDSA sign operation.

Use this after starting an ECDSA sign operation with ecdsa_sign_start.

source

pub fn ecdsa_verify<const MODULUS_SIZE: usize, const PRIME_ORDER_SIZE: usize>( &mut self, curve: &EllipticCurve<MODULUS_SIZE, PRIME_ORDER_SIZE>, sig: &EcdsaSignature<'_, MODULUS_SIZE>, pub_key: &EcdsaPublicKey<'_, MODULUS_SIZE>, hash: &[u32; PRIME_ORDER_SIZE] ) -> Result<(), EcdsaVerifyError>

ECDSA (Elliptic Curve Digital Signature Algorithm) verification.

This is the blocking ECDSA verify method, equivalent to calling ecdsa_verify_start then polling ecdsa_verify_result.

// blocking
pka.ecdsa_verify(&curve, &sig, &pub_key, &hash)?;

// non-blocking
pka.ecdsa_verify_start(&curve, &sig, &pub_key, &hash)?;
nb::block!(pka.ecdsa_verify_result())?;
Computation Times
Modulus Length (bits)CyclesSeconds at 48MHz
16035000000.073
19253500000.112
256104980000.219
320181260000.378
384291180000.607
512613460001.278
521715880001.491
source

pub fn ecdsa_verify_start<const MODULUS_SIZE: usize, const PRIME_ORDER_SIZE: usize>( &mut self, curve: &EllipticCurve<MODULUS_SIZE, PRIME_ORDER_SIZE>, sig: &EcdsaSignature<'_, MODULUS_SIZE>, pub_key: &EcdsaPublicKey<'_, MODULUS_SIZE>, hash: &[u32; PRIME_ORDER_SIZE] ) -> Result<(), EcdsaVerifyError>

Start an ECDSA verify operation.

This will enable all the PKA IRQs.

Use the ecdsa_verify_result method to poll for completion, or to get the result in an interrupt handler.

source

pub fn ecdsa_verify_result(&mut self) -> Result<(), EcdsaVerifyError>

Get the result of an ECDSA verify operation.

Use this after starting an ECDSA verify operation with ecdsa_verify_start.

Trait Implementations§

source§

impl Debug for Pka

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Pka

§

impl Send for Pka

§

impl !Sync for Pka

§

impl Unpin for Pka

§

impl UnwindSafe for Pka

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.