generate-kat.mjs

1.1 KB · raw

1// generate-kat.mjs — recompute the pinned ciphertext for self-test.ts (PCH-01-020).2//3// Run: node scripts/generate-kat.mjs4//5// Uses the SAME parameters as deriveKatKey/runSelfTest in6// src/background/self-test.ts (PBKDF2 1000 iters SHA-256 → AES-256-GCM). Paste7// the printed hex into KAT_EXPECTED_CIPHERTEXT_HEX. It MUST NOT change once8// committed — a different value means WebCrypto changed under us.910const KAT_PLAINTEXT = "peach self-test vector v1";11const KAT_PASSWORD = "kat-fixed-password-do-not-use";12const SALT = Buffer.from("1719d355fb0e9b33cc95bca2298a00c9", "hex");13const NONCE = Buffer.from("6b65792d6e6f6e63652d3031", "hex");1415const km = await crypto.subtle.importKey(16  "raw",17  new TextEncoder().encode(KAT_PASSWORD),18  "PBKDF2",19  false,20  ["deriveKey"],21);22const key = await crypto.subtle.deriveKey(23  { name: "PBKDF2", salt: SALT, iterations: 1000, hash: "SHA-256" },24  km,25  { name: "AES-GCM", length: 256 },26  false,27  ["encrypt"],28);29const ct = await crypto.subtle.encrypt(30  { name: "AES-GCM", iv: NONCE },31  key,32  new TextEncoder().encode(KAT_PLAINTEXT),33);3435console.log(Buffer.from(ct).toString("hex"));