otp_crypto/hkdf library

OTP Crypto – HKDF-SHA256 (extract + expand)

Implements HKDF (RFC 5869) over SHA-256 in pure Dart using our HMAC construction (HmacSha256). Used to derive two 32-byte keys:

  • enc_key (AES-256 key)
  • mac_key (HMAC-SHA256 key)

SCHEME:

  • PRK = HMAC(salt, IKM) // extract
  • OKM = T(1) || T(2) || … up to L bytes // expand where T(i) = HMAC(PRK, T(i-1) || info || i)

NOTES:

  • HashLen = 32 (SHA-256)
  • Max output length L ≤ 255 * HashLen (per RFC 5869).
  • If salt is null/empty, RFC recommends a zero-array of HashLen.
  • We derive 64 bytes once and split: enc_key = first 32, mac_key = next 32.

HINTS:

  • Use deriveKeys(...) for the common enc/mac pair derivation.
  • Keep inputs as bytes; avoid string conversions for secrets.

Classes

DerivedKeys
Pair of derived keys (32 bytes each): encryption and MAC.
HkdfSha256