Struct stm32wlxx_hal::pka::Pka
source · pub struct Pka { /* private fields */ }
Expand description
PKA driver.
Implementations§
source§impl Pka
impl Pka
sourcepub fn new(pka: PKA, rcc: &mut RCC) -> Pka
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);
sourcepub fn is_enabled(&mut self) -> bool
pub fn is_enabled(&mut self) -> bool
Returns true
if the PKA is enabled.
sourcepub fn free(self) -> PKA
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();
sourcepub unsafe fn steal() -> Pka
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() };
sourcepub unsafe fn disable_clock(rcc: &mut RCC)
pub unsafe fn disable_clock(rcc: &mut RCC)
Disable the PKA clock.
Safety
- You are responsible for ensuring the PKA bus is in a state where the clock can be disabled without entering an error state.
- You cannot use the PKA bus while the clock is disabled.
- You are responsible for re-enabling the clock before resuming use of the PKA bus.
- You are responsible for setting up anything that may have lost state while the clock was disabled.
sourcepub fn enable_clock(rcc: &mut RCC)
pub fn enable_clock(rcc: &mut RCC)
Enable the PKA clock.
sourcepub unsafe fn pulse_reset(rcc: &mut RCC)
pub unsafe fn pulse_reset(rcc: &mut RCC)
Reset the PKA.
Safety
- The PKA must not be in-use.
- You are responsible for setting up the PKA after a reset.
sourcepub unsafe fn unmask_irq()
Available on non-crate feature stm32wl5x_cm0p
and crate feature rt
only.
pub unsafe fn unmask_irq()
stm32wl5x_cm0p
and crate feature rt
only.sourcepub 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>
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) | Cycles | Seconds at 48MHz |
---|---|---|
160 | 1760000 | 0.037 |
192 | 2664000 | 0.056 |
256 | 5249000 | 0.109 |
320 | 9016000 | 0.188 |
384 | 14596000 | 0.304 |
512 | 30618000 | 0.638 |
521 | 35540000 | 0.740 |
sourcepub 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>
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.
sourcepub fn ecdsa_sign_result<const MODULUS_SIZE: usize>(
&mut self,
r_sign: &mut [u32; MODULUS_SIZE],
s_sign: &mut [u32; MODULUS_SIZE]
) -> Result<(), EcdsaSignError>
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
.
sourcepub 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>
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) | Cycles | Seconds at 48MHz |
---|---|---|
160 | 3500000 | 0.073 |
192 | 5350000 | 0.112 |
256 | 10498000 | 0.219 |
320 | 18126000 | 0.378 |
384 | 29118000 | 0.607 |
512 | 61346000 | 1.278 |
521 | 71588000 | 1.491 |
sourcepub 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>
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.
sourcepub fn ecdsa_verify_result(&mut self) -> Result<(), EcdsaVerifyError>
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
.