Skip to content

Commit

Permalink
Switch to standardized version of ML-KEM
Browse files Browse the repository at this point in the history
  • Loading branch information
larabr committed Sep 13, 2024
1 parent 48a938c commit 75568f8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 37 deletions.
53 changes: 27 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@noble/curves": "^1.6.0",
"@noble/ed25519": "^1.7.3",
"@noble/hashes": "^1.5.0",
"@openpgp/crystals-kyber-js": "^1.1.1",
"@noble/post-quantum": "^0.2.0",
"@openpgp/jsdoc": "^3.6.11",
"@openpgp/seek-bzip": "^1.0.5-git",
"@openpgp/tweetnacl": "^1.0.4-1",
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const wasmOptions = {

const getChunkFileName = (chunkInfo, extension) => {
// index files result in chunks named simply 'index', so we rename them to include the package name
if (chunkInfo.name === 'index' && chunkInfo.facadeModuleId) {
if (chunkInfo.name === 'index') {
const packageName = chunkInfo.facadeModuleId.split('/').at(-2); // assume index file is under the root folder
return `${packageName}.${extension}`;
}
Expand Down
15 changes: 6 additions & 9 deletions src/crypto/public_key/post_quantum/kem/ml_kem.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import util from '../../../../util';
export async function generate(algo) {
switch (algo) {
case enums.publicKey.pqc_mlkem_x25519: {
const { MlKem768 } = await import('@openpgp/crystals-kyber-js');
const kyberInstance = new MlKem768();
const [encapsulationKey, decapsulationKey] = await kyberInstance.generateKeyPair();
const { ml_kem768 } = await import('@noble/post-quantum/ml-kem');
const { publicKey: encapsulationKey, secretKey: decapsulationKey } = ml_kem768.keygen();

return { mlkemPublicKey: encapsulationKey, mlkemSecretKey: decapsulationKey };
}
Expand All @@ -18,9 +17,8 @@ export async function generate(algo) {
export async function encaps(algo, mlkemRecipientPublicKey) {
switch (algo) {
case enums.publicKey.pqc_mlkem_x25519: {
const { MlKem768 } = await import('@openpgp/crystals-kyber-js');
const kyberInstance = new MlKem768();
const [mlkemCipherText, mlkemKeyShare] = await kyberInstance.encap(mlkemRecipientPublicKey);
const { ml_kem768 } = await import('@noble/post-quantum/ml-kem');
const { cipherText: mlkemCipherText, sharedSecret: mlkemKeyShare } = ml_kem768.encapsulate(mlkemRecipientPublicKey);

return { mlkemCipherText, mlkemKeyShare };
}
Expand All @@ -32,9 +30,8 @@ export async function encaps(algo, mlkemRecipientPublicKey) {
export async function decaps(algo, mlkemCipherText, mlkemSecretKey) {
switch (algo) {
case enums.publicKey.pqc_mlkem_x25519: {
const { MlKem768 } = await import('@openpgp/crystals-kyber-js');
const kyberInstance = new MlKem768();
const mlkemKeyShare = await kyberInstance.decap(mlkemCipherText, mlkemSecretKey);
const { ml_kem768 } = await import('@noble/post-quantum/ml-kem');
const mlkemKeyShare = ml_kem768.decapsulate(mlkemCipherText, mlkemSecretKey);

return mlkemKeyShare;
}
Expand Down

0 comments on commit 75568f8

Please sign in to comment.