Class Kdf

java.lang.Object
zeroecho.sdk.util.Kdf

public final class Kdf extends Object
HKDF utilities for deriving symmetric keys from a KEM shared secret. This class provides an RFC 5869 compliant HKDF-SHA256 implementation.

Notes

The function implements HKDF-Extract followed by HKDF-Expand with SHA-256. If salt is null or empty, a zero-filled salt of length 32 is used as recommended by RFC 5869. If info is null, it is treated as an empty byte array.
// Example: derive 32 bytes for AES-256 or ChaCha20-Poly1305
byte[] ikm   = kemSharedSecret;          // input keying material from KEM
byte[] salt  = null;                     // or a KEM-specific salt
byte[] info  = "ZeroEcho-KEM".getBytes(StandardCharsets.US_ASCII);
int    len   = 32;
byte[] key   = Kdf.hkdfSha256(ikm, salt, info, len);
  • Method Details

    • hkdfSha256

      public static byte[] hkdfSha256(byte[] ikm, byte[] salt, byte[] info, int length) throws GeneralSecurityException
      Derives length bytes of key material using HKDF-SHA256 as specified in RFC 5869.

      HKDF-Extract: PRK = HMAC(salt, IKM) where salt defaults to HashLen zeros if salt is null or empty.

      HKDF-Expand: T(0)=empty, T(i)=HMAC(PRK, T(i-1) || info || i), and the output key material is the first length bytes of T(1)||...||T(N), where N = ceil(length / HashLen) and i is a single octet counter.

      Parameters:
      ikm - input keying material; must not be null or empty
      salt - optional salt; if null or empty, a zero salt of 32 bytes is used
      info - optional context/application info; if null, treated as empty
      length - number of output bytes to produce; must be in range 1..(255*32)
      Returns:
      derived keying material of exactly length bytes
      Throws:
      GeneralSecurityException - if the MAC operation fails
      IllegalArgumentException - if ikm is empty or length is out of range
      Since:
      1.0