Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activate X25519 tests for @hpke/core. #434

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading