Skip to content

Commit

Permalink
Switch to noble-post-quantum for ML-DSA
Browse files Browse the repository at this point in the history
  • Loading branch information
larabr committed Jul 4, 2024
1 parent 306d167 commit 3fb90cb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 160 deletions.
181 changes: 39 additions & 142 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 @@ -65,7 +65,7 @@
"@noble/curves": "^1.4.0",
"@noble/ed25519": "^1.7.3",
"@noble/hashes": "^1.4.0",
"@asanrom/dilithium": "^1.1.0",
"@noble/post-quantum": "^0.1.0",
"@openpgp/asmcrypto.js": "^3.1.0",
"@openpgp/crystals-kyber-js": "^1.1.1",
"@openpgp/jsdoc": "^3.6.11",
Expand Down
23 changes: 6 additions & 17 deletions src/crypto/public_key/post_quantum/signature/ml_dsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@ import enums from '../../../../enums';
export async function generate(algo) {
switch (algo) {
case enums.publicKey.pqc_mldsa_ed25519: {
const { DilithiumKeyPair, DilithiumLevel } = await import('@asanrom/dilithium');

const level = DilithiumLevel.get(3);
const keyPair = DilithiumKeyPair.generate(level);

const mldsaSecretKey = keyPair.getPrivateKey().getBytes();
const mldsaPublicKey = keyPair.getPublicKey().getBytes();

const { ml_dsa65 } = await import('@noble/post-quantum/ml-dsa');
const { secretKey: mldsaSecretKey, publicKey: mldsaPublicKey } = ml_dsa65.keygen();
return { mldsaSecretKey, mldsaPublicKey };
}
default:
Expand All @@ -21,10 +15,8 @@ export async function generate(algo) {
export async function sign(algo, mldsaSecretKey, dataDigest) {
switch (algo) {
case enums.publicKey.pqc_mldsa_ed25519: {
const { DilithiumPrivateKey, DilithiumLevel } = await import('@asanrom/dilithium');
const level = DilithiumLevel.get(3);
const secretKey = DilithiumPrivateKey.fromBytes(mldsaSecretKey, level);
const mldsaSignature = secretKey.sign(dataDigest).getBytes();
const { ml_dsa65 } = await import('@noble/post-quantum/ml-dsa');
const mldsaSignature = ml_dsa65.sign(mldsaSecretKey, dataDigest);
return { mldsaSignature };
}
default:
Expand All @@ -35,11 +27,8 @@ export async function sign(algo, mldsaSecretKey, dataDigest) {
export async function verify(algo, mldsaPublicKey, dataDigest, mldsaSignature) {
switch (algo) {
case enums.publicKey.pqc_mldsa_ed25519: {
const { DilithiumPublicKey, DilithiumSignature, DilithiumLevel } = await import('@asanrom/dilithium');
const level = DilithiumLevel.get(3);
const publicKey = DilithiumPublicKey.fromBytes(mldsaPublicKey, level);
const signature = DilithiumSignature.fromBytes(mldsaSignature, level);
return publicKey.verifySignature(dataDigest, signature);
const { ml_dsa65 } = await import('@noble/post-quantum/ml-dsa');
return ml_dsa65.verify(mldsaPublicKey, dataDigest, mldsaSignature);
}
default:
throw new Error('Unsupported signature algorithm');
Expand Down

0 comments on commit 3fb90cb

Please sign in to comment.