arcana/ecc/mod.rs
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Cédric Mesnil <cslashm@pm.me>
3
4// Elliptic curve cryptography: ECDSA, ECDH, EdDSA, X25519, X448.
5//
6// Short-Weierstrass curves (Curve trait):
7// NIST P-256, P-384, P-521
8// SECG secp256k1
9// BSI brainpoolP256r1, brainpoolP384r1, brainpoolP512r1
10//
11// Edwards / Montgomery curves (standalone modules):
12// EdDSA Ed25519, Ed448
13// X25519 Diffie-Hellman over Curve25519
14// X448 Diffie-Hellman over Curve448
15
16pub mod curve;
17pub mod curves;
18pub mod ecdh;
19pub mod ecdsa;
20pub mod ed448;
21pub mod eddsa;
22pub mod field;
23pub mod x25519;
24pub mod x448;
25
26/// SEC1 point-encoding entry points of the arithmetic layer, re-exported at
27/// `ecc::` level. Both validate the point on-curve (defence in depth), so
28/// they are safe public entries — unlike the raw point ops in [`curve`],
29/// which do not validate (see that module's `# Arithmetic layer` contract).
30///
31/// # Examples
32///
33/// Round-trip the P-256 generator through its SEC1 compressed form
34/// (SEC 2 §2.4.2; `G_y` is odd, hence the `0x03` tag):
35///
36/// ```
37/// use arcana::ecc::{compress_pubkey, decompress_pubkey};
38/// use arcana::ecc::curve::p256_params;
39///
40/// let compressed: [u8; 33] = [
41/// 0x03, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc,
42/// 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d,
43/// 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
44/// ];
45/// let params = p256_params();
46/// // Decompress recovers `04 || X || Y` (validating the point on-curve)…
47/// let pk = decompress_pubkey(¶ms, &compressed).expect("valid point");
48/// assert_eq!(pk.bytes.len(), 65);
49/// assert_eq!(pk.bytes[0], 0x04);
50/// // …and compressing it again returns the original encoding.
51/// let again = compress_pubkey(¶ms, &pk).expect("valid point");
52/// assert_eq!(again.as_slice(), compressed.as_slice());
53/// ```
54pub use ecdsa::{compress_pubkey, decompress_pubkey};