Class Kdf
java.lang.Object
zeroecho.sdk.util.Kdf
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. Ifsalt 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 Summary
Modifier and TypeMethodDescriptionstatic byte[]hkdfSha256(byte[] ikm, byte[] salt, byte[] info, int length) Deriveslengthbytes of key material using HKDF-SHA256 as specified in RFC 5869.
-
Method Details
-
hkdfSha256
public static byte[] hkdfSha256(byte[] ikm, byte[] salt, byte[] info, int length) throws GeneralSecurityException Deriveslengthbytes of key material using HKDF-SHA256 as specified in RFC 5869.HKDF-Extract:
PRK = HMAC(salt, IKM)wheresaltdefaults toHashLenzeros ifsaltisnullor empty.HKDF-Expand:
T(0)=empty,T(i)=HMAC(PRK, T(i-1) || info || i), and the output key material is the firstlengthbytes ofT(1)||...||T(N), whereN = ceil(length / HashLen)andiis a single octet counter.- Parameters:
ikm- input keying material; must not benullor emptysalt- optional salt; ifnullor empty, a zero salt of 32 bytes is usedinfo- optional context/application info; ifnull, treated as emptylength- number of output bytes to produce; must be in range 1..(255*32)- Returns:
- derived keying material of exactly
lengthbytes - Throws:
GeneralSecurityException- if the MAC operation failsIllegalArgumentException- ifikmis empty orlengthis out of range- Since:
- 1.0
-