pub struct Pka<'d, T: Instance> { /* private fields */ }Expand description
PKA driver
Implementations§
Source§impl<'d, T: Instance> Pka<'d, T>
impl<'d, T: Instance> Pka<'d, T>
Sourcepub fn new_blocking(
peripheral: Peri<'d, T>,
_irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd,
) -> Self
pub fn new_blocking( peripheral: Peri<'d, T>, _irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd, ) -> Self
Create a new PKA driver
Sourcepub fn ecdsa_verify(
&mut self,
curve: &EcdsaCurveParams,
public_key: &EcdsaPublicKey<'_>,
signature: &EcdsaSignature<'_>,
message_hash: &[u8],
) -> Result<bool, Error>
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.
Sourcepub 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>
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 parametersprivate_key- Private key dk- 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!
Sourcepub fn ecc_mul(
&mut self,
curve: &EcdsaCurveParams,
k: &[u8],
point_x: &[u8],
point_y: &[u8],
result: &mut EccPoint,
) -> Result<(), Error>
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 parametersk- Scalar multiplierpoint_x- Input point X coordinatepoint_y- Input point Y coordinateresult- Output point (must be initialized with correct size)
Sourcepub fn point_check(
&mut self,
curve: &EcdsaCurveParams,
point_x: &[u8],
point_y: &[u8],
) -> Result<bool, Error>
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.
Sourcepub fn modular_exp(
&mut self,
base: &[u8],
exponent: &[u8],
modulus: &[u8],
result: &mut [u8],
) -> Result<(), Error>
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 nresult- Output buffer (must be same size as modulus)
Sourcepub fn rsa_crt_exp(
&mut self,
ciphertext: &[u8],
params: &RsaCrtParams<'_>,
result: &mut [u8],
) -> Result<(), Error>
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 dataparams- CRT parameters (p, q, dp, dq, qinv)result- Output buffer
Sourcepub fn modular_inv(
&mut self,
a: &[u8],
modulus: &[u8],
result: &mut [u8],
) -> Result<(), Error>
pub fn modular_inv( &mut self, a: &[u8], modulus: &[u8], result: &mut [u8], ) -> Result<(), Error>
Compute modular inverse: result = a^(-1) mod n
Sourcepub fn modular_add(
&mut self,
a: &[u8],
b: &[u8],
modulus: &[u8],
result: &mut [u8],
) -> Result<(), Error>
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
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more