Skip to main content

Module cose_sign

Module cose_sign 

Expand description

Nested-COSE hybrid composite signing for the hyprstream SignedEnvelope (EdDSA + ML-DSA-65).

§Where this sits in the PQUIP hybrid-signature taxonomy

In the taxonomy of draft-ietf-pquip-hybrid-signature-spectrums §1.3.4 this construction is still Weak Non-Separable (WNS), not Strong Non-Separable (SNS). SNS requires fusion — the two algorithms’ signatures combined into a single object that cannot be verified by either component alone. We do not do that: we emit two distinct COSE_Sign1 signatures and bind them by nesting (the outer signs payload ‖ inner_sig).

As of #278 the inner EdDSA layer additionally binds a hybrid-composite alg-id into its signed input when produced in Hybrid mode (see HYBRID_COMPOSITE_ALG_ID / build_hybrid_external_aad). This delivers signature-level non-separability for the inner component: an inner EdDSA signature lifted out of a Hybrid composite (its outer ML-DSA layer stripped) is NO LONGER a valid standalone Classical signature, because its Sig_structure was bound to the hybrid-alg-id that a Classical verifier does not reconstruct. A genuine Classical-mode inner (no hybrid-alg-id) still verifies under a Classical verifier — that intended interop is preserved. We keep the WNS label because the two signatures remain separable objects (no fusion) and a standalone outer ML-DSA layer is still independently meaningful; #278 closes the inner-component separability gap, not the structural one.

Downgrade resistance is now enforced by BOTH crypto and policy:

  1. signature-level non-separability (#278): a stripped-inner attack fails the inner EdDSA signature check (AAD mismatch), not merely a policy gate.
  2. require_pq (fail-closed Hybrid policy): a Hybrid verifier rejects any envelope lacking a valid outer ML-DSA-65 layer, so an attacker who strips the outer layer is also rejected by policy.
  3. kid-anchoring: the PQ key is resolved from a [PqTrustStore] keyed by the EdDSA signer identity, never self-asserted in the COSE object — closing the self-certification gap a naïve two-signature scheme has.

§What the nesting does buy

M3 (#152) replaced an earlier COSE_Sign with two independent signatures over the same payload (a fail-open, trivially strippable scheme). The nesting below is a real improvement over that: because the outer ML-DSA-65 signature covers payload ‖ inner_eddsa_signature, the inner signature is part of the outer’s signed message — so once a verifier has committed to checking the outer (Hybrid policy), it cannot be fed a mismatched inner/outer pair. The nesting binds the two layers together; the requirement to check the outer at all comes from policy.

Classical:                                          external_aad
  inner  = EdDSA  COSE_Sign1 over  payload          base_aad

Hybrid (#278 hybrid-alg-id bound; policy-enforced): external_aad
  inner  = EdDSA  COSE_Sign1 over  payload          [base_aad, hybridAlgID]
  outer  = ML-DSA COSE_Sign1 over  payload‖inner_sig [base_aad, hybridAlgID]

Both layers bind the base external_aad (the CBOR [envelope_schema_id, inner_type_id] schema binding, see crate::cose_sign1::build_external_aad), and — in Hybrid mode only — additionally bind a hybrid-composite algorithm identifier (see HYBRID_COMPOSITE_ALG_ID) into both layers’ external_aad via build_hybrid_external_aad.

§Signature-level non-separability of the inner EdDSA (#278)

Per draft-ietf-pquip-hybrid-signature-spectrums (§ Nested Construction / Non-Separability), signature-level non-separability requires binding a hybridAlgID into each component’s signed input: sig = Sign(hybridAlgID ‖ m). We achieve this by extending the COSE external_aad (which RFC 9052 §4.4 folds into every layer’s Sig_structure) with the composite alg-id whenever signing in Hybrid mode.

Consequence: the inner EdDSA COSE_Sign1 to-be-signed bytes produced in Hybrid mode are now byte-distinct from those produced in Classical mode, so a stripped inner EdDSA signature lifted out of a Hybrid composite is not a valid standalone Classical signature — it fails verification at the signature level (not merely the require_pq policy check). In Classical mode the external_aad is left exactly as before (no hybrid-alg-id), so classical-only signing/verification is byte-for-byte unchanged.

§Backwards-compatibility / transition window

This changes what is signed under Hybrid mode: a Hybrid signer at this revision binds the hybrid-alg-id, so its inner EdDSA layer will NOT verify against a pre-#278 Classical verifier that reconstructs the bare base AAD, and vice-versa. Per WNS the classical sig/cnf fields on the envelope are retained for the raw-EdDSA advertisement / JWT-cnf paths and are unaffected. During a mixed-version deployment, peers MUST agree on the same policy (Classical↔Classical or Hybrid↔Hybrid); a Hybrid producer talking to a Classical-only consumer was already rejected by the require_pq policy, so no new interop surface is broken — only the Hybrid inner AAD changed.

§Wire shape (SignedEnvelope.cose)

A definite-length CBOR array of two entries:

[ inner_cose_sign1_bytes : bstr,
  outer_cose_sign1_bytes : bstr / null ]   ; null in Classical mode

The signed payloads are detached (never embedded). Each COSE_Sign1 carries its signer’s kid + alg in its protected header.

Structs§

CompositeVerified
Outcome of composite verification.

Constants§

ALG_ML_DSA_65
IANA COSE algorithm id for ML-DSA-65 (FIPS 204, draft-ietf-cose-dilithium).
HYBRID_COMPOSITE_ALG_ID
Stable composite/hybrid algorithm identifier for the EdDSA + ML-DSA-65 component pair signed by this nested construction.
PQ_BINDING_HEADER_LABEL
Protected-header label under which the INNER EdDSA layer names the ML-DSA-65 verifying key that must sit above it.

Functions§

assemble_composite_nested
Assemble the nested WNS composite from out-of-band signatures.
assemble_composite_nested_pq_bound
assemble_composite_nested for a composite whose inner layer commits to the ML-DSA-65 key above it.
build_hybrid_external_aad
Extend a base external_aad with the HYBRID_COMPOSITE_ALG_ID binding.
inner_tbs
Compute the inner EdDSA layer’s detached to-be-signed bytes.
inner_tbs_pq_bound
inner_tbs for a composite whose inner layer commits to the ML-DSA-65 key above it (see PQ_BINDING_HEADER_LABEL).
outer_tbs
Compute the outer ML-DSA-65 layer’s detached to-be-signed bytes over payload ‖ inner_eddsa_signature (the inner→outer binding).
self_asserted_outer_pq_key
The ML-DSA-65 verifying key the composite’s outer layer claims for itself, read out of that layer’s kid protected header.
sign_composite
Sign payload (detached) producing the CBOR-encoded nested COSE composite.
sign_composite_pq_bound
sign_composite, with the inner EdDSA layer additionally committing to the ML-DSA-65 key above it (see PQ_BINDING_HEADER_LABEL).
split_composite
Split a nested composite blob into its raw component signatures (ed25519_signature, Option<mldsa65_signature>).
verify_composite
Verify a CBOR-encoded nested COSE composite against a detached payload.