ecqv 0.1.0

SEC 4 ECQV implicit certificates on P-256: reconstruct a public key from a certificate and the issuer's key, with no signature to carry
Documentation
//! Known-answer test vectors for the ECQV protocol core.
//!
//! Source: `conz27/crypto-test-vectors` -> `implicit.txt`, from the CAMP LLC
//! SCMS / V2X project (archived). Two vectors, both P-256, same scenario with
//! two different CA nonces `k`.
//!
//! The vectors cover all three roles separately and include the CA nonce `k`
//! as an INPUT, so each role can be checked without depending on another
//! role's output:
//!
//!   - CA side:      (tbsCert, RU, dCA, k)  -> (PU, CertU, r)
//!   - requester:    (kU, CertU, r)         -> dU
//!   - any party:    (CertU, QCA)           -> QU
//!
//! Encoding note: the vectors use the toy encoding `CertU = tbsCert || PU`
//! (compressed), explicitly labeled "for illustration purposes and testing
//! only" in the source. They therefore validate the protocol core (point
//! arithmetic, `e` derivation, scalar algebra) and NOT a production certificate
//! encoding; encoding ambiguity is covered by the adversarial tests in
//! `src/encoding.rs` instead.
//!
//! Every value here was independently re-derived from the raw inputs with
//! separate P-256 arithmetic (pure-Python bigint point ops) before being
//! committed, and every value matched the published constants. The `e` field is
//! the leftmost 255 bits of SHA-256(CertU) per SEC 4 v1.0 section 2.3.
//!
//! This module is gated behind the `test-vectors` feature so the secret inputs
//! (kU, k, dCA) can never be compiled into a production dependency graph.

/// One known-answer vector.
#[derive(Clone, Copy, Debug)]
pub struct CampVector {
    /// To-be-signed certificate data (here: the bytes of "This is a test!").
    pub tbs_cert: &'static [u8],
    /// Requester's certificate request private key.
    pub k_u: &'static str,
    /// Requester's certificate request public key (RU), x and y.
    pub r_u_x: &'static str,
    pub r_u_y: &'static str,
    /// CA private key.
    pub d_ca: &'static str,
    /// CA public key (QCA), x and y.
    pub q_ca_x: &'static str,
    pub q_ca_y: &'static str,
    /// CA ephemeral nonce (secret, input for testing only).
    pub k: &'static str,
    /// User's reconstruction point (PU), x and y.
    pub p_u_x: &'static str,
    pub p_u_y: &'static str,
    /// The exact certificate bytes hashed by Hn: tbsCert || compressed PU.
    pub cert_u_hex: &'static str,
    /// CA's private key reconstruction value (r).
    pub r_hex: &'static str,
    /// Requester's reconstructed private key (dU).
    pub d_u_hex: &'static str,
    /// Requester's reconstructed public key (QU), x and y.
    pub q_u_x: &'static str,
    pub q_u_y: &'static str,
    /// Expected e = leftmost 255 bits of SHA-256(cert_u).
    pub e_hex: &'static str,
}

pub const CAMP_VECTOR_1: CampVector = CampVector {
    tbs_cert: b"This is a test!\x00",
    k_u: "1384C31D6982D52BCA3BED8A7E60F52FECDAB44E5C0EA166815A8159E09FFB42",
    r_u_x: "F45A99137B1BB2C150D6D8CF7292CA07DA68C003DAA766A9AF7F67F5EE916828",
    r_u_y: "F6A25216F44CB64A96C229AE00B479857B3B81C1319FB2ADF0E8DB2681769729",
    d_ca: "97D1368E8C07A54F66C9DCE284BA76CAF4178206614F809A4EB43CB3106AA60E",
    q_ca_x: "3BB8FFD19B25EE1BB939CD4935FBFA8FBAADBA64843338A95595A70ED7479B70",
    q_ca_y: "EB60DDC790E3CB05E85225F636D8A7C20DF3A8135C4B2AE5396367B4E86077F8",
    k: "E2F9CBCEC3F28F7DFBEF044732C41119816C62909FB720B091FB8F380F1B70DC",
    p_u_x: "4A1890E30A584208DAD3838D0C5CECB1ED6B01D48893C684C59908F5B38E3D82",
    p_u_y: "BAE8FB2EF2DC080F248F44FCEC458B1B35ECDC80F00C959292CBE21BE2FF2EA2",
    cert_u_hex: "54686973206973206120746573742100024A1890E30A584208DAD3838D0C5CECB1ED6B01D48893C684C59908F5B38E3D82",
    r_hex: "1FA86893A1AABE8A79F63360F4B6D5617380B4D84B8C260DD8D3D64163C874FD",
    d_u_hex: "C8599ECA52B58D691B2BB609CDB53DDD9F49C0D635AB652EC79C546914590274",
    q_u_x: "6E89D7C0F910AAA4AD3137EBE01EF781C0BAB6748318D66FE714471F7F860EB2",
    q_u_y: "1EFE06E2ACC3A2343D2E4445F2083BFA4379672DFBFE0B2575002082407FFDDC",
    e_hex: "4B3766671CF02DAA0DF2B882AEE31FBEF9BBF3CC238B3F15C7497C193FD61C26",
};

pub const CAMP_VECTOR_2: CampVector = CampVector {
    tbs_cert: b"This is a test!\x00",
    k_u: "1384C31D6982D52BCA3BED8A7E60F52FECDAB44E5C0EA166815A8159E09FFB42",
    r_u_x: "F45A99137B1BB2C150D6D8CF7292CA07DA68C003DAA766A9AF7F67F5EE916828",
    r_u_y: "F6A25216F44CB64A96C229AE00B479857B3B81C1319FB2ADF0E8DB2681769729",
    d_ca: "97D1368E8C07A54F66C9DCE284BA76CAF4178206614F809A4EB43CB3106AA60E",
    q_ca_x: "3BB8FFD19B25EE1BB939CD4935FBFA8FBAADBA64843338A95595A70ED7479B70",
    q_ca_y: "EB60DDC790E3CB05E85225F636D8A7C20DF3A8135C4B2AE5396367B4E86077F8",
    k: "3396DA2ECBFC6E5F231E2C80EB27AB84F09DD5E724F8652ADE86E60BC800EAD7",
    p_u_x: "6694D1F99A18CBE8035E053B2E56C12EECB94E9D5DBA88E07E5B50CBE309103E",
    p_u_y: "74A698788B8F35B3A86E553228D592FCB7C85611637690A85EEACA02EB178887",
    cert_u_hex: "54686973206973206120746573742100036694D1F99A18CBE8035E053B2E56C12EECB94E9D5DBA88E07E5B50CBE309103E",
    r_hex: "001CF7456A157A90FCEA0634699E7A3644FEBFB86C119E6A9686928B8E3F7EF0",
    d_u_hex: "C9CCC8E83AB985C436A8BC09C0CAA8A5AC627DD7BC9336A5E8AB81B77D3A031D",
    q_u_x: "8ED40E9601BEEB146A4A0AB96D20EE0FE4CA1E389397F2B1CC67AD9F5B0F579E",
    q_u_y: "73E589E8A9A135306F4AA324F17B66906153BD333961F9BE530F20EB8D3339C7",
    e_hex: "27FE62399BE5978ACDAECD70293B6B4C7480103864AAD3F020B4A4E6438600AC",
};

/// Both vectors, for iteration in the harness.
pub const ALL: &[CampVector] = &[CAMP_VECTOR_1, CAMP_VECTOR_2];