Skip to content

Commit

Permalink
Merge pull request #476 from dajiaji/ml-kem-initial-public-release
Browse files Browse the repository at this point in the history
ml-kem: initial public preview release.
  • Loading branch information
dajiaji authored Nov 10, 2024
2 parents 0b586f0 + 9fb6a65 commit 6d8cbb2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ npm install @hpke/core

Following extensions can be installed in the same manner:

- `@hpke/core`
- `@hpke/chacha20poly1305`
- `@hpke/dhkem-x25519`
- `@hpke/dhkem-x448`
- `@hpke/dhkem-secp256k1`
- `@hpke/hybridkem-x25519-kyber768`
- `@hpke/hybridkem-x-wing`
- `@hpke/ml-kem`

Then, you can use it as follows:

Expand Down Expand Up @@ -117,6 +117,7 @@ The hpke-js includes the following packages.
| @hpke/dhkem-x448 | [![npm](https://img.shields.io/npm/v/@hpke/dhkem-x448?color=%23EE3214)](https://www.npmjs.com/package/@hpke/dhkem-x448)<br/>[![JSR](https://jsr.io/badges/@hpke/dhkem-x448)](https://jsr.io/@hpke/dhkem-x448) | The HPKE module extension for DHKEM(X448, HKDF-SHA512).<br/>[README](https://github.com/dajiaji/hpke-js/blob/main/packages/dhkem-x448/README.md) / [samples](https://github.com/dajiaji/hpke-js/tree/main/packages/dhkem-x448/samples) |
| hpke-js | [![npm](https://img.shields.io/npm/v/hpke-js?color=%23EE3214)](https://www.npmjs.com/package/hpke-js) | The HPKE module supporting all of the ciphersuites defined in [RFC9180](https://datatracker.ietf.org/doc/html/rfc9180), which consists of the above @hpke/{core, dhkem-x25519, dhkem-x448, chacha20poly1305} internally.<br/>[README](https://github.com/dajiaji/hpke-js/tree/main/packages/hpke-js/README.md) / [samples](https://github.com/dajiaji/hpke-js/tree/main/packages/hpke-js/samples) |
| @hpke/hpke-js | [![JSR](https://jsr.io/badges/@hpke/hpke-js)](https://jsr.io/@hpke/hpke-js) | The JSR version of the above `hpke-js`.<br/>[README](https://github.com/dajiaji/hpke-js/tree/main/packages/hpke-js/README.md) / [samples](https://github.com/dajiaji/hpke-js/tree/main/packages/hpke-js/samples) |
| @hpke/ml-kem | [![npm](https://img.shields.io/npm/v/@hpke/ml-kem?color=%23EE3214)](https://www.npmjs.com/package/@hpke/ml-kem)<br/>[![JSR](https://jsr.io/badges/@hpke/ml-kem)](https://jsr.io/@hpke/ml-kem) | **EXPERIMENTAL AND NOT STANDARDIZED**<br/>The HPKE module extension for [ML-KEM](https://datatracker.ietf.org/doc/draft-connolly-cfrg-hpke-mlkem/).<br/>[README](https://github.com/dajiaji/hpke-js/blob/main/packages/ml-kem/README.md) / [samples](https://github.com/dajiaji/hpke-js/tree/main/packages/ml-kem/samples) |
| @hpke/hybridkem-x-wing | [![npm](https://img.shields.io/npm/v/@hpke/hybridkem-x-wing?color=%23EE3214)](https://www.npmjs.com/package/@hpke/hybridkem-x-wing)<br/>[![JSR](https://jsr.io/badges/@hpke/hybridkem-x-wing)](https://jsr.io/@hpke/hybridkem-x-wing) | **EXPERIMENTAL AND NOT STANDARDIZED**<br/>The HPKE module extension for [X-Wing: general-purpose hybrid post-quantum KEM](https://datatracker.ietf.org/doc/draft-connolly-cfrg-xwing-kem/).<br/>[README](https://github.com/dajiaji/hpke-js/blob/main/packages/hybridkem-x-wing/README.md) / [samples](https://github.com/dajiaji/hpke-js/tree/main/packages/hybridkem-x-wing/samples) |
| @hpke/hybridkem-x25519-kyber768 | [![npm](https://img.shields.io/npm/v/@hpke/hybridkem-x25519-kyber768?color=%23EE3214)](https://www.npmjs.com/package/@hpke/hybridkem-x25519-kyber768)<br/>[![JSR](https://jsr.io/badges/@hpke/hybridkem-x25519-kyber768)](https://jsr.io/@hpke/hybridkem-x25519-kyber768) | **EXPERIMENTAL AND NOT STANDARDIZED**<br/>The HPKE module extension for the hybrid post-quantum KEM currently named [X25519Kyber768Draft00](https://datatracker.ietf.org/doc/draft-westerbaan-cfrg-hpke-xyber768d00/).<br/>[README](https://github.com/dajiaji/hpke-js/blob/main/packages/hybridkem-x25519-kyber768/README.md) / [samples](https://github.com/dajiaji/hpke-js/tree/main/packages/hybridkem-x25519-kyber768/samples) |
| @hpke/dhkem-secp256k1 | [![npm](https://img.shields.io/npm/v/@hpke/dhkem-secp256k1?color=%23EE3214)](https://www.npmjs.com/package/@hpke/dhkem-secp256k1)<br/>[![JSR](https://jsr.io/badges/@hpke/dhkem-secp256k1)](https://jsr.io/@hpke/dhkem-secp256k1) | **EXPERIMENTAL AND NOT STANDARDIZED**<br/>The HPKE module extension for DHKEM(secp256k1, HKDF-SHA256).<br/>[README](https://github.com/dajiaji/hpke-js/blob/main/packages/dhkem-secp256k1/README.md) / [samples](https://github.com/dajiaji/hpke-js/tree/main/packages/dhkem-secp256k1/samples) |
Expand All @@ -138,6 +139,9 @@ The hpke-js includes the following packages.
| DHKEM (P-521, HKDF-SHA512) | ✅<br>hpke-js<br>@hpke/core | ✅<br>hpke-js<br>@hpke/core | | ✅<br>hpke-js<br>@hpke/core | ✅<br>hpke-js<br>@hpke/core |
| DHKEM (X25519, HKDF-SHA256) | ✅<br>hpke-js<br>@hpke/dhkem-x25519 | ✅<br>hpke-js<br>@hpke/dhkem-x25519 | ✅<br>hpke-js<br>@hpke/dhkem-x25519 | ✅<br>hpke-js<br>@hpke/dhkem-x25519 | ✅<br>hpke-js<br>@hpke/dhkem-x25519 |
| DHKEM (X448, HKDF-SHA512) | ✅<br>hpke-js<br>@hpke/dhkem-x448 | ✅<br>hpke-js<br>@hpke/dhkem-x448 | ✅<br>hpke-js<br>@hpke/dhkem-x448 | ✅<br>hpke-js<br>@hpke/dhkem-x448 | ✅<br>hpke-js<br>@hpke/dhkem-x448 |
| ML-KEM-512 | ✅<br>@hpke/ml-kem | ✅<br>@hpke/ml-kem | ✅<br>@hpke/ml-kem | ✅<br>@hpke/ml-kem | ✅<br>@hpke/ml-kem |
| ML-KEM-768 | ✅<br>@hpke/ml-kem | ✅<br>@hpke/ml-kem | ✅<br>@hpke/ml-kem | ✅<br>@hpke/ml-kem | ✅<br>@hpke/ml-kem |
| ML-KEM-1024 | ✅<br>@hpke/ml-kem | ✅<br>@hpke/ml-kem | ✅<br>@hpke/ml-kem | ✅<br>@hpke/ml-kem | ✅<br>@hpke/ml-kem |
| X-Wing | ✅<br>@hpke/hybridkem-x-wing | ✅<br>@hpke/hybridkem-x-wing | ✅<br>@hpke/hybridkem-x-wing | ✅<br>@hpke/hybridkem-x-wing | ✅<br>@hpke/hybridkem-x-wing |
| Hybrid KEM (X25519, Kyber768) | ✅<br>@hpke/hybridkem-x25519-kyber768 | ✅<br>@hpke/hybridkem-x25519-kyber768 | ✅<br>@hpke/hybridkem-x25519-kyber768 | ✅<br>@hpke/hybridkem-x25519-kyber768 | ✅<br>@hpke/hybridkem-x25519-kyber768 |
| DHKEM (secp256k1, HKDF-SHA256) | ✅<br>@hpke/dhkem-secp256k1 | ✅<br>@hpke/dhkem-secp256k1 | ✅<br>@hpke/dhkem-secp256k1 | ✅<br>@hpke/dhkem-secp256k1 | ✅<br>@hpke/dhkem-secp256k1 |
Expand Down
4 changes: 4 additions & 0 deletions packages/ml-kem/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# Changes

Released 2024-11-10

- First public preview release.
25 changes: 13 additions & 12 deletions packages/ml-kem/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</div>

<div align="center">
A TypeScript <a href="https://datatracker.ietf.org/doc/html/rfc9180">Hybrid Public Key Encryption (HPKE)</a> module extension for <a href="https://datatracker.ietf.org/doc/draft-connolly-cfrg-xwing-kem/">X-Wing: general-purpose hybrid post-quantum KEM</a>.
A TypeScript <a href="https://datatracker.ietf.org/doc/html/rfc9180">Hybrid Public Key Encryption (HPKE)</a> module extension for <a href="https://datatracker.ietf.org/doc/draft-connolly-cfrg-hpke-mlkem/">ML-KEM for HPKE</a>.
</div>
<p></p>

Expand Down Expand Up @@ -34,23 +34,24 @@ async function doHpke() {
const jwkPub = {
k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YZUjXIrA7W70Vesmd7hwKmqE",
key_ops: [],
};
const pk = await suite.kem.importKey("jwk", jwkPub, true);
// In addition to importing keys from external sources, you can also generate keys as follows:
// const rkp = await suite.kem.generateKeyPair();
// const rkp = await suite.kem.deriveKeyPair(random32bytesValue);
// const rkp = await suite.kem.deriveKeyPair(random64bytesValue);

const sender = await suite.createSenderContext({ recipientPublicKey: pk });

const jwkPriv = {
kty: "AKP",
kid: "01",
alg: "X-Wing",
priv: "f5wrpOiPgn1hYEVQdgWFPtc7gJP277yI6xpurPpm7yY",
alg: "ML-KEM-768",
priv:
"1pz8ZPhNTzPkxU4Wa3_5KDo5SYalObI5h6EPOdLZaJtt5i40ZaVcnHigfSZb6FQLPliwgBoSTQf_ErQ41SAuoA",
key_ops: ["deriveBits"],
};
const sk = await suite.kem.importKey("jwk", jwkPriv, false);
Expand Down Expand Up @@ -188,7 +189,7 @@ async function doHpke() {

const rkp = await suite.kem.generateKeyPair();

// Note that the `ct` (ciphertext) resulting from X-Wing Encapsulate() is set to `sender.enc`.
// Note that the `ct` (ciphertext) resulting from ML-KEM::Encaps() is set to `sender.enc`.
const sender = await suite.createSenderContext({
recipientPublicKey: rkp.publicKey,
});
Expand All @@ -198,7 +199,7 @@ async function doHpke() {

const recipient = await suite.createRecipientContext({
recipientKey: rkp.privateKey,
enc: sender.enc, // == `ct` (ciphertext) in the context of X-Wing
enc: sender.enc, // == `ct` (ciphertext) in the context of ML-KEM
});

// decrypt
Expand Down Expand Up @@ -231,7 +232,7 @@ async function doHpke() {

const rkp = await suite.kem.generateKeyPair();

// Note that the `ct` (ciphertext) resulting from X-Wing::Encapsulate() is set to `sender.enc`.
// Note that the `ct` (ciphertext) resulting from ML-KEM::Encaps() is set to `sender.enc`.
const sender = await suite.createSenderContext({
recipientPublicKey: rkp.publicKey,
});
Expand All @@ -241,7 +242,7 @@ async function doHpke() {

const recipient = await suite.createRecipientContext({
recipientKey: rkp.privateKey,
enc: sender.enc, // == `ct` (ciphertext) in the context of X-Wing
enc: sender.enc, // == `ct` (ciphertext) in the context of ML-KEM
});

// decrypt
Expand Down Expand Up @@ -282,7 +283,7 @@ try {
const rkp = await suite.kem.generateKeyPair();
// Note that the `ct` resulting from X-Wing::Encapsulate() is set to `sender.enc`.
// Note that the `ct` (ciphertext) resulting from ML-KEM::Encaps() is set to `sender.enc`.
const sender = await suite.createSenderContext({
recipientPublicKey: rkp.publicKey,
});
Expand All @@ -293,7 +294,7 @@ try {
const recipient = await suite.createRecipientContext({
recipientKey: rkp.privateKey, // rkp (CryptoKeyPair) is also acceptable.
enc: sender.enc, // == `ct` (ciphertext) in the context of X-Wing
enc: sender.enc, // == `ct` (ciphertext) in the context of ML-KEM
});
// decrypt
Expand Down

0 comments on commit 6d8cbb2

Please sign in to comment.