feat: hybrid signatures ML-DSA-65 + Ed25519, RFC 10073 id-MLDSA65-Ed25519-SHA512

arcanum::sign, as docs/02_signatures.md sets out. M' = Prefix || Label ||
u8(len ctx) || ctx || SHA-512(M), built on the stack. The ML-DSA-65 half is
ExpandedSigningKey::sign_randomized(M', ctx = Label, rng), hedged; the
Ed25519 half is pure Ed25519 over M' (try_sign), checked with verify_strict.
Verification computes both halves before answering, and returns one
InvalidSignature whichever failed. ml-dsa's Signer/Verifier traits,
sign_deterministic and sign_mu_deterministic are never called.

- SigningKey: two 32-byte seeds (RFC 10073's private key format), the
  expanded ML-DSA key boxed; ZeroizeOnDrop, not Clone, Debug redacted.
- VerifyingKey: 1984 bytes; refuses an Ed25519 half that is not a point,
  not its canonical encoding, or of small order (InvalidVerifyingKey).
- AppContext: only "domi/arcanum/v2/sig/app/" + a 1..=231-byte label.
- bind_kem_key / verify_binding: an X-Wing public key bound to a key id and
  an inclusive validity window under "domi/arcanum/v2/sig/kem-key"; the
  message is hashed field by field; window and id are checked first, then
  the signature, then now (InvalidValidity, TooLong, InvalidSignature,
  OutsideValidity).
- sign_composite_raw / verify_composite_raw: the bare RFC ctx, hazmat only.
  They still take an RNG (the ML-DSA half stays hedged), not the
  deterministic variant the doc mentions.
- Error gains TooLong, InvalidVerifyingKey, InvalidSignature,
  SigningFailed, InvalidValidity, OutsideValidity; Input gains SigningKey,
  VerifyingKey, Signature, Context, KeyId.

Also fixes tests/kat_mldsa65.rs, which passed a &[&Vec<u8>] to
sign_internal and did not compile.

cargo test (debug): 121 passed, 0 failed (82 from v0.1.0, golden_v1
unchanged). clippy --all-targets --all-features -D warnings: clean.
This commit is contained in:
2026-11-25 13:12:22 +01:00
parent 2a432f5d86
commit 5a52854ccc
5 changed files with 485 additions and 7 deletions
+44
View File
@@ -14,6 +14,16 @@ pub enum Input {
Ciphertext,
/// A sealed box.
SealedBox,
/// A composite signing key (ML-DSA-65 seed || Ed25519 seed).
SigningKey,
/// A composite verifying key (ML-DSA-65 public key || Ed25519 public key).
VerifyingKey,
/// A composite signature (ML-DSA-65 signature || Ed25519 signature).
Signature,
/// A signature context, or the caller's label inside one.
Context,
/// The key id in a key binding.
KeyId,
}
impl fmt::Display for Input {
@@ -23,6 +33,11 @@ impl fmt::Display for Input {
Input::SecretKey => "secret key",
Input::Ciphertext => "ciphertext",
Input::SealedBox => "sealed box",
Input::SigningKey => "signing key",
Input::VerifyingKey => "verifying key",
Input::Signature => "signature",
Input::Context => "signature context",
Input::KeyId => "key id",
})
}
}
@@ -49,6 +64,15 @@ pub enum Error {
/// The length that was given.
actual: usize,
},
/// The input is longer than the largest valid value.
TooLong {
/// What was being parsed.
input: Input,
/// The maximum length in bytes.
maximum: usize,
/// The length that was given.
actual: usize,
},
/// The ML-KEM-768 part of a public key fails the FIPS 203 §7.2 encapsulation key check.
InvalidPublicKey,
/// An X25519 value is a low-order point, so the classical half would contribute nothing.
@@ -59,6 +83,18 @@ pub enum Error {
DecryptionFailed,
/// The plaintext is longer than ChaCha20-Poly1305 allows (about 256 GiB).
MessageTooLong,
/// 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).
InvalidSignature,
/// ML-DSA signing failed (the randomness source or the rejection-sampling bound). Retry with
/// fresh randomness.
SigningFailed,
/// A key binding's validity window ends before it starts (`not_before > not_after`).
InvalidValidity,
/// A key binding is authentic, but `now` lies outside its validity window.
OutsideValidity,
}
impl fmt::Display for Error {
@@ -70,11 +106,19 @@ impl fmt::Display for Error {
Error::TooShort { input, minimum, actual } => {
write!(f, "{input} is too short: at least {minimum} bytes, got {actual}")
}
Error::TooLong { input, maximum, actual } => {
write!(f, "{input} is too long: at most {maximum} bytes, got {actual}")
}
Error::InvalidPublicKey => f.write_str("public key fails the ML-KEM-768 encapsulation key check"),
Error::NonContributory => f.write_str("X25519 value is a low-order point"),
Error::UnsupportedVersion(v) => write!(f, "sealed box version {v} is not supported"),
Error::DecryptionFailed => f.write_str("sealed box could not be opened"),
Error::MessageTooLong => f.write_str("message is too long to seal"),
Error::InvalidVerifyingKey => f.write_str("verifying key has a weak or non-canonical Ed25519 point"),
Error::InvalidSignature => f.write_str("signature does not verify"),
Error::SigningFailed => f.write_str("signing failed; retry with fresh randomness"),
Error::InvalidValidity => f.write_str("key binding validity ends before it starts"),
Error::OutsideValidity => f.write_str("key binding is not valid at this time"),
}
}
}