import { describe, expect, it } from "vitest"; import { blake3 } from "hash-wasm"; import { _testSeam as aesTestSeam } from "../background/aes"; function unhex(value: string): Uint8Array { const output = new Uint8Array(value.length / 2); for (let index = 0; index < value.length; index += 2) { output[index / 2] = Number.parseInt(value.slice(index, index + 2), 16); } return output; } function hex(value: Uint8Array): string { return Array.from(value, (byte) => byte.toString(16).padStart(2, "0")).join(""); } describe("official cryptographic vectors", () => { // NIST CAVP gcmDecrypt256.rsp, PTlen=128, AADlen=0, Taglen=128, Count=0. // Source archive SHA-256 is pinned in docs/CRYPTOGRAPHIC-TEST-VECTORS.md. it("decrypts the NIST AES-256-GCM CAVP vector and rejects a bad tag", async () => { const key = unhex( "4c8ebfe1444ec1b2d503c6986659af2c94fafe945f72c1e8486a5acfedb8a0f8", ); const nonce = "473360e0ad24889959858995"; const ciphertext = "d2c78110ac7e8f107c0df0570bd7c90c"; const tag = "c26a379b6d98ef2852ead8ce83a833a7"; const plaintext = await aesTestSeam.decryptWithAadBytes( key, nonce, ciphertext, tag, new Uint8Array(), ); expect(hex(plaintext)).toBe("7789b41cb3ee548814ca0b388c10b343"); await expect( aesTestSeam.decryptWithAadBytes( key, nonce, ciphertext, `${tag.slice(0, -2)}a6`, new Uint8Array(), ), ).rejects.toThrow(); }); // BLAKE3 official test_vectors.json, input_len=1024. The reference input is // byte i % 251 and the first 32 output bytes are the production digest size. it("matches the BLAKE3 reference vector across a chunk boundary", async () => { const input = Uint8Array.from({ length: 1024 }, (_, index) => index % 251); expect(await blake3(input)).toBe( "42214739f095a406f3fc83deb889744ac00df831c10daa55189b5d121c855af7", ); }); });