From 0f30abcf0261d031dcdf6dac02ccc8a5940243a7 Mon Sep 17 00:00:00 2001 From: larabr <7375870+larabr@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:40:46 +0200 Subject: [PATCH] Temp (?): manually encode context in ML-DSA (missing step in noble-post-quantum) --- src/crypto/public_key/post_quantum/signature/ml_dsa.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/crypto/public_key/post_quantum/signature/ml_dsa.js b/src/crypto/public_key/post_quantum/signature/ml_dsa.js index 09dc40aaa..7c2fa35ef 100644 --- a/src/crypto/public_key/post_quantum/signature/ml_dsa.js +++ b/src/crypto/public_key/post_quantum/signature/ml_dsa.js @@ -1,4 +1,5 @@ import enums from '../../../../enums'; +import util from '../../../../util'; import hash from '../../../hash'; import { getRandomBytes } from '../../../random'; @@ -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: @@ -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');