Expand description
Secret protected key envelope is a cryptographic building block that allows sealing a symmetric key with a high-entropy secret (a random URL-fragment secret, a derived key, random bytes, etc.) of arbitrary length.
It is implemented by using a cheap KDF (HKDF-SHA256) combined with symmetric key encryption (AES-256-GCM). Unlike the crate::safe::PasswordProtectedKeyEnvelope, which protects a low-entropy secret (password, PIN) and therefore uses a hard KDF (Argon2ID, PBKDF2) to slow down brute-forcing, this envelope assumes the secret is high-entropy and not brute-forceable, so a cheap KDF is sufficient. The cheap KDF also natively accepts input material of arbitrary length.
For the consumer, the output is an opaque blob that can be later unsealed with the same secret. The KDF salt is contained in the envelope, and does not need to be provided for unsealing.
Internally, the envelope is a CoseEncrypt object that uses the standardized COSE “Direct Key
with KDF” construction with the direct+HKDF-SHA-256 recipient algorithm, as described in
RFC 9053 §6.1.2. The
random HKDF salt is placed in the single recipient’s unprotected headers (the standardized
salt header parameter), and the secret is used as the input keying material. The output from
the KDF - “envelope key”, is used directly as the content-encryption key that wraps the
symmetric key sealed by the envelope.
Note: AES-GCM is used here since the CEK is locally derived, so there is no nonce re-use problem.
Structs§
- Hkdf
Settings 🔒 - Raw HKDF settings. The salt is a fixed size, randomly generated value. Unlike a memory-hard KDF, HKDF has no difficulty parameters to tune, since the input secret is assumed to be high-entropy.
- Secret
Protected KeyEnvelope - A secret-protected key envelope can seal a symmetric key, and protect it with a high-entropy secret of arbitrary length.
Enums§
- Secret
Protected KeyEnvelope Error - Errors that can occur when sealing or unsealing a key with the
SecretProtectedKeyEnvelope. - Secret
Protected KeyEnvelope Namespace - The content-layer separation namespace for secret protected key envelopes.
Constants§
- ENVELOPE_
HKDF_ 🔒OUTPUT_ KEY_ SIZE - 32 is chosen to match the size of an AES-256-GCM key
- ENVELOPE_
HKDF_ 🔒SALT_ SIZE - 32 matches the SHA-256 output size (HashLen), which is the RECOMMENDED salt size for HKDF: https://datatracker.ietf.org/doc/html/rfc5869
- HKDF_
ALGORITHM 🔒 - The recipient algorithm used by the envelope:
direct+HKDF-SHA-256(https://datatracker.ietf.org/doc/html/rfc9053#name-direct-key-with-kdf). - HKDF_
SALT_ 🔒LABEL - The standardized COSE
saltheader algorithm parameter label (-20).
Functions§
- content_
encryption_ 🔒algorithm - Reads the content-encryption algorithm declared in the protected header. This value is used as
the
AlgorithmIDof theCOSE_KDF_Context, binding the derived key to the message’s declared algorithm (RFC 9053 §6.1.2). - derive_
cek 🔒 - kdf_
context_ 🔒info - Builds the serialized
COSE_KDF_Contextused as the HKDFinfoparameter, as required by the COSE “Direct Key with KDF” construction (https://datatracker.ietf.org/doc/html/rfc9053#name-context-information-structu): - make_
salt 🔒