Skip to main content

StaticKey

Struct StaticKey 

Source
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

Source

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: privateKeyAlgorithm id-ecPublicKey with algorithm’s namedCurve (RFC 5480 §2.1.1), privateKey an RFC 5915 ECPrivateKey, then optional [0] attributes;
  • an RFC 5915 §3 ECPrivateKey with 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.

Source

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).

Source

pub fn algorithm(&self) -> KeyAgreementAlgorithm

The key’s curve.

Source

pub fn public_key(&self) -> &[u8] ⓘ

The public key: an uncompressed SEC 1 point, or 32 bytes for X25519.

Source

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.

Trait Implementations§

Source§

impl Debug for StaticKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.