Skip to content

Commit

Permalink
Merge pull request #454 from dajiaji/rename-to-xwing
Browse files Browse the repository at this point in the history
Rename HybridkemXWing to XWing.
  • Loading branch information
dajiaji authored Nov 5, 2024
2 parents 56b22b8 + edd51e7 commit 05c44ee
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 176 deletions.
323 changes: 182 additions & 141 deletions npm/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/common/src/identifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const KemId = {
DhkemX25519HkdfSha256: 0x0020,
DhkemX448HkdfSha512: 0x0021,
HybridkemX25519Kyber768: 0x0030,
HybridkemXWing: 0x647a,
XWing: 0x647a,
} as const;

/**
Expand Down
20 changes: 10 additions & 10 deletions packages/hybridkem-x-wing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Then, you can use the module from code like this:

```ts
import { Aes256Gcm, CipherSuite, HkdfSha256 } from "@hpke/core";
import { HybridkemXWing } from "@hpke/hybridkem-x-wing";
import { XWing } from "@hpke/hybridkem-x-wing";
```

### Deno
Expand All @@ -79,7 +79,7 @@ Using esm.sh:
CipherSuite,
HkdfSha256,
} from "https://esm.sh/@hpke/core@<SEMVER>";
import { HybridkemXWing } from "https://esm.sh/@hpke/hybridkem-x-wing@<SEMVER>";
import { XWing } from "https://esm.sh/@hpke/hybridkem-x-wing@<SEMVER>";
// ...
</script>

Expand All @@ -90,7 +90,7 @@ Using esm.sh:
CipherSuite,
HkdfSha256,
} from "https://esm.sh/@hpke/core";
import { HybridkemXWing } from "https://esm.sh/@hpke/hybridkem-x-wing";
import { XWing } from "https://esm.sh/@hpke/hybridkem-x-wing";
// ...
</script>
```
Expand All @@ -105,7 +105,7 @@ Using unpkg:
CipherSuite,
HkdfSha256,
} from "https://unpkg.com/@hpke/core@<SEMVER>/esm/mod.js";
import { HybridkemXWing } from "https://unpkg.com/@hpke/hybridkem-x-wing@<SEMVER>/esm/mod.js";
import { XWing } from "https://unpkg.com/@hpke/hybridkem-x-wing@<SEMVER>/esm/mod.js";
// ...
</script>
```
Expand All @@ -118,12 +118,12 @@ This section shows some typical usage examples.

```js
import { Aes256Gcm, CipherSuite, HkdfSha256 } from "@hpke/core";
import { HybridkemXWing } from "@hpke/hybridkem-x-wing";
import { XWing } from "@hpke/hybridkem-x-wing";

async function doHpke() {
// setup
const suite = new CipherSuite({
kem: new HybridkemXWing(),
kem: new XWing(),
kdf: new HkdfSha256(),
aead: new Aes256Gcm(),
});
Expand Down Expand Up @@ -161,12 +161,12 @@ try {

```ts
import { Aes256Gcm, CipherSuite, HkdfSha256 } from "@hpke/core";
import { HybridkemXWing } from "@hpke/hybridkem-x-wing";
import { XWing } from "@hpke/hybridkem-x-wing";

async function doHpke() {
// setup
const suite = new CipherSuite({
kem: new HybridkemXWing(),
kem: new XWing(),
kdf: new HkdfSha256(),
aead: new Aes256Gcm(),
});
Expand Down Expand Up @@ -212,12 +212,12 @@ try {
CipherSuite,
HkdfSha256,
} from "https://esm.sh/@hpke/core";
import { HybridkemXWing } from "https://esm.sh/@hpke/hybridkem-x-wing";
import { XWing } from "https://esm.sh/@hpke/hybridkem-x-wing";
globalThis.doHpke = async () => {
try {
const suite = new CipherSuite({
kem: new HybridkemXWing(),
kem: new XWing(),
kdf: new HkdfSha256(),
aead: new Aes256Gcm(),
});
Expand Down
2 changes: 1 addition & 1 deletion packages/hybridkem-x-wing/mod.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { HybridkemXWing } from "./src/hybridkemXWing.ts";
export { XWing } from "./src/xWing.ts";
4 changes: 2 additions & 2 deletions packages/hybridkem-x-wing/samples/deno/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Aes256Gcm, CipherSuite, HkdfSha256 } from "@hpke/core";
import { HybridkemXWing } from "@hpke/hybridkem-x-wing";
import { XWing } from "@hpke/hybridkem-x-wing";

async function doHpke() {
// setup
const suite = new CipherSuite({
kem: new HybridkemXWing(),
kem: new XWing(),
kdf: new HkdfSha256(),
aead: new Aes256Gcm(),
});
Expand Down
4 changes: 2 additions & 2 deletions packages/hybridkem-x-wing/samples/node/app.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Aes256Gcm, CipherSuite, HkdfSha256 } from "@hpke/core";
import { HybridkemXWing } from "@hpke/hybridkem-x-wing";
import { XWing } from "@hpke/hybridkem-x-wing";

async function doHpke() {
const suite = new CipherSuite({
kem: new HybridkemXWing(),
kem: new XWing(),
kdf: new HkdfSha256(),
aead: new Aes256Gcm(),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ function combiner(
*
* ```ts
* import { Aes128Gcm, CipherSuite, HkdfSha256 } from "@hpke/core";
* import { HybridkemXWing } from "@hpke/hybridkem-x-wing";
* import { XWing } from "@hpke/hybridkem-x-wing";
* const suite = new CipherSuite({
* kem: new HybridkemXWing(),
* kem: new XWing(),
* kdf: new HkdfSha256(),
* aead: new Aes128Gcm(),
* });
* ```
*/
export class HybridkemXWing implements KemInterface {
public readonly id: KemId = KemId.HybridkemXWing;
export class XWing implements KemInterface {
public readonly id: KemId = KemId.XWing;
public readonly name: string = "X-Wing";
public readonly secretSize: number = 32;
public readonly encSize: number = 1120;
Expand Down
18 changes: 9 additions & 9 deletions packages/hybridkem-x-wing/test/hybridkemXWing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import { describe, it } from "@std/testing/bdd";

import { hexToBytes, loadCrypto } from "@hpke/common";
import { Aes128Gcm, CipherSuite, HkdfSha256, KemId } from "@hpke/core";
import { HybridkemXWing } from "../mod.ts";
import { XWing } from "../mod.ts";
import { TEST_VECTORS } from "./testVectors.ts";

describe("HybridkemXWing", () => {
describe("XWing", () => {
describe("constructor", () => {
it("should have a correct ciphersuite", () => {
const kem = new HybridkemXWing();
const kem = new XWing();
assertEquals(kem.secretSize, 32);
assertEquals(kem.encSize, 1120);
assertEquals(kem.publicKeySize, 1216);
assertEquals(kem.privateKeySize, 32);
assertEquals(kem.id, KemId.HybridkemXWing);
assertEquals(kem.id, KemId.XWing);
assertEquals(kem.id, 0x647a);
});
});
Expand All @@ -35,7 +35,7 @@ describe("HybridkemXWing", () => {
assertEquals(ct.length, 1120);
assertEquals(ss.length, 32);

const recipient = new HybridkemXWing();
const recipient = new XWing();
const kp = await recipient.generateKeyPairDerand(seed);
assertEquals(
(await recipient.serializePublicKey(kp.publicKey)).byteLength,
Expand All @@ -49,7 +49,7 @@ describe("HybridkemXWing", () => {
new Uint8Array(await recipient.serializePublicKey(kp.publicKey)),
pk,
);
const sender = new HybridkemXWing();
const sender = new XWing();
const res = await sender.encap({
recipientPublicKey: kp.publicKey,
ekm: eseed,
Expand All @@ -70,10 +70,10 @@ describe("HybridkemXWing", () => {
});

describe("README examples", () => {
describe("HybridkemXWing/HkdfShar256/Aes128Gcm", () => {
describe("XWing/HkdfShar256/Aes128Gcm", () => {
it("should work normally with generateKeyPair", async () => {
const suite = new CipherSuite({
kem: new HybridkemXWing(),
kem: new XWing(),
kdf: new HkdfSha256(),
aead: new Aes128Gcm(),
});
Expand All @@ -95,7 +95,7 @@ describe("README examples", () => {

it("should work normally with deriveKeyPair", async () => {
const suite = new CipherSuite({
kem: new HybridkemXWing(),
kem: new XWing(),
kdf: new HkdfSha256(),
aead: new Aes128Gcm(),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
HkdfSha384,
HkdfSha512,
} from "./src/hpke-core.js";
import { HybridkemXWing } from "./src/hpke-hybridkem-x-wing.js";
import { XWing } from "./src/hpke-hybridkem-x-wing.js";

// const kems = [
// new DhkemP256HkdfSha256(),
Expand All @@ -36,7 +36,7 @@
globalThis.run = async () => {
let pass = 0;
let fail = 0;
const kem = new HybridkemXWing();
const kem = new XWing();
for (const kdf of kdfs) {
for (const aead of aeads) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
KdfId,
} from "@hpke/core";

import { HybridkemXWing } from "@hpke/hybridkem-x-wing";
import { XWing } from "@hpke/hybridkem-x-wing";

function createKdf(id: number): KdfInterface {
switch (id) {
Expand Down Expand Up @@ -47,7 +47,7 @@ function createAead(id: number): AeadInterface {
}

test("bun - normal cases", async () => {
const kem = new HybridkemXWing();
const kem = new XWing();
for (const kdf of [0x0001, 0x0002, 0x0003]) {
for (const aead of [0x0001, 0x0002]) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
KdfId,
} from "@hpke/core";

import { HybridkemXWing } from "@hpke/hybridkem-x-wing";
import { XWing } from "@hpke/hybridkem-x-wing";

function createKdf(id) {
switch (id) {
Expand Down Expand Up @@ -51,7 +51,7 @@ export async function testServer(request) {
if (kdfStr === null || aeadStr === null) {
return new Response("ng: invalid params");
}
const kem = new HybridkemXWing();
const kem = new XWing();
const kdf = Number.parseInt(kdfStr);
const aead = Number.parseInt(aeadStr);
if (Number.isNaN(kdf) || Number.isNaN(aead)) {
Expand Down

0 comments on commit 05c44ee

Please sign in to comment.