Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Key Derivation with HKDF

The crate includes an HKDF-SHA256 helper (RFC 5869) for deriving per-session keys, for example a per-user HMAC secret from a session token.

No signing mode uses it automatically. To sign per session, derive a key and build an engine with Setup::hmac (or call anza::crypto::hmac::sign::payload) with it yourself.

1. Rust API

src/crypto/hkdf/derive.rs:

// anza::crypto::hkdf::derive
pub fn key(ikm: &[u8], salt: Option<&[u8]>, info: &[u8]) -> anza::Result<[u8; 32]>;
use anza::crypto::{hkdf::derive, hmac::sign};

let session_token = b"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...";
let salt = b"anza-cluster-salt-2026";

let user_key: [u8; 32] = derive::key(session_token, Some(salt), b"user-live-feed")?;

let envelope_message = anza::crypto::envelope::message(1_724_771_200, "feed", "<ui-card>Hi</ui-card>", None);
let sig = sign::payload(&user_key, &envelope_message)?;

2. Properties

  1. Stateless: the same inputs always give the same key, so the server can re-derive it per request.
  2. Isolation: knowing one derived key does not reveal the input key or other derived keys.