Repository navigation
Expand file tree
/
Copy pathWebCryptPQCFullCoverage.test.js
More file actions
64 lines (53 loc) · 2.21 KB
/
Copy pathWebCryptPQCFullCoverage.test.js
File metadata and controls
64 lines (53 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// __tests__/WebCryptPQCFullCoverage.test.js
import { WebCryptPQC } from "../src/WebCryptPQC.js";
describe("WebCryptPQC Full Coverage Expansion", () => {
let pqc;
beforeEach(() => {
pqc = new WebCryptPQC();
WebCryptPQC.enableStubTesting(true);
});
test("Kyber key generation, encapsulation, and decapsulation", async () => {
const keyPair = await pqc.generateKyberKeyPair(WebCryptPQC.KYBER_768);
expect(keyPair.publicKey).toBeDefined();
expect(keyPair.privateKey).toBeDefined();
const encap = await pqc.kyberEncapsulate(keyPair.publicKey, WebCryptPQC.KYBER_768);
expect(encap.ciphertext).toBeDefined();
expect(encap.sharedSecret).toBeDefined();
const decapSecret = await pqc.kyberDecapsulate(
encap.ciphertext,
keyPair.privateKey,
WebCryptPQC.KYBER_768
);
expect(decapSecret).toBeDefined();
expect(decapSecret.byteLength).toBe(encap.sharedSecret.byteLength);
});
test("Dilithium key generation, signing, and verification", async () => {
const keyPair = await pqc.generateDilithiumKeyPair(WebCryptPQC.DILITHIUM_3);
expect(keyPair.publicKey).toBeDefined();
expect(keyPair.privateKey).toBeDefined();
const data = "Message to sign with post-quantum Dilithium-3";
const signature = await pqc.dilithiumSign(data, keyPair.privateKey, WebCryptPQC.DILITHIUM_3);
expect(signature).toBeDefined();
const valid = await pqc.dilithiumVerify(
data,
signature,
keyPair.publicKey,
WebCryptPQC.DILITHIUM_3
);
expect(valid).toBe(true);
});
test("Invalid security level traps and disabled stub testing mode", async () => {
await expect(pqc.generateKyberKeyPair("INVALID_LEVEL")).rejects.toThrow(
"Unsupported Kyber level"
);
await expect(pqc.generateDilithiumKeyPair("INVALID_LEVEL")).rejects.toThrow(
"Unsupported Dilithium level"
);
// Disable stub testing mode and verify it throws placeholder notice
WebCryptPQC.enableStubTesting(false);
await expect(pqc.generateKyberKeyPair()).rejects.toThrow("placeholder stub");
await expect(pqc.generateDilithiumKeyPair()).rejects.toThrow("placeholder stub");
// Re-enable for cleanup
WebCryptPQC.enableStubTesting(true);
});
});