Skip to content

Commit

Permalink
Merge pull request #158 from dajiaji/minimize-test
Browse files Browse the repository at this point in the history
Reduce CCTV test from 10000 to 100.
  • Loading branch information
dajiaji authored Dec 21, 2024
2 parents 4909e6c + be6d049 commit ecb8e62
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,11 @@ as well.
<!-- use a specific version -->
<script type="module">
// Using esm.sh:
import { MlKem1024, MlKem512, MlKem768 } from "https://esm.sh/mlkem@<SEMVER>";
import {
MlKem1024,
MlKem512,
MlKem768,
} from "https://esm.sh/mlkem@<SEMVER>";
// Using unpkg.com:
// import { MlKem768 } from "https://unpkg.com/mlkem@SEMVER";
// ...
Expand Down
23 changes: 16 additions & 7 deletions test/mlkem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,27 @@ function concat(a: Uint8Array, b: Uint8Array): Uint8Array {
* k from ML-KEM.Decaps when provided with the random ct
* The resulting hashes for 10 000 consecutive tests are:
*/
const count = 100;
const expectedHashes: { [key: string]: string } = {
"MlKem512":
"705dcffc87f4e67e35a09dcaa31772e86f3341bd3ccf1e78a5fef99ae6a35a13",
"449120c6e320ef3e9fbfa2316e5f2d2e1e6dd37d8ff5d086d5d2db7d42aff0a1",
"MlKem768":
"f959d18d3d1180121433bf0e05f11e7908cf9d03edc150b2b07cb90bef5bc1c1",
"8d65b902f28edc683cebee2872962fd165a4d197c9e24ec74caa4470270df0b7",
"MlKem1024":
"e3bf82b013307b2e9d47dde791ff6dfc82e694e6382404abdb948b908b75bad5",
"c3ffe9ebecfa479c142656cbfbc6417efa05b77e994fe538eef4daed166363df",
};
console.log("pq-crystals/kyber test vector count: 10000");

for (let i = 0; i < 10000; i++) {
// count == 10000
// const expectedHashes: { [key: string]: string } = {
// "MlKem512":
// "705dcffc87f4e67e35a09dcaa31772e86f3341bd3ccf1e78a5fef99ae6a35a13",
// "MlKem768":
// "f959d18d3d1180121433bf0e05f11e7908cf9d03edc150b2b07cb90bef5bc1c1",
// "MlKem1024":
// "e3bf82b013307b2e9d47dde791ff6dfc82e694e6382404abdb948b908b75bad5",
// };
console.log("pq-crystals/kyber test vector count:", count);

for (let i = 0; i < count; i++) {
const [ek, dk] = await deterministicMlKem.generateKeyPair();
const [ct, k] = await deterministicMlKem.encap(ek);
const kActual = await deterministicMlKem.decap(ct, dk);
Expand All @@ -182,7 +192,6 @@ function concat(a: Uint8Array, b: Uint8Array): Uint8Array {
.update(k)
.update(kRandom);
}

const actualHash = shakeInstance.digest();
assertEquals(bytesToHex(actualHash), expectedHashes[MlKemClass.name]);
});
Expand Down
6 changes: 5 additions & 1 deletion test/runtimes/browsers/pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
<head><title>crystals-kyber-js test</title></head>
<body>
<script type="module">
import { MlKem1024, MlKem512, MlKem768 } from "./src/crystals-kyber.js";
import {
MlKem1024,
MlKem512,
MlKem768,
} from "./src/crystals-kyber.js";

function isEqual(x, y) {
if (x.length !== y.length) {
Expand Down

0 comments on commit ecb8e62

Please sign in to comment.