Skip to main content

proof_crypto/
alg.rs

1// Copyright 2026 Proof Engine Contributors
2// SPDX-License-Identifier: MIT OR Apache-2.0
3// PE-LONG-002: signature algorithm migration / hybrid bridging (docs/LONGEVITY.md
4// §4): new algs enter the same closed registry, default off, additive keyref
5// prefixes, dual-sign windows -- never a silent core rewrite.
6//! COSE algorithm numbers (verified 2026-09-06 vs IANA + RFC 9864).
7//! Fully-specified only. Deprecated polymorphic ids are rejected, never negotiated.
8
9/// EdDSA with Ed25519 (RFC 8032 §5.1). REQUIRED. IANA Recommended: Yes.
10pub const COSE_ED25519: i64 = -19;
11/// ECDSA P-256 + SHA-256 (fully-specified). OPTIONAL, default off. Recommended: Yes.
12pub const COSE_ESP256: i64 = -9;
13
14/// Deprecated polymorphic ids (RFC 9864 §4.2.2). MUST fail closed.
15pub const DEPRECATED: &[i64] = &[-8, -7, -35, -36];
16
17/// Verifier algorithm policy.
18#[derive(Debug, Clone, Copy)]
19pub struct AllowedAlgs {
20    /// Always true in V0.1 (Ed25519 required).
21    pub ed25519: bool,
22    /// Default false. Enable explicitly per deployment.
23    pub esp256: bool,
24}
25
26impl Default for AllowedAlgs {
27    fn default() -> Self {
28        Self {
29            ed25519: true,
30            esp256: false,
31        }
32    }
33}
34
35impl AllowedAlgs {
36    /// Ed25519-only (V0.1 default).
37    pub fn strict() -> Self {
38        Self::default()
39    }
40
41    pub fn with_esp256(mut self) -> Self {
42        self.esp256 = true;
43        self
44    }
45
46    pub fn is_allowed(&self, alg: i64) -> bool {
47        match alg {
48            x if x == COSE_ED25519 => self.ed25519,
49            x if x == COSE_ESP256 => self.esp256,
50            _ => false,
51        }
52    }
53
54    pub fn is_deprecated(alg: i64) -> bool {
55        DEPRECATED.contains(&alg)
56    }
57}