Skip to content

Commit

Permalink
Activate X25519 tests for @hpke/core.
Browse files Browse the repository at this point in the history
  • Loading branch information
dajiaji committed Oct 13, 2024
1 parent 29ea087 commit 9b74bd8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 32 deletions.
24 changes: 0 additions & 24 deletions packages/core/test/conformance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ describe("RFC9180 conformance", () => {
it("should match demonstrated values", async () => {
for (const v of testVectors) {
if (v.mode === 0 && v.kem_id === 0x0020 && v.aead_id <= 0x0002) {
if (isDeno()) {
continue;
}
await tester.test(v);
}
}
Expand All @@ -115,9 +112,6 @@ describe("RFC9180 conformance", () => {
it("should match demonstrated values", async () => {
for (const v of testVectors) {
if (v.mode === 0 && v.kem_id === 0x0020 && v.aead_id === 0xFFFF) {
if (isDeno()) {
continue;
}
await tester.test(v);
}
}
Expand Down Expand Up @@ -203,9 +197,6 @@ describe("RFC9180 conformance", () => {
it("should match demonstrated values", async () => {
for (const v of testVectors) {
if (v.mode === 1 && v.kem_id === 0x0020 && v.aead_id <= 0x0002) {
if (isDeno()) {
continue;
}
await tester.test(v);
}
}
Expand All @@ -226,9 +217,6 @@ describe("RFC9180 conformance", () => {
it("should match demonstrated values", async () => {
for (const v of testVectors) {
if (v.mode === 1 && v.kem_id === 0x0020 && v.aead_id === 0xFFFF) {
if (isDeno()) {
continue;
}
await tester.test(v);
}
}
Expand Down Expand Up @@ -314,9 +302,6 @@ describe("RFC9180 conformance", () => {
it("should match demonstrated values", async () => {
for (const v of testVectors) {
if (v.mode === 2 && v.kem_id === 0x0020 && v.aead_id <= 0x0002) {
if (isDeno()) {
continue;
}
await tester.test(v);
}
}
Expand All @@ -337,9 +322,6 @@ describe("RFC9180 conformance", () => {
it("should match demonstrated values", async () => {
for (const v of testVectors) {
if (v.mode === 2 && v.kem_id === 0x0020 && v.aead_id === 0xFFFF) {
if (isDeno()) {
continue;
}
await tester.test(v);
}
}
Expand Down Expand Up @@ -425,9 +407,6 @@ describe("RFC9180 conformance", () => {
it("should match demonstrated values", async () => {
for (const v of testVectors) {
if (v.mode === 3 && v.kem_id === 0x0020 && v.aead_id <= 0x0002) {
if (isDeno()) {
continue;
}
await tester.test(v);
}
}
Expand All @@ -448,9 +427,6 @@ describe("RFC9180 conformance", () => {
it("should match demonstrated values", async () => {
for (const v of testVectors) {
if (v.mode === 3 && v.kem_id === 0x0020 && v.aead_id === 0xFFFF) {
if (isDeno()) {
continue;
}
await tester.test(v);
}
}
Expand Down
21 changes: 13 additions & 8 deletions packages/core/test/conformanceTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { PreSharedKey } from "@hpke/common";
import type { AeadInterface, KdfInterface, KemInterface } from "../mod.ts";
import {
hexToBytes,
isDeno,
kemToKeyGenAlgorithm,
loadSubtleCrypto,
} from "@hpke/common";
Expand Down Expand Up @@ -119,9 +120,11 @@ export class ConformanceTester {

const dSkR = await suite.kem.deserializePrivateKey(skRm);
const dPkR = await suite.kem.deserializePublicKey(pkRm);
const skRm2 = await suite.kem.serializePrivateKey(dSkR);
if (!isDeno()) {
const skRm2 = await suite.kem.serializePrivateKey(dSkR);
assertEquals(skRm, new Uint8Array(skRm2));
}
const pkRm2 = await suite.kem.serializePublicKey(dPkR);
assertEquals(skRm, new Uint8Array(skRm2));
assertEquals(pkRm, new Uint8Array(pkRm2));

const ekp = {
Expand All @@ -132,12 +135,14 @@ export class ConformanceTester {
// deriveKeyPair
const ikmE = hexToBytes(v.ikmE);
const ikmR = hexToBytes(v.ikmR);
const derivedR = await suite.kem.deriveKeyPair(ikmR.buffer);
const derivedPkRm = await this.cryptoKeyToBytes(derivedR.publicKey);
assertEquals(derivedPkRm, pkRm);
const derivedE = await suite.kem.deriveKeyPair(ikmE.buffer);
const derivedPkEm = await this.cryptoKeyToBytes(derivedE.publicKey);
assertEquals(derivedPkEm, pkEm);
if (!isDeno()) {
const derivedR = await suite.kem.deriveKeyPair(ikmR.buffer);
const derivedPkRm = await this.cryptoKeyToBytes(derivedR.publicKey);
assertEquals(derivedPkRm, pkRm);
const derivedE = await suite.kem.deriveKeyPair(ikmE.buffer);
const derivedPkEm = await this.cryptoKeyToBytes(derivedE.publicKey);
assertEquals(derivedPkEm, pkEm);
}

// create EncryptionContext
const info = hexToBytes(v.info);
Expand Down

0 comments on commit 9b74bd8

Please sign in to comment.