pub struct SecretKey { /* private fields */ }Expand description
P-256 (secp256r1) ECDSA secret key.
Supports signing and ECDH key agreement.
§Signing
ⓘ
use crypto::p256::PrivateKey;
let key = PrivateKey::generate().unwrap();
let signature = key.sign(b"message").unwrap();§ECDH key exchange
ⓘ
use crypto::p256::PrivateKey;
let alice = PrivateKey::generate().unwrap();
let bob = PrivateKey::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
pub fn generate() -> Result<SecretKey, EllipticCurveError>
pub fn from_bytes(key: &[u8; 32]) -> Result<SecretKey, EllipticCurveError>
pub fn public_key(&self) -> PublicKey
pub fn sign(&self, message: &[u8]) -> Result<[u8; 64], EllipticCurveError>
pub fn ecdh( &self, peer_public: &PublicKey, ) -> Result<[u8; 32], EllipticCurveError>
pub fn to_bytes(&self) -> [u8; 32]
Trait Implementations§
impl Copy for SecretKey
impl Eq for SecretKey
impl StructuralPartialEq for SecretKey
Auto Trait Implementations§
impl Freeze for SecretKey
impl RefUnwindSafe for SecretKey
impl Send for SecretKey
impl Sync for SecretKey
impl Unpin for SecretKey
impl UnsafeUnpin for SecretKey
impl UnwindSafe for SecretKey
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