commonware_cryptography/secp256r1/
mod.rs

1//! Secp256r1 implementation of the [crate::Verifier] and [crate::Signer] traits.
2//!
3//! This implementation operates over public keys in compressed form (SEC 1, Version 2.0, Section 2.3.3), generates
4//! deterministic signatures as specified in [RFC 6979](https://datatracker.ietf.org/doc/html/rfc6979), and enforces
5//! signatures are normalized according to [BIP 62](https://github.com/bitcoin/bips/blob/master/bip-0062.mediawiki#low-s-values-in-signatures).
6//!
7//! # Example
8//! ```rust
9//! use commonware_cryptography::{secp256r1, PrivateKey, PublicKey, Signature, Recoverable, Verifier as _, Signer as _};
10//! use commonware_math::algebra::Random;
11//! use rand::rngs::OsRng;
12//!
13//! // Generate a new private key
14//! let mut signer = secp256r1::standard::PrivateKey::random(&mut OsRng);
15//!
16//! // Create a message to sign
17//! let namespace = &b"demo"[..];
18//! let msg = b"hello, world!";
19//!
20//! // Sign the message
21//! let signature = signer.sign(namespace, msg);
22//!
23//! // Verify the signature
24//! assert!(signer.public_key().verify(namespace, msg, &signature));
25//!
26//! // Generate a new private key that supports recoverable signatures
27//! let mut signer = secp256r1::recoverable::PrivateKey::random(&mut OsRng);
28//!
29//! // Sign the message
30//! let signature = signer.sign(namespace, msg);
31//!
32//! // Verify the signature
33//! assert_eq!(signature.recover_signer(namespace, msg).unwrap(), signer.public_key());
34//! ```
35
36mod common;
37pub mod recoverable;
38pub mod standard;