embassy-crypto-driver

Crates

git

Versions

default

Flavors

Skip to main content

P256EcImpl

Struct P256EcImpl 

Source
pub struct P256EcImpl;
Expand description

The global P256Ec implementation.

Implementations§

Source§

impl P256EcImpl

Source

pub fn generate_keypair( rng: &mut dyn Rng, ) -> Result<(P256Scalar, P256AffinePoint), CryptoError>

Generate a fresh keypair: d uniform in [1, n-1], Q = d * G.

Used for TLS 1.3 ECDHE keygen and BLE LE-SC keygen.

Source

pub fn public_key(k: P256Scalar) -> Result<P256AffinePoint, CryptoError>

Derive the public key k * G from a known private scalar.

No RNG: used for persistent keys (e.g. a TLS static ECDSA identity loaded from flash, or deriving a BLE public key from a stored secret) where the caller already holds k.

Source

pub fn validate_point(p: &P256AffinePoint) -> bool

Validate that p is a non-identity point on the P-256 curve.

Source

pub fn ecdh_shared_secret( k: P256Scalar, peer: P256AffinePoint, ) -> Result<[u8; 32], CryptoError>

ECDH shared secret: X coordinate of k * peer, big-endian.

This is the TLS 1.3 ecdhe_shared_secret (fed into HKDF via HmacSha256) and the BLE LE-SC DHKey.

Source

pub fn ecdsa_sign( k: P256Scalar, digest: &[u8; 32], rng: &mut dyn Rng, ) -> Result<P256Signature, CryptoError>

ECDSA sign a pre-hashed message (ecdsa_secp256r1_sha256).

The nonce is drawn from rng unless the hardware mandates an internal entropy source. Returns a low-S normalized signature.

Source

pub fn ecdsa_verify( q: P256AffinePoint, digest: &[u8; 32], sig: &P256Signature, ) -> Result<(), CryptoError>

ECDSA verify a pre-hashed message. All inputs public; may be variable-time. Err(CryptoError::InvalidSignature) on failure.

Trait Implementations§

Source§

impl P256Ec for P256EcImpl

Source§

fn generate_keypair( rng: &mut dyn Rng, ) -> Result<(P256Scalar, P256AffinePoint), CryptoError>

Generate a fresh keypair: d uniform in [1, n-1], Q = d * G. Read more
Source§

fn public_key(k: P256Scalar) -> Result<P256AffinePoint, CryptoError>

Derive the public key k * G from a known private scalar. Read more
Source§

fn validate_point(p: &P256AffinePoint) -> bool

Validate that p is a non-identity point on the P-256 curve.
Source§

fn ecdh_shared_secret( k: P256Scalar, peer: P256AffinePoint, ) -> Result<[u8; 32], CryptoError>

ECDH shared secret: X coordinate of k * peer, big-endian. Read more
Source§

fn ecdsa_sign( k: P256Scalar, digest: &[u8; 32], rng: &mut dyn Rng, ) -> Result<P256Signature, CryptoError>

ECDSA sign a pre-hashed message (ecdsa_secp256r1_sha256). Read more
Source§

fn ecdsa_verify( q: P256AffinePoint, digest: &[u8; 32], sig: &P256Signature, ) -> Result<(), CryptoError>

ECDSA verify a pre-hashed message. All inputs public; may be variable-time. Err(CryptoError::InvalidSignature) on failure.

Auto Trait Implementations§

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 = !

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.