The public history carried kat/__pycache__/mlkem768_reference.cpython-314.pyc, a compiled Python artifact embedding the operator's absolute local path. Text secret scanners do not read compiled binaries, which is exactly how it slipped through, and removing it from the tip would have left it reachable through the old root commits. So this repository is republished from a single clean root. This root also carries, from the previously unpublished line of work: - corrected LICENSE year, LICENSING.md, VERIFY-POLICY.md, and CITATIONS-UNRESOLVED.md remeasured 2026-08-11 (101 paths, README aligned) - O-018: run_consensus_verification.py ran 19 of 29 models and reported PASS; it now runs all 29, and computemarket_smt.py gains resolveByTimeout / reclaimUnsettled cases plus a negative control - O-006: the word 'audited' removed from next to Bouncy Castle, twice, after a concurrent edit resurrected it - O-014: prior art named and dated - Algorand's native falcon_verify shipped about ten months before AERE's precompiles; the primacy claim is withdrawn where it was implied - bench/ scripts parametrized so they actually run for an outsider (the earlier textual sanitization left $STAGING unexpanded inside Python strings) - AIP-2/AIP-3 errata with measured figures, spec remeasurements at 2026-08-01, and the spec-zk-stack retractions (owner is an operational key, not the Foundation; 'maximally sound' withdrawn; aggregator V1 deprecated) The redacted bench-host environment files from the sanitized line are kept exactly as published; the unredacted local variants are not carried.
64 lines
2.6 KiB
Java
64 lines
2.6 KiB
Java
package org.hyperledger.besu.evm.precompile;
|
|
|
|
// Backup ML-KEM-768 KAT generator (used only if the NIST ACVP fetch is unavailable).
|
|
// Produces vectors whose expected (c, k) are cryptographically trustworthy because
|
|
// each shared secret k is CONFIRMED by an independent decapsulation:
|
|
// keygen -> (ek, dk); pick random m; (k, c) = Encaps_internal(ek, m);
|
|
// k2 = Decaps(dk, c); assert k == k2 (ML-KEM correctness / KAT property).
|
|
// Emits tcId|ek_hex|m_hex|c_hex|k_hex, same format as the NIST ACVP file, for
|
|
// MlKemAcvpKat.java to drive through the precompile.
|
|
|
|
import org.bouncycastle.crypto.SecretWithEncapsulation;
|
|
import org.bouncycastle.pqc.crypto.mlkem.*;
|
|
import java.io.*;
|
|
import java.nio.file.*;
|
|
import java.security.SecureRandom;
|
|
import java.util.Arrays;
|
|
|
|
public class GenMlKemSelfKat {
|
|
static String hex(byte[] b) {
|
|
StringBuilder s = new StringBuilder();
|
|
for (byte x : b) s.append(String.format("%02x", x));
|
|
return s.toString();
|
|
}
|
|
|
|
public static void main(String[] a) throws Exception {
|
|
String out = a.length > 0 ? a[0] : "mlkem768_acvp.txt";
|
|
int n = a.length > 1 ? Integer.parseInt(a[1]) : 20;
|
|
SecureRandom rnd = new SecureRandom();
|
|
|
|
MLKEMKeyPairGenerator kg = new MLKEMKeyPairGenerator();
|
|
kg.init(new MLKEMKeyGenerationParameters(rnd, MLKEMParameters.ml_kem_768));
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("# BC-generated ML-KEM-768 encapsulation vectors, decapsulation-confirmed (ek|m|c|k)\n");
|
|
int ok = 0;
|
|
for (int i = 0; i < n; i++) {
|
|
org.bouncycastle.crypto.AsymmetricCipherKeyPair kp = kg.generateKeyPair();
|
|
MLKEMPublicKeyParameters pub = (MLKEMPublicKeyParameters) kp.getPublic();
|
|
MLKEMPrivateKeyParameters priv = (MLKEMPrivateKeyParameters) kp.getPrivate();
|
|
|
|
byte[] m = new byte[32];
|
|
rnd.nextBytes(m);
|
|
|
|
MLKEMGenerator gen = new MLKEMGenerator(rnd);
|
|
SecretWithEncapsulation enc = gen.internalGenerateEncapsulated(pub, m);
|
|
byte[] k = enc.getSecret();
|
|
byte[] c = enc.getEncapsulation();
|
|
|
|
// independent confirmation of k via decapsulation
|
|
MLKEMExtractor ext = new MLKEMExtractor(priv);
|
|
byte[] k2 = ext.extractSecret(c);
|
|
if (!Arrays.equals(k, k2)) {
|
|
System.out.println("DECAPS_MISMATCH at " + i);
|
|
System.exit(4);
|
|
}
|
|
ok++;
|
|
sb.append(i).append("|").append(hex(pub.getEncoded())).append("|").append(hex(m))
|
|
.append("|").append(hex(c)).append("|").append(hex(k)).append("\n");
|
|
}
|
|
Files.write(Paths.get(out), sb.toString().getBytes());
|
|
System.out.println("GenMlKemSelfKat: wrote " + ok + " decaps-confirmed vectors -> " + out);
|
|
}
|
|
}
|