embassy-crypto

Crates

git

Versions

default

Flavors

Skip to main content

P256Ecdsa

Trait P256Ecdsa 

Source
pub trait P256Ecdsa {
    // Required methods
    fn public_key(k: &P256Scalar) -> Result<P256Point, Error>;
    fn sign(k: &P256Scalar, digest: &[u8; 32]) -> Result<P256Signature, Error>;
    fn verify(
        q: &P256Point,
        digest: &[u8; 32],
        sig: &P256Signature,
    ) -> Result<(), Error>;
}
Expand description

ECDSA/P-256 (secp256r1) driver, over pre-hashed messages.

§Contract

  • Private scalars are canonical and nonzero; other values return Error::InvalidKey.
  • No secret-dependent timing with respect to the private scalar and the nonce.
  • Implementations wipe copies of secrets they materialize in RAM.

Required Methods§

Source

fn public_key(k: &P256Scalar) -> Result<P256Point, Error>

The public key k * G of the private scalar k.

Source

fn sign(k: &P256Scalar, digest: &[u8; 32]) -> Result<P256Signature, Error>

Sign digest with the private scalar k.

The nonce is drawn from [RngImpl] by rejection sampling into [1, n). Hardware that generates the nonce on-chip from its own entropy source may not use [RngImpl], and must document it. The signature is low-S normalized.

Source

fn verify( q: &P256Point, digest: &[u8; 32], sig: &P256Signature, ) -> Result<(), Error>

Verify the signature of digest with the public key q.

Accepts both low-S and high-S signatures. q is untrusted: implementations validate that it is a point on the curve. Failure of any kind is reported as Error::InvalidSignature, except an invalid q, which is Error::InvalidKey. Only public data is handled, so this may be variable-time.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§