pub struct SecretKey(/* private fields */);Expand description
P-384 (secp384r1) ECDSA secret key.
Supports signing and ECDH key agreement.
§Signing
use crypto::p384::SecretKey;
let key = SecretKey::generate().unwrap();
let signature = key.sign(b"message").unwrap();§ECDH key exchange
use crypto::p384::SecretKey;
let alice = SecretKey::generate().unwrap();
let bob = SecretKey::generate().unwrap();
let alice_shared = alice.ecdh(&bob.public_key()).unwrap();
let bob_shared = bob.ecdh(&alice.public_key()).unwrap();
assert_eq!(alice_shared, bob_shared);§Security
The raw shared secret from ecdh must not be used
directly as an encryption key. Apply a KDF (e.g. HKDF) first.
Implementations§
Source§impl SecretKey
impl SecretKey
Sourcepub fn generate() -> Result<SecretKey, EllipticCurveError>
pub fn generate() -> Result<SecretKey, EllipticCurveError>
Generates a fresh random secret key.
Sourcepub fn from_bytes(key: &[u8; 48]) -> Result<SecretKey, EllipticCurveError>
pub fn from_bytes(key: &[u8; 48]) -> Result<SecretKey, EllipticCurveError>
Builds a secret key from its 48-byte big-endian scalar.
Returns EllipticCurveError::InvalidKey when the scalar is zero or
greater than or equal to the group order.
Sourcepub fn public_key(&self) -> PublicKey
pub fn public_key(&self) -> PublicKey
Returns the corresponding public key.
Sourcepub fn sign(&self, message: &[u8]) -> Result<[u8; 96], EllipticCurveError>
pub fn sign(&self, message: &[u8]) -> Result<[u8; 96], EllipticCurveError>
Signs message with ECDSA using SHA-384 and deterministic (RFC 6979)
nonces.
The emitted signature is always in canonical low-s form (s <= n / 2),
so a given key and message always produce the exact same signature
bytes. This prevents signature malleability for systems that hash the
signature bytes (e.g. transaction ids, replay caches).
Verification remains permissive by default (both s and n - s are
accepted); use PublicKey::verify_strict if high-s signatures must be
rejected.