Skip to main content

origin_crypto_sdk/
lib.rs

1// SPDX-License-Identifier: Apache-2.0
2#![cfg_attr(docsrs, warn(missing_docs))]
3
4//! Origin Crypto SDK — Post-quantum and classical cryptographic primitives.
5//!
6//! A standalone Rust SDK for signing, encryption, key derivation, and
7//! key encapsulation, with first-class support for both classical
8//! (Ed25519, X25519) and post-quantum (Falcon-1024, SLH-DSA, ML-DSA,
9//! NTRU Prime, Curve41417) primitives.
10//!
11//! # Quick start
12//!
13//! For most users, importing the [`prelude`] gives you everything:
14//!
15//! ```rust
16//! use origin_crypto_sdk::prelude::*;
17//!
18//! // Hybrid Ed25519 + Falcon-1024 signature (recommended default)
19//! let master_seed = [0x42u8; 32];
20//! let bundle = HybridSigningKeyBundle::from_seed(&master_seed, "my-app")
21//!     .expect("valid seed");
22//! let msg = b"sign this";
23//! let sig = bundle.sign_hybrid(msg);
24//! // sig is an Ed25519 + Falcon-1024 hybrid signature
25//! ```
26//!
27//! For users who only need a single primitive:
28//!
29//! ```rust
30//! use origin_crypto_sdk::signing::classical::Ed25519Signer;
31//! use origin_crypto_sdk::signing::postquantum::Falcon1024Signer;
32//!
33//! // Just Ed25519
34//! let ed = Ed25519Signer::from_seed(&[1u8; 32]);
35//! let sig = ed.sign(b"hello");
36//! assert!(ed.verify(b"hello", &sig));
37//!
38//! // Just Falcon-1024
39//! let falcon = Falcon1024Signer::from_seed(&[1u8; 32]);
40//! let sig = falcon.sign(b"hello").expect("Falcon sign");
41//! assert!(falcon.verify(b"hello", &sig));
42//! ```
43//!
44//! # Module organization
45//!
46//! - [`signing`] — Direct access to signing primitives, organized by family:
47//!   - [`signing::classical`] — Ed25519 (no PQ dependencies)
48//!   - [`signing::postquantum`] — Falcon-512/1024, SLH-DSA, ML-DSA
49//!   - [`signing::hybrid`] — Recommended default. Ed25519 + PQ combined.
50//! - [`aead`] / [`chacha20_blake3`] — Symmetric encryption (committing & non-committing)
51//! - [`kdf`] — Key derivation (Argon2id, HKDF-SHA3-256)
52//! - [`pqc`] — Raw post-quantum primitives (advanced use)
53//! - [`ec_schnorr`] — secp256k1 Schnorr signatures (native, no external deps)
54//! - [`prelude`] — One-line import for common types
55//!
56//! # Security defaults
57//!
58//! - For **signatures**: use the hybrid (Ed25519 + PQ) — see [`signing::hybrid`].
59//!   Both must verify, so a vulnerability in one primitive does not break security.
60//! - For **encryption**: prefer [`chacha20_blake3`] (committing AEAD).
61//!   Avoid XChaCha20-Poly1305 unless you specifically need the smaller tag
62//!   and accept the partitioning-oracle risk.
63//! - For **key derivation**: use Argon2id (memory-hard) for password-based KDF,
64//!   HKDF-SHA3-256 for HKDF-style derivation.
65//!
66//! # Cargo features
67//!
68//! | Feature   | Enables                                | Default |
69//! |-----------|----------------------------------------|---------|
70//! | `parallel`  | Rayon-based parallel processing      | **yes** |
71//! | `slh-dsa`   | SLH-DSA / SPHINCS+ signatures (FIPS 205) | no  |
72//! | `ml-dsa`    | ML-DSA / Dilithium signatures (FIPS 204)  | no  |
73//! | `pqc-simd`  | SIMD acceleration for NTRU Prime    | no      |
74//!
75//! Low-level PQC primitives are always available through their modules
76//! (`pqc::falcon1024`, `pqc::ed448`, etc.) — the features only gate the
77//! optional FIPS schemes that pull in extra dependencies.
78
79#![doc(html_root_url = "https://docs.rs/origin-crypto-sdk/0.4.0")]
80#![allow(clippy::result_large_err)]
81
82// ──────────────────────────────────────────────────────────────────────
83// Public modules (matching the README map exactly)
84// ──────────────────────────────────────────────────────────────────────
85
86/// Error types and `Result` alias.
87pub mod types;
88pub mod error;
89pub use error::{CryptoError, Result};
90
91/// Test utilities for downstream users.
92///
93/// **Feature-gated** — enable with `features = ["test-utils"]`.
94///
95/// Provides deterministic seeds, keys, nonces, and byte generators so
96/// users can write tests against the SDK without hitting real randomness.
97///
98/// # Example
99///
100/// ```ignore
101/// use origin_crypto_sdk::test_utils::deterministic_seed;
102/// let seed = deterministic_seed(42);
103/// ```
104#[cfg(feature = "test-utils")]
105pub mod test_utils;
106
107/// Prelude — re-exports common types for `use origin_crypto_sdk::prelude::*`.
108pub mod prelude;
109
110// ── Symmetric encryption ──
111pub mod aead;
112pub mod chacha20_blake3;
113
114// ── Hashing & KDF ──
115pub mod kdf;
116
117// ── Signatures ──
118/// Signing primitives: classical, post-quantum, and hybrid.
119///
120/// **Recommended**: use [`signing::hybrid::HybridSigningKeyBundle`] for
121/// new applications. It pairs Ed25519 with a post-quantum primitive so
122/// the signature remains unforgeable even if one primitive is broken.
123pub mod signing;
124pub mod pqc;
125pub mod ec_schnorr;
126
127// Legacy flat `signing` API (pre-restructuring). Re-exported as
128// `origin_crypto_sdk::signing_legacy` for callers that imported the
129// old types directly. **Deprecated in 0.4, will be removed in 0.5**.
130// See `signing_legacy` module docs for migration instructions.
131#[deprecated(
132    since = "0.4.0",
133    note = "use signing::hybrid::HybridSigningKeyBundle instead. This module will be removed in 0.5."
134)]
135pub mod signing_legacy;
136
137// ── Randomness & DRBG ──
138pub mod drbg;
139
140// ── Utility modules (hidden from docs) ──
141/// Entropy analysis — internal utility.
142#[doc(hidden)]
143pub mod entropy;
144
145/// Seed handling with TTL and memory security.
146pub mod seed;
147
148/// Merkle Mountain Range — internal utility.
149#[doc(hidden)]
150pub mod mmr;
151
152/// Stealth address primitives (KDF + PoW).
153pub mod stealth;
154
155/// Error correction codes — internal utility.
156#[doc(hidden)]
157pub mod error_correction;
158
159/// Low-level cryptographic primitives (hashes, ciphers, etc.).
160///
161/// **Internal use only.** Application code should use the higher-level
162/// modules ([`chacha20_blake3`], [`kdf`], etc.) instead.
163#[doc(hidden)]
164pub mod primitives;
165
166/// SipHash keyed hash — internal utility.
167#[doc(hidden)]
168pub mod siphash;
169
170/// Compression utility — internal.
171#[doc(hidden)]
172pub mod compression;
173
174/// Blob storage — internal utility.
175#[doc(hidden)]
176pub mod blob;
177
178// ──────────────────────────────────────────────────────────────────────
179// Internal modules (not part of public API; use at your own risk)
180// ──────────────────────────────────────────────────────────────────────
181#[doc(hidden)]
182pub mod internal;
183
184// ──────────────────────────────────────────────────────────────────────
185// Re-exports at crate root for convenience
186// ──────────────────────────────────────────────────────────────────────
187
188// Errors
189pub use error::{CryptoError as Error, Result as StdResult};
190
191// Encryption
192pub use aead::XChaCha20Poly1305;
193
194// KDF
195pub use kdf::Argon2id;
196pub use kdf::hkdf::{derive_subkeys, hkdf_sha3_256};
197
198// MAC
199pub use kdf::mac::hmac_sha3_256;
200
201// DRBG
202pub use drbg::ChaCha20Drbg;
203
204// Seed handling
205pub use seed::{derive_child_seed, derive_signing_keys, derive_verifying_keys, SeedHandle};
206
207// Signatures — re-exports (DEPRECATED, will be removed in 0.5)
208#[allow(deprecated)]
209#[deprecated(
210    since = "0.4.0",
211    note = "use signing::hybrid::HybridSigningKeyBundle instead"
212)]
213pub use signing::HybridSignatureOutput;
214#[allow(deprecated)]
215#[deprecated(
216    since = "0.4.0",
217    note = "use signing::hybrid::HybridSigningKeyBundle instead"
218)]
219pub use signing::HybridSigningKey;
220#[allow(deprecated)]
221#[deprecated(
222    since = "0.4.0",
223    note = "use signing::hybrid::HybridSigningKeyBundle instead"
224)]
225pub use signing::HybridVerifyingKey;
226
227// Hybrid bundle (canonical PQ-hybrid signing)
228pub use signing::hybrid::HybridSigningKeyBundle;
229pub use signing::hybrid::falcon1024_keygen;
230pub use signing::hybrid::{skein1024, skein512};
231
232// PQC direct access — use `pqc::{falcon1024, falcon512, ed448, ...}::module` for raw types.
233// Re-exports at crate root are intentionally omitted to keep the surface clean.
234// Advanced users access via `origin_crypto_sdk::pqc::falcon1024::FalconPrivateKey` etc.
235
236// Ed448 — RFC 8032 signature scheme on the 448-bit Goldilocks curve.
237// Exposed at `origin_crypto_sdk::pqc::ed448`.
238// Ed41417 — Daniel J. Bernstein's signature scheme on curve41417.
239// pub use pqc::curve41417::ed41417 as ed41417_raw;  // intentionally not re-exported
240
241// SLH-DSA direct access (feature-gated)
242#[cfg(feature = "slh-dsa")]
243pub use pqc::slhdsa::{sign as slhdsa_sign, verify as slhdsa_verify, SlhDsaPrivateKey, SlhDsaPublicKey};
244
245// ML-DSA direct access (feature-gated)
246#[cfg(feature = "ml-dsa")]
247pub use pqc::mldsa::{MldsaPrivateKey, MldsaPublicKey};