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
86pub mod error;
87/// Error types and `Result` alias.
88pub mod types;
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 ──
118pub mod ec_schnorr;
119pub mod pqc;
120/// Signing primitives: classical, post-quantum, and hybrid.
121///
122/// **Recommended**: use [`signing::hybrid::HybridSigningKeyBundle`] for
123/// new applications. It pairs Ed25519 with a post-quantum primitive so
124/// the signature remains unforgeable even if one primitive is broken.
125pub mod signing;
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; removal deferred to 0.6**.
130// See `signing_legacy` module docs for migration instructions.
131#[deprecated(
132    since = "0.5.1",
133    note = "Removal deferred to 0.6. Use signing::hybrid::HybridSigningKeyBundle instead. See MIGRATION.md."
134)]
135pub mod signing_legacy;
136
137// ── Randomness & DRBG ──
138pub mod drbg;
139
140// ── Recovery phrases ──
141///
142/// BIP-39-shaped Unicode recovery phrases. NOT BIP-39-compatible —
143/// uses a curated Unicode codepoint wordlist and SHA-3-256 (not
144/// SHA-256). For interop with other wallets, use the `bip39` crate.
145pub mod recovery;
146
147// ── Utility modules (hidden from docs) ──
148/// Entropy analysis — internal utility.
149#[doc(hidden)]
150pub mod entropy;
151
152/// Seed handling with TTL and memory security.
153pub mod seed;
154
155/// Merkle Mountain Range — internal utility.
156#[doc(hidden)]
157pub mod mmr;
158
159/// Stealth address primitives (KDF + PoW).
160pub mod stealth;
161
162/// Error correction codes — internal utility.
163#[doc(hidden)]
164pub mod error_correction;
165
166/// Low-level cryptographic primitives (hashes, ciphers, etc.).
167///
168/// **Internal use only.** Application code should use the higher-level
169/// modules ([`chacha20_blake3`], [`kdf`], etc.) instead.
170#[doc(hidden)]
171pub mod primitives;
172
173/// SipHash keyed hash — internal utility.
174#[doc(hidden)]
175pub mod siphash;
176
177/// Compression utility — internal.
178#[doc(hidden)]
179pub mod compression;
180
181/// Blob storage — internal utility.
182#[doc(hidden)]
183pub mod blob;
184
185// ──────────────────────────────────────────────────────────────────────
186// Internal modules (not part of public API; use at your own risk)
187// ──────────────────────────────────────────────────────────────────────
188#[doc(hidden)]
189pub mod internal;
190
191// ──────────────────────────────────────────────────────────────────────
192// Re-exports at crate root for convenience
193// ──────────────────────────────────────────────────────────────────────
194
195// Errors
196pub use error::{CryptoError as Error, Result as StdResult};
197
198// Encryption
199pub use aead::XChaCha20Poly1305;
200
201// KDF
202pub use kdf::hkdf::{derive_subkeys, hkdf_sha3_256};
203pub use kdf::Argon2id;
204
205// MAC
206pub use kdf::mac::hmac_sha3_256;
207
208// DRBG
209pub use drbg::ChaCha20Drbg;
210
211// Seed handling
212pub use seed::{derive_child_seed, derive_signing_keys, derive_verifying_keys, SeedHandle};
213
214// Signatures — re-exports (DEPRECATED, will be removed in 0.5)
215#[allow(deprecated)]
216#[deprecated(
217    since = "0.5.1",
218    note = "Removal deferred to 0.6. Use signing::hybrid::HybridSigningKeyBundle instead. See MIGRATION.md."
219)]
220pub use signing::HybridSignatureOutput;
221#[allow(deprecated)]
222#[deprecated(
223    since = "0.5.1",
224    note = "Removal deferred to 0.6. Use signing::hybrid::HybridSigningKeyBundle instead. See MIGRATION.md."
225)]
226pub use signing::HybridSigningKey;
227#[allow(deprecated)]
228#[deprecated(
229    since = "0.5.1",
230    note = "Removal deferred to 0.6. Use signing::hybrid::HybridSigningKeyBundle instead. See MIGRATION.md."
231)]
232pub use signing::HybridVerifyingKey;
233
234// Hybrid bundle (canonical PQ-hybrid signing)
235pub use signing::hybrid::falcon1024_keygen;
236pub use signing::hybrid::HybridSigningKeyBundle;
237pub use signing::hybrid::{skein1024, skein512};
238
239// PQC direct access — use `pqc::{falcon1024, falcon512, ed448, ...}::module` for raw types.
240// Re-exports at crate root are intentionally omitted to keep the surface clean.
241// Advanced users access via `origin_crypto_sdk::pqc::falcon1024::FalconPrivateKey` etc.
242
243// Ed448 — RFC 8032 signature scheme on the 448-bit Goldilocks curve.
244// Exposed at `origin_crypto_sdk::pqc::ed448`.
245// Ed41417 — Daniel J. Bernstein's signature scheme on curve41417.
246// pub use pqc::curve41417::ed41417 as ed41417_raw;  // intentionally not re-exported
247
248// SLH-DSA direct access (feature-gated)
249#[cfg(feature = "slh-dsa")]
250pub use pqc::slhdsa::{
251    sign as slhdsa_sign, verify as slhdsa_verify, SlhDsaPrivateKey, SlhDsaPublicKey,
252};
253
254// ML-DSA direct access (feature-gated)
255#[cfg(feature = "ml-dsa")]
256pub use pqc::mldsa::{MldsaPrivateKey, MldsaPublicKey};