Skip to content

Commit

Permalink
Temp (?): manually encode context in ML-DSA (missing step in noble-po…
Browse files Browse the repository at this point in the history
…st-quantum)
  • Loading branch information
larabr committed Sep 23, 2024
1 parent ceeebd7 commit 0f30abc
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/crypto/public_key/post_quantum/signature/ml_dsa.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import enums from '../../../../enums';
import util from '../../../../util';
import hash from '../../../hash';
import { getRandomBytes } from '../../../random';

Expand All @@ -18,7 +19,8 @@ export async function sign(algo, mldsaSecretKey, dataDigest) {
switch (algo) {
case enums.publicKey.pqc_mldsa_ed25519: {
const { ml_dsa65 } = await import('@noble/post-quantum/ml-dsa');
const mldsaSignature = ml_dsa65.sign(mldsaSecretKey, dataDigest);
const dataDigestWithContext = util.concatUint8Array([new Uint8Array([0, 0]), dataDigest]);
const mldsaSignature = ml_dsa65.sign(mldsaSecretKey, dataDigestWithContext);
return { mldsaSignature };
}
default:
Expand All @@ -30,7 +32,8 @@ export async function verify(algo, mldsaPublicKey, dataDigest, mldsaSignature) {
switch (algo) {
case enums.publicKey.pqc_mldsa_ed25519: {
const { ml_dsa65 } = await import('@noble/post-quantum/ml-dsa');
return ml_dsa65.verify(mldsaPublicKey, dataDigest, mldsaSignature);
const dataDigestWithContext = util.concatUint8Array([new Uint8Array([0, 0]), dataDigest]);
return ml_dsa65.verify(mldsaPublicKey, dataDigestWithContext, mldsaSignature);
}
default:
throw new Error('Unsupported signature algorithm');
Expand Down

0 comments on commit 0f30abc

Please sign in to comment.