diff --git a/docs/02_signatures.md b/docs/02_signatures.md index e8f2598..d102b5a 100644 --- a/docs/02_signatures.md +++ b/docs/02_signatures.md @@ -104,8 +104,11 @@ pub mod sign { `AppContext` is a newtype that can only be built with the `domi/arcanum/v2/sig/app/` prefix, so a caller can never pass an empty or foreign context by accident. The bare RFC interface (any ctx, deterministic ML-DSA) exists only under `hazmat`, for the known-answer tests. Verification returns one error, -`Error::InvalidSignature`, whichever half failed, and checks both halves before answering, so timing does not -tell which component failed (RFC 10073 §3.2). +`Error::InvalidSignature`, whichever half failed. **Correction (QA S-06):** the timing *does* tell which half +failed: a malformed ML-DSA half is refused at decode without being verified, and `verify_strict` returns early +on an undecodable or small-order R (QA measured 59 µs, 187 µs and 217 µs against 225 µs for a valid signature). +That is harmless: verification handles only public data (the message, the public key, the signature), so its +timing leaks nothing secret, and RFC 10073 §3.3 allows failing early. No dummy work is added. ## Tests (written first) diff --git a/src/error.rs b/src/error.rs index c4d895b..049d1d1 100644 --- a/src/error.rs +++ b/src/error.rs @@ -86,7 +86,8 @@ pub enum Error { /// The Ed25519 half of a verifying key is not a canonically encoded point, or is a point of /// small order (a weak key). InvalidVerifyingKey, - /// A signature does not verify: one half, the other, or both (deliberately not said which). + /// A signature does not verify: one half, the other, or both. The error does not say which; the + /// verification time may, which is harmless because verification uses only public data. InvalidSignature, /// ML-DSA signing failed (the randomness source or the rejection-sampling bound). Retry with /// fresh randomness. diff --git a/src/sign.rs b/src/sign.rs index d38a6e8..4865d55 100644 --- a/src/sign.rs +++ b/src/sign.rs @@ -223,22 +223,23 @@ impl VerifyingKey { /// Verify a signature over `msg` made with [`SigningKey::sign`] under the same context. /// /// # Errors - /// [`Error::InvalidSignature`] if either half (or both) fails. Both halves are always checked - /// before answering, and the error does not say which failed (RFC 10073 §3.2). + /// [`Error::InvalidSignature`] if either half (or both) fails. The error does not say which + /// half failed; the time taken may (a malformed ML-DSA half is refused at decode, and + /// `verify_strict` stops early on a bad R). That is fine: verification handles only public data, + /// so its timing reveals nothing secret (RFC 10073 §3.3 allows failing early; QA S-06). pub fn verify(&self, msg: &[u8], ctx: &AppContext, sig: &Signature) -> Result<(), Error> { self.verify_m_prime(&MPrime::of_message(msg, ctx.as_bytes())?, sig) } fn verify_m_prime(&self, mp: &MPrime, sig: &Signature) -> Result<(), Error> { let mp = mp.as_bytes(); - // A malformed ML-DSA half (bad hint encoding, z out of range) cannot verify; that it was - // malformed is public, the signature itself says so. + // A malformed ML-DSA half (bad hint encoding, z out of range) is refused at decode, without + // the verification step: quicker, and visible in the timing, but everything here is public. let ml_ok = ml_dsa::Signature::::try_from(&sig.0[..ML_DSA_SIGNATURE_LEN]) .is_ok_and(|s| self.ml.verify_with_context(mp, LABEL, &s)); let ed_sig = ed25519_dalek::Signature::from_bytes(&array::from_fn(|i| sig.0[ML_DSA_SIGNATURE_LEN + i])); let ed_ok = self.ed.verify_strict(mp, &ed_sig).is_ok(); - // `&`, not `&&`: both results are computed whatever the first one says. - if ml_ok & ed_ok { Ok(()) } else { Err(Error::InvalidSignature) } + if ml_ok && ed_ok { Ok(()) } else { Err(Error::InvalidSignature) } } }