Skip to content

Commit

Permalink
Merge pull request #434 from dajiaji/activate-conformance-test-for-x2…
Browse files Browse the repository at this point in the history
…5519

Activate X25519 tests for @hpke/core.
  • Loading branch information
dajiaji authored Oct 13, 2024
2 parents 29ea087 + f01b0a3 commit a012cf6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
16 changes: 8 additions & 8 deletions packages/core/test/conformance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ 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()) {
if (isDenoV1()) {
continue;
}
await tester.test(v);
Expand All @@ -115,7 +115,7 @@ 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()) {
if (isDenoV1()) {
continue;
}
await tester.test(v);
Expand Down Expand Up @@ -203,7 +203,7 @@ 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()) {
if (isDenoV1()) {
continue;
}
await tester.test(v);
Expand All @@ -226,7 +226,7 @@ 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()) {
if (isDenoV1()) {
continue;
}
await tester.test(v);
Expand Down Expand Up @@ -314,7 +314,7 @@ 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()) {
if (isDenoV1()) {
continue;
}
await tester.test(v);
Expand All @@ -337,7 +337,7 @@ 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()) {
if (isDenoV1()) {
continue;
}
await tester.test(v);
Expand Down Expand Up @@ -425,7 +425,7 @@ 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()) {
if (isDenoV1()) {
continue;
}
await tester.test(v);
Expand All @@ -448,7 +448,7 @@ 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()) {
if (isDenoV1()) {
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 a012cf6

Please sign in to comment.