Add kdf module: Key Derivation Function API (JEP 510, final in JDK 25), HKDF, RFC 5869 vectors, interop with Python cryptography and openssl, per-tenant keys

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b7rnC7jppGGdHGESvy
This commit is contained in:
2026-10-28 18:07:57 +00:00
co-authored by Claude Sonnet 5.5
parent c93a1fffbb
commit eca73ad544
21 changed files with 995 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
import java.util.HexFormat;
/** Tiny helpers shared by the demos: hex, a self-checking assert that prints PASS/FAIL, section headers. */
final class Fx {
private static final HexFormat HEX = HexFormat.of();
static int failures = 0;
static String hex(byte[] b) { return HEX.formatHex(b); }
static byte[] unhex(String s) { return HEX.parseHex(s.replaceAll("\\s+", "")); }
/** Bytes 0x00..n-1 starting at {@code from} (RFC 5869 test case 2 uses such ranges). */
static byte[] range(int from, int count) {
byte[] b = new byte[count];
for (int i = 0; i < count; i++) b[i] = (byte) (from + i);
return b;
}
static byte[] fill(int value, int count) {
byte[] b = new byte[count];
java.util.Arrays.fill(b, (byte) value);
return b;
}
static void check(String what, boolean ok) {
System.out.println((ok ? "PASS " : "FAIL ") + what);
if (!ok) failures++;
}
static void checkEq(String what, byte[] expected, byte[] actual) {
check(what, java.util.Arrays.equals(expected, actual));
if (!java.util.Arrays.equals(expected, actual)) {
System.out.println(" expected " + hex(expected));
System.out.println(" actual " + hex(actual));
}
}
static void header(String s) { System.out.println("== " + s); }
/** Exit non-zero if any check failed, so run.sh and CI notice. */
static void done() {
System.out.println(failures == 0 ? "ALL CHECKS PASSED" : failures + " CHECK(S) FAILED");
if (failures != 0) System.exit(1);
}
}