reallyme_crypto/lib.rs
1// SPDX-FileCopyrightText: 2026 ReallyMe LLC
2//
3// SPDX-License-Identifier: MIT OR Apache-2.0
4
5//! # reallyme-crypto
6//!
7//! Umbrella crate that re-exports the ReallyMe cryptographic primitives,
8//! dispatch and signer abstractions behind one dependency and a consistent
9//! feature set.
10//!
11//! ## Platform lanes
12//!
13//! Rust exposes two backend lanes selected by Cargo feature and target:
14//! `native` (portable Rust) and `wasm` (package-owned Rust compiled for
15//! WebAssembly with target-appropriate entropy support).
16//! Swift and Kotlin provider selection lives in their package facades; those
17//! facades call this Rust workspace through FFI/JNI only for algorithms whose
18//! provider policy explicitly selects Rust. A lane never silently falls back to
19//! another backend.
20//!
21//! The canonical contract is not the Rust API by itself. It is the shared set
22//! of protobuf/enums, package algorithm identifiers, typed error taxonomy,
23//! provider manifest, and conformance vectors. Rust is the reference
24//! implementation and the shared implementation for selected primitives; native
25//! platform routes are interchangeable only when vectors and typed-error tests
26//! prove identical input, output, failure, and edge-case behavior.
27//!
28//! ## Security posture
29//!
30//! `#![forbid(unsafe_code)]` here; secret material is returned in zeroizing
31//! wrappers; signature verification fails closed; and cross-implementation
32//! conformance vectors pin the Rust output against an independent oracle.
33//! See `SECURITY.md` and `SECURITY_MEMORY_MODEL.md` at the repository root.
34//!
35//! Compile-checked usage examples live in the crate README so tests remain
36//! separate from production implementation files.
37
38#![doc = include_str!("../README.md")]
39#![forbid(unsafe_code)]
40
41#[cfg(all(feature = "wasm", not(target_arch = "wasm32"), not(feature = "native")))]
42compile_error!(
43 "reallyme-crypto's `wasm` backend lane must be checked with \
44 `--target wasm32-unknown-unknown`. Host builds should use the `native` \
45 backend lane, or include `native` when running all-feature host checks."
46);
47
48pub use crypto_core as core;
49pub use crypto_core::{
50 AeadAlgorithm, Algorithm, CryptoError, HashAlgorithm, KeyWrapAlgorithm, MacAlgorithm,
51};
52
53mod aead_error;
54#[cfg(any(
55 feature = "ml-kem-512",
56 feature = "ml-kem-768",
57 feature = "ml-kem-1024",
58 feature = "x-wing"
59))]
60mod kem_error;
61#[cfg(any(
62 feature = "x25519",
63 feature = "p256",
64 feature = "p384",
65 feature = "p521"
66))]
67mod key_agreement_error;
68mod signature_error;
69
70/// Operation-layer domain conventions shared by Rust and adapter boundaries.
71pub mod operations;
72
73/// Typed ownership, retention, export, and destruction contracts for secrets.
74pub mod secret_material;
75
76/// JSON Web Key envelope types and public-key conversion helpers.
77#[cfg(feature = "jwk")]
78pub use envelopes_jwk as jwk;
79
80/// Bidirectional conversion between JWK and Multikey public-key envelopes.
81#[cfg(feature = "jwk-multikey")]
82pub use envelopes_jwk_multikey as jwk_multikey;
83
84/// Algorithm-selected dispatch: keygen, sign/verify, key agreement, KEM, AEAD,
85/// hashing, and multikey binding routed by an [`core::Algorithm`] selector.
86#[cfg(feature = "dispatch")]
87pub mod dispatch;
88
89/// Primary generated protobuf operation-response boundary.
90#[cfg(feature = "operation-response")]
91pub mod operation_contract;
92
93/// Signer/verifier traits and dispatch-backed implementations for producing and
94/// checking detached signatures.
95#[cfg(feature = "signer")]
96pub mod signer;
97
98/// AES-GCM authenticated encryption primitives and their typed key/nonce
99/// wrappers and length constants.
100#[cfg(feature = "aes")]
101pub mod aes;
102
103/// AES-256-GCM authenticated encryption with typed key and nonce boundaries.
104#[cfg(feature = "aes")]
105pub mod aes256_gcm;
106
107/// AES-128, AES-192, and AES-256 Key Wrap (RFC 3394) for compact key material.
108#[cfg(feature = "aes-kw")]
109pub mod aes_kw;
110
111/// AES-256-GCM-SIV nonce-misuse-resistant authenticated encryption primitive and
112/// its typed key/nonce wrappers and length constants.
113#[cfg(feature = "aes-gcm-siv")]
114pub mod aes_gcm_siv;
115
116/// ChaCha20-Poly1305 and XChaCha20-Poly1305 authenticated encryption
117/// primitives with typed key and nonce wrappers.
118#[cfg(feature = "chacha20-poly1305")]
119pub mod chacha20_poly1305;
120
121/// Argon2id password-based key derivation, including platform-tuned cost
122/// profiles and typed salt/secret/derived-key wrappers.
123#[cfg(feature = "argon2id")]
124pub mod argon2id;
125
126/// OS-backed cryptographically secure randomness and typed generators for AEAD
127/// nonces and Argon2 salts.
128#[cfg(feature = "csprng")]
129pub mod csprng;
130
131/// Ed25519 signatures: keypair generation, sign/verify, and public-key encoding.
132#[cfg(feature = "ed25519")]
133pub mod ed25519;
134
135/// HMAC authentication tags over SHA-256, SHA-384, and SHA-512.
136#[cfg(feature = "hmac")]
137pub mod hmac;
138
139/// JWA ECDH-ES Concat KDF over SHA-256 for deriving content-encryption keys
140/// from an ECDH shared secret.
141#[cfg(feature = "concat-kdf")]
142pub mod concat_kdf;
143
144/// NIST P-256 (secp256r1) ECDSA over pre-hashed messages, with public-key
145/// compression and Secure Enclave handle encoding.
146#[cfg(feature = "p256")]
147pub mod p256;
148
149/// NIST P-384 (secp384r1) ECDSA and ECDH, with public-key
150/// compression/decompression helpers.
151#[cfg(feature = "p384")]
152pub mod p384;
153
154/// NIST P-521 (secp521r1) ECDSA and ECDH, with public-key
155/// compression/decompression helpers.
156#[cfg(feature = "p521")]
157pub mod p521;
158
159/// PBKDF2 password-based key derivation conforming to RFC 8018.
160#[cfg(feature = "pbkdf2")]
161pub mod pbkdf2;
162
163/// RSA signature verification for PKCS#1 v1.5 and PSS.
164#[cfg(feature = "rsa")]
165pub mod rsa;
166
167/// secp256k1 ECDSA signs SHA-256(message) once, returns compact low-S `r || s`,
168/// and uses compressed SEC1 public keys as the canonical API representation.
169#[cfg(feature = "secp256k1")]
170pub mod secp256k1;
171
172/// X25519 Diffie–Hellman key agreement and public-key encoding.
173#[cfg(feature = "x25519")]
174pub mod x25519;
175
176/// X-Wing hybrid KEM over X25519 plus ML-KEM-768.
177#[cfg(feature = "x-wing")]
178pub mod x_wing;
179
180/// RFC 9180 HPKE Base-mode encryption over supported DHKEM/HKDF/AEAD suites.
181#[cfg(feature = "hpke-api")]
182pub mod hpke;
183
184/// HKDF (RFC 5869) extract-and-expand key derivation over the SHA-2/SHA-3 suites,
185/// with domain-separated key derivation helpers.
186#[cfg(feature = "hkdf")]
187pub mod hkdf;
188
189/// KMAC256 key derivation for protocols using NIST SP 800-108 and SP 800-185.
190#[cfg(feature = "kmac")]
191pub mod kmac;
192
193/// ML-DSA-44 (FIPS 204) post-quantum signatures: keygen, sign/verify, and
194/// public-key encoding.
195#[cfg(feature = "ml-dsa-44")]
196pub mod ml_dsa_44;
197
198/// ML-DSA-65 (FIPS 204) post-quantum signatures: keygen, sign/verify, and
199/// public-key encoding.
200#[cfg(feature = "ml-dsa-65")]
201pub mod ml_dsa_65;
202
203/// ML-DSA-87 (FIPS 204) post-quantum signatures: keygen, sign/verify, and
204/// public-key encoding.
205#[cfg(feature = "ml-dsa-87")]
206pub mod ml_dsa_87;
207
208/// SLH-DSA-SHA2-128s (FIPS 205) hash-based post-quantum signatures.
209#[cfg(feature = "slh-dsa")]
210pub mod slh_dsa;
211
212/// ML-KEM-512 (FIPS 203) post-quantum key encapsulation: keygen, encapsulate,
213/// and decapsulate.
214#[cfg(feature = "ml-kem-512")]
215pub mod ml_kem_512;
216
217/// ML-KEM-768 (FIPS 203) post-quantum key encapsulation: keygen, encapsulate,
218/// and decapsulate.
219#[cfg(feature = "ml-kem-768")]
220pub mod ml_kem_768;
221
222/// ML-KEM-1024 (FIPS 203) post-quantum key encapsulation: keygen, encapsulate,
223/// and decapsulate.
224#[cfg(feature = "ml-kem-1024")]
225pub mod ml_kem_1024;
226
227/// SHA-2-256 hashing and its fixed-length digest wrapper.
228#[cfg(feature = "sha2")]
229pub mod sha2;
230
231/// SHA-3-256 hashing and its fixed-length digest wrapper.
232#[cfg(feature = "sha3")]
233pub mod sha3;
234
235/// BN254 Poseidon2 byte hashing compatible with ReallyMe ZK circuits.
236#[cfg(feature = "poseidon2")]
237pub mod poseidon2;