docs: verification timing does show which half failed, harmlessly (QA S-06)

The design doc, VerifyingKey::verify and Error::InvalidSignature claimed
that both halves are always checked so timing does not tell which failed.
Not so: a malformed ML-DSA half is refused at decode without verification,
and verify_strict returns early on a bad R (QA measured 59/187/217 us
against 225 us). The docs now say the error does not name the half, the
timing may, and that is fine because verification uses only public data
(RFC 10073 3.3 allows failing early). The `&` and its comment, which
bought nothing (both booleans were already computed), become a plain `&&`.
No behaviour change.
This commit is contained in:
2026-11-26 03:46:47 +01:00
parent 413dbaa279
commit 274cf37d69
3 changed files with 14 additions and 9 deletions
+5 -2
View File
@@ -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)
+2 -1
View File
@@ -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.
+7 -6
View File
@@ -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::<MlDsa65>::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) }
}
}