Package io.github.mahmoudimus.quic
Class Hkdf
java.lang.Object
io.github.mahmoudimus.quic.Hkdf
HKDF (RFC 5869) over an HMAC, and the
HKDF-Expand-Label of TLS 1.3 (RFC 8446 section 7.1)
that QUIC uses for its secrets and keys (RFC 9001 section 5.1).
Instances are immutable and thread-safe; each call makes its own Mac.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionbyte[]expand(byte[] prk, byte[] info, int length) HKDF-Expand(prk, info, length).byte[]expandLabel(byte[] secret, String label, byte[] context, int length) TLS 1.3'sHKDF-Expand-Label(secret, label, context, length), with the"tls13 "prefix added tolabel.byte[]extract(byte[] salt, byte[] ikm) HKDF-Extract(salt, ikm).intThe length of the hash, which is also the length ofextract(byte[], byte[])output.
-
Field Details
-
SHA256
HKDF with HMAC-SHA256, for the SHA-256 cipher suites and QUIC's Initial secrets. -
SHA384
HKDF with HMAC-SHA384, forTLS_AES_256_GCM_SHA384.
-
-
Method Details
-
hashLength
public int hashLength()The length of the hash, which is also the length ofextract(byte[], byte[])output.- Returns:
- the hash length in bytes
-
extract
public byte[] extract(byte[] salt, byte[] ikm) HKDF-Extract(salt, ikm).- Parameters:
salt- the salt; empty means a string ofhashLength()zerosikm- the input keying material- Returns:
- the pseudorandom key,
hashLength()bytes
-
expand
public byte[] expand(byte[] prk, byte[] info, int length) HKDF-Expand(prk, info, length).- Parameters:
prk- the pseudorandom key, at leasthashLength()bytesinfo- the contextlength- the output length, at most 255 timeshashLength()- Returns:
- the output keying material
-
expandLabel
TLS 1.3'sHKDF-Expand-Label(secret, label, context, length), with the"tls13 "prefix added tolabel.- Parameters:
secret- the secret to expandlabel- the label without its prefix, such as"quic key"context- the context, often empty or a transcript hashlength- the output length, at most 65535- Returns:
- the derived bytes
-