pub struct StaticKey { /* private fields */ }Expand description
A static key, imported from the owner’s PKI or HSM tooling; ecdh neither generates nor
exports one (sealbox::PrivateKey keeps its own P-384 generation and export for the sealed
box). Its private key is cleansed by the module when the key is dropped.
Implementations§
Source§impl StaticKey
impl StaticKey
Sourcepub fn from_pkcs8_der(
a: &Admitted,
algorithm: KeyAgreementAlgorithm,
der: &[u8],
) -> Result<Self, CryptoError>
pub fn from_pkcs8_der( a: &Admitted, algorithm: KeyAgreementAlgorithm, der: &[u8], ) -> Result<Self, CryptoError>
Imports a P-256, P-384 or P-521 private key, DER-encoded, in one of two forms:
- an RFC 5958 §2
PrivateKeyInfo, version v1: privateKeyAlgorithmid-ecPublicKeywithalgorithm’s namedCurve (RFC 5480 §2.1.1), privateKey an RFC 5915ECPrivateKey, then optional[0]attributes; - an RFC 5915 §3
ECPrivateKeywith its parameters.
The ECPrivateKey is version 1, a privateKey of exactly 32, 48 or 66 bytes, then optional
parameters naming algorithm’s curve and an optional publicKey holding the key’s own
uncompressed point (RFC 5915 §3, RFC 5480 §2.2). Refuses a curve a’s profile does not
admit, then anything else, a field or version these sections do not define, BER, id-ecDH
and id-ecMQV, other bytes after the key, and a key the module refuses
(CryptoError::KeyAgreementPrivateKey). An X25519 key is imported with
StaticKey::from_scalar.
Sourcepub fn from_scalar(
a: &Admitted,
algorithm: KeyAgreementAlgorithm,
d: &[u8],
) -> Result<Self, CryptoError>
pub fn from_scalar( a: &Admitted, algorithm: KeyAgreementAlgorithm, d: &[u8], ) -> Result<Self, CryptoError>
Imports a raw private key: a big-endian scalar of exactly the field length (32, 48 or 66
bytes) for a NIST curve, or the 32-byte RFC 7748 private key for X25519. Refuses a curve
a’s profile does not admit, then a key of another length, or a scalar that is zero or not
below the curve order (CryptoError::KeyAgreementPrivateKey).
Sourcepub fn algorithm(&self) -> KeyAgreementAlgorithm
pub fn algorithm(&self) -> KeyAgreementAlgorithm
The key’s curve.
Sourcepub fn public_key(&self) -> &[u8] ⓘ
pub fn public_key(&self) -> &[u8] ⓘ
The public key: an uncompressed SEC 1 point, or 32 bytes for X25519.
Sourcepub fn agree(
&self,
peer_ephemeral: &[u8],
spec: &Spec<'_>,
len: usize,
) -> Result<DerivedKey, CryptoError>
pub fn agree( &self, peer_ephemeral: &[u8], spec: &Spec<'_>, len: usize, ) -> Result<DerivedKey, CryptoError>
Agrees with a peer’s ephemeral public key and derives len bytes from the shared secret
as spec says, under the profile the key was imported under. With kdf::Spec::Dhkem this
is RFC 9180 §4.1 Decap’s shared secret, enc being the peer’s key. Refuses as
EphemeralKey::agree does.