Skip to main content

reallyme_crypto/
lib.rs

1// SPDX-FileCopyrightText: Copyright © 2026 ReallyMe LLC. All rights reserved
2//
3// SPDX-License-Identifier: Apache-2.0
4
5//! # reallyme-crypto
6//!
7//! Umbrella crate that re-exports the ReallyMe cryptographic primitives,
8//! codecs, dispatch, and signer abstractions behind one dependency and a
9//! consistent 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` (browser/Node host bindings).
15//! Swift and Kotlin provider selection lives in their package facades; those
16//! facades call this Rust workspace through FFI/JNI only for algorithms whose
17//! provider policy explicitly selects Rust. A lane never silently falls back to
18//! another backend.
19//!
20//! ## Security posture
21//!
22//! `#![forbid(unsafe_code)]` here; secret material is returned in zeroizing
23//! wrappers; signature verification fails closed; and cross-implementation
24//! conformance vectors pin the Rust output against an independent oracle.
25//! See `SECURITY.md` and `SECURITY_MEMORY_MODEL.md` at the repository root.
26//!
27//! ## Example: sign then verify
28//!
29//! A detached signature round-trip through [`dispatch`] (requires the
30//! `dispatch` and `ed25519` features, both on by default). Verification
31//! fails closed — tampering with the message yields `Err`, never `Ok(false)`.
32//!
33//! ```
34//! # #[cfg(all(feature = "dispatch", feature = "ed25519"))]
35//! # fn main() -> Result<(), reallyme_crypto::dispatch::AlgorithmError> {
36//! use reallyme_crypto::core::Algorithm;
37//! use reallyme_crypto::dispatch::{generate_keypair, sign, verify};
38//!
39//! let (public, secret) = generate_keypair(Algorithm::Ed25519)?;
40//! let message = b"attested payload";
41//!
42//! let signature = sign(Algorithm::Ed25519, &secret, message)?;
43//! verify(Algorithm::Ed25519, &public, message, &signature)?;
44//!
45//! // A signature never covers a different message: verify returns Err.
46//! assert!(verify(Algorithm::Ed25519, &public, b"tampered", &signature).is_err());
47//! # Ok(())
48//! # }
49//! # #[cfg(not(all(feature = "dispatch", feature = "ed25519")))]
50//! # fn main() {}
51//! ```
52
53#![forbid(unsafe_code)]
54
55#[cfg(all(feature = "wasm", not(target_arch = "wasm32"), not(feature = "native")))]
56compile_error!(
57    "reallyme-crypto's `wasm` backend lane must be checked with \
58     `--target wasm32-unknown-unknown`. Host builds should use the `native` \
59     backend lane, or include `native` when running all-feature host checks."
60);
61
62pub use crypto_core as core;
63
64/// JSON Web Key envelope types and public-key conversion helpers.
65#[cfg(feature = "jwk")]
66pub use envelopes_jwk as jwk;
67
68/// Bidirectional conversion between JWK and Multikey public-key envelopes.
69#[cfg(feature = "jwk-multikey")]
70pub use envelopes_jwk_multikey as jwk_multikey;
71
72/// Algorithm-selected dispatch: keygen, sign/verify, key agreement, KEM, AEAD,
73/// hashing, and multikey binding routed by an [`core::Algorithm`] selector.
74#[cfg(feature = "dispatch")]
75pub mod dispatch {
76    pub use crypto_dispatch::{
77        aead_decrypt, aead_encrypt, derive_shared_secret, generate_keypair,
78        generate_multikey_keypair, hash_digest, kem_decapsulate, kem_encapsulate, mac_authenticate,
79        mac_verify, public_key_to_multikey, sign, validate_verification_method_multikey, verify,
80        AeadParams, AlgorithmError, GeneratedKeypair, MacParams,
81    };
82}
83
84/// Signer/verifier traits and dispatch-backed implementations for producing and
85/// checking detached signatures.
86#[cfg(feature = "signer")]
87pub mod signer {
88    pub use crypto_signer::{
89        DispatchSigner, DispatchVerifier, Signer, SignerError, SignerFailureKind, Verifier,
90        VerifierError, VerifierFailureKind,
91    };
92}
93
94/// AES-GCM authenticated encryption primitives and their typed key/nonce
95/// wrappers and length constants.
96#[cfg(feature = "aes")]
97pub mod aes {
98    pub use crypto_aes256_gcm::{
99        decrypt, decrypt_aes128_gcm, decrypt_aes192_gcm, encrypt, encrypt_aes128_gcm,
100        encrypt_aes192_gcm, Aes128GcmDecryptRequest, Aes128GcmEncryptRequest, Aes128GcmKey,
101        Aes128GcmNonce, Aes192GcmDecryptRequest, Aes192GcmEncryptRequest, Aes192GcmKey,
102        Aes192GcmNonce, Aes256GcmKey, Aes256GcmNonce, CiphertextWithTag, DecryptRequest,
103        EncryptRequest, AES_128_GCM_KEY_LENGTH, AES_128_GCM_NONCE_LENGTH, AES_128_GCM_TAG_LENGTH,
104        AES_192_GCM_KEY_LENGTH, AES_192_GCM_NONCE_LENGTH, AES_192_GCM_TAG_LENGTH,
105        AES_256_GCM_KEY_LENGTH, AES_256_GCM_NONCE_LENGTH, AES_256_GCM_TAG_LENGTH,
106    };
107}
108
109/// AES-256 Key Wrap (RFC 3394) for wrapping compact key material.
110#[cfg(feature = "aes-kw")]
111pub mod aes_kw {
112    pub use crypto_aes_kw::{
113        unwrap_key, wrap_key, Aes256KwKek, AesKwKeyData, AesKwWrappedKey, AES_256_KW_KEK_LENGTH,
114        AES_KW_BLOCK_LENGTH, AES_KW_INTEGRITY_CHECK_LENGTH, AES_KW_MAX_KEY_DATA_LENGTH,
115        AES_KW_MIN_KEY_DATA_LENGTH, AES_KW_MIN_WRAPPED_KEY_LENGTH,
116    };
117}
118
119/// AES-256-GCM-SIV nonce-misuse-resistant authenticated encryption primitive and
120/// its typed key/nonce wrappers and length constants.
121#[cfg(feature = "aes-gcm-siv")]
122pub mod aes_gcm_siv {
123    pub use crypto_aes256_gcm_siv::{
124        decrypt, encrypt, Aes256GcmSivKey, Aes256GcmSivNonce, CiphertextWithTag, DecryptRequest,
125        EncryptRequest, AES_256_GCM_SIV_KEY_LENGTH, AES_256_GCM_SIV_NONCE_LENGTH,
126        AES_256_GCM_SIV_TAG_LENGTH,
127    };
128}
129
130/// ChaCha20-Poly1305 and XChaCha20-Poly1305 authenticated encryption
131/// primitives with typed key and nonce wrappers.
132#[cfg(feature = "chacha20-poly1305")]
133pub mod chacha20_poly1305 {
134    pub use crypto_chacha20_poly1305::{
135        decrypt, decrypt_xchacha20_poly1305, encrypt, encrypt_xchacha20_poly1305,
136        ChaCha20Poly1305Key, ChaCha20Poly1305Nonce, CiphertextWithTag, DecryptRequest,
137        EncryptRequest, XChaCha20Poly1305DecryptRequest, XChaCha20Poly1305EncryptRequest,
138        XChaCha20Poly1305Nonce, CHACHA20_POLY1305_KEY_LENGTH, CHACHA20_POLY1305_NONCE_LENGTH,
139        CHACHA20_POLY1305_TAG_LENGTH, XCHACHA20_POLY1305_NONCE_LENGTH,
140    };
141}
142
143/// Argon2id password-based key derivation, including platform-tuned cost
144/// profiles and typed salt/secret/derived-key wrappers.
145#[cfg(feature = "argon2id")]
146pub mod argon2id {
147    pub use crypto_argon2id::{
148        derive_key, derive_key_for_version, resolve_mobile_profile_for_unlock,
149        resolve_profile_params_for_platform, resolve_profile_params_with_caps, Argon2Caps,
150        Argon2KdfVersion, Argon2ParamsProfile, Argon2PlatformClass, Argon2Profile, Argon2Salt,
151        Argon2Secret, Argon2idDerivedKey, DeriveKeyRequest, ARGON2ID_DERIVED_KEY_LENGTH,
152        ARGON2ID_SALT_MAX_LENGTH, ARGON2ID_SALT_MIN_LENGTH, ARGON2ID_V1_LANES,
153        ARGON2ID_V1_MEMORY_COST_KIB, ARGON2ID_V1_TIME_COST, ARGON2ID_V2_LANES,
154        ARGON2ID_V2_MEMORY_COST_KIB, ARGON2ID_V2_TIME_COST,
155    };
156}
157
158/// Constant-time (non-short-circuiting) byte-slice equality checks.
159#[cfg(feature = "constant-time")]
160pub mod constant_time {
161    pub use crypto_constant_time::{ct_eq, ct_eq_fixed, require_ct_eq};
162}
163
164/// OS-backed cryptographically secure randomness and typed generators for AEAD
165/// nonces and Argon2 salts.
166#[cfg(feature = "csprng")]
167pub mod csprng {
168    pub use crypto_csprng::{
169        generate_aead_nonce_12, generate_argon2_salt_16, generate_argon2_salt_32, generate_bytes,
170        AeadNonce12, Argon2Salt16, Argon2Salt32, OsSecureRandom, RandomBytes, SecureRandom,
171        AEAD_NONCE_12_LENGTH, ARGON2_SALT_16_LENGTH, ARGON2_SALT_32_LENGTH,
172    };
173}
174
175/// Ed25519 signatures: keypair generation, sign/verify, and public-key encoding.
176#[cfg(feature = "ed25519")]
177pub mod ed25519 {
178    pub use crypto_ed25519::{
179        assert_public_key, decode_public_key, encode_public_key, generate_ed25519_keypair,
180        sign_ed25519, verify_ed25519,
181    };
182
183    // Pure wasm primitive crates intentionally expose only their host-provider
184    // contract. Import/deterministic helpers stay native here; TypeScript
185    // consumers get equivalent deriveKeyPair APIs from the package facade.
186    #[cfg(not(all(feature = "wasm", target_arch = "wasm32", not(feature = "native"))))]
187    pub use crypto_ed25519::generate_ed25519_keypair_from_seed;
188}
189
190/// HMAC authentication tags over SHA-256 and SHA-512.
191#[cfg(feature = "hmac")]
192pub mod hmac {
193    pub use crypto_hmac::{
194        authenticate, verify, HmacKey, HmacTag, HMAC_MAX_KEY_LENGTH, HMAC_SHA256_TAG_LENGTH,
195        HMAC_SHA512_TAG_LENGTH,
196    };
197}
198
199/// JWA ECDH-ES Concat KDF over SHA-256 for deriving content-encryption keys
200/// from an ECDH shared secret.
201#[cfg(feature = "concat-kdf")]
202pub mod concat_kdf {
203    pub use crypto_concat_kdf::{
204        derive_jwa_concat_kdf_sha256, JwaAlgorithmId, JwaConcatKdfOutput, JwaConcatKdfRequest,
205        JwaPartyInfo, JwaSharedSecret, JWA_CONCAT_KDF_MAX_INFO_LENGTH,
206        JWA_CONCAT_KDF_MAX_SHARED_SECRET_LENGTH, JWA_CONCAT_KDF_SHA256_DIGEST_LENGTH,
207    };
208}
209
210/// NIST P-256 (secp256r1) ECDSA over pre-hashed messages, with public-key
211/// compression and Secure Enclave handle encoding.
212#[cfg(feature = "p256")]
213pub mod p256 {
214    pub use crypto_p256::{
215        compress_public_key, decode_se_handle, decompress_public_key, derive_p256_shared_secret,
216        encode_se_handle, generate_p256_keypair, generate_p256_keypair_from_secret_key,
217        p256_ecdsa_der_to_jose_signature, p256_ecdsa_der_to_jose_signature_permissive,
218        p256_ecdsa_jose_signature_to_der, sign_p256_der_prehash, verify_p256_der_prehash,
219        P256_ECDSA_JOSE_SIGNATURE_LEN, SE_HANDLE_PREFIX,
220    };
221
222    #[cfg(feature = "native")]
223    pub use crypto_p256::{
224        compressed_public_key_from_private_key, private_key_from_pem, private_key_from_pkcs8_der,
225        private_key_from_pkcs8_pem, private_key_from_sec1_der, private_key_from_sec1_pem,
226        public_key_from_spki_der, public_key_from_spki_pem,
227    };
228}
229
230/// NIST P-384 (secp384r1) ECDSA and ECDH, with public-key
231/// compression/decompression helpers.
232#[cfg(feature = "p384")]
233pub mod p384 {
234    pub use crypto_p384::{
235        compress_p384, compress_public_key, decompress_p384, decompress_public_key,
236        derive_p384_shared_secret, generate_p384_keypair, generate_p384_keypair_from_secret_key,
237        sign_p384_der_prehash, verify_p384_der_prehash, P384_PUBLIC_KEY_COMPRESSED_LEN,
238        P384_PUBLIC_KEY_RAW_LEN, P384_PUBLIC_KEY_UNCOMPRESSED_LEN, P384_SECRET_KEY_LEN,
239        P384_SHARED_SECRET_LEN, P384_SIGNATURE_DER_MAX_LEN,
240    };
241}
242
243/// NIST P-521 (secp521r1) ECDSA and ECDH, with public-key
244/// compression/decompression helpers.
245#[cfg(feature = "p521")]
246pub mod p521 {
247    pub use crypto_p521::{
248        compress_p521, compress_public_key, decompress_p521, decompress_public_key,
249        derive_p521_shared_secret, generate_p521_keypair, generate_p521_keypair_from_secret_key,
250        sign_p521_der_prehash, verify_p521_der_prehash, P521_PUBLIC_KEY_COMPRESSED_LEN,
251        P521_PUBLIC_KEY_RAW_LEN, P521_PUBLIC_KEY_UNCOMPRESSED_LEN, P521_SECRET_KEY_LEN,
252        P521_SHARED_SECRET_LEN, P521_SIGNATURE_DER_MAX_LEN,
253    };
254}
255
256/// PBKDF2 (RFC 8018) for legacy password-based key derivation.
257#[cfg(feature = "pbkdf2")]
258pub mod pbkdf2 {
259    pub use crypto_pbkdf2::{
260        derive_key, Pbkdf2Iterations, Pbkdf2Output, Pbkdf2Password, Pbkdf2Prf, Pbkdf2Request,
261        Pbkdf2Salt, PBKDF2_MAX_OUTPUT_LENGTH, PBKDF2_MAX_PASSWORD_LENGTH, PBKDF2_MAX_SALT_LENGTH,
262        PBKDF2_MIN_ITERATIONS, PBKDF2_MIN_OUTPUT_LENGTH, PBKDF2_MIN_PASSWORD_LENGTH,
263        PBKDF2_MIN_SALT_LENGTH,
264    };
265}
266
267/// RSA signature verification for PKCS#1 v1.5 and PSS.
268#[cfg(feature = "rsa")]
269pub mod rsa {
270    pub use crypto_rsa::{
271        verify_rsa_pkcs1v15, verify_rsa_pss, RsaHash, RsaPssParams, RsaPublicKeyDerEncoding,
272        RSA_MAX_MODULUS_BITS, RSA_MIN_MODULUS_BITS, RSA_PUBLIC_KEY_DER_MAX_LEN,
273        RSA_SIGNATURE_MAX_LEN,
274    };
275}
276
277/// secp256k1 ECDSA signs SHA-256(message) once, returns compact low-S `r || s`,
278/// and uses compressed SEC1 public keys as the canonical API representation.
279#[cfg(feature = "secp256k1")]
280pub mod secp256k1 {
281    pub use crypto_secp256k1::{
282        decode_bip340_schnorr_public_key, decode_public_key, decompress_public_key,
283        derive_bip340_schnorr_public_key, encode_bip340_schnorr_public_key, encode_public_key,
284        generate_secp256k1_keypair, secp256k1_ecdsa_der_to_jose_signature,
285        secp256k1_ecdsa_der_to_jose_signature_permissive, secp256k1_ecdsa_jose_signature_to_der,
286        sign_bip340_schnorr, sign_secp256k1, verify_bip340_schnorr, verify_secp256k1,
287        BIP340_SCHNORR_AUX_RAND_LEN, BIP340_SCHNORR_MESSAGE_LEN, BIP340_SCHNORR_PUBLIC_KEY_LEN,
288        BIP340_SCHNORR_SIGNATURE_LEN, SECP256K1_ECDSA_JOSE_SIGNATURE_LEN, SECP256K1_SECRET_KEY_LEN,
289    };
290
291    // See the Ed25519 gate: pure wasm does not widen the JS host-provider
292    // contract for import helpers.
293    #[cfg(not(all(feature = "wasm", target_arch = "wasm32", not(feature = "native"))))]
294    pub use crypto_secp256k1::generate_secp256k1_keypair_from_secret_key;
295}
296
297/// X25519 Diffie–Hellman key agreement and public-key encoding.
298#[cfg(feature = "x25519")]
299pub mod x25519 {
300    pub use crypto_x25519::{
301        decode_public_key, derive_x25519_shared_secret, encode_public_key, generate_x25519_keypair,
302    };
303
304    // See the Ed25519 gate: pure wasm does not widen the JS host-provider
305    // contract for import helpers.
306    #[cfg(not(all(feature = "wasm", target_arch = "wasm32", not(feature = "native"))))]
307    pub use crypto_x25519::generate_x25519_keypair_from_seed;
308}
309
310/// X-Wing hybrid KEM suites over X25519 plus ML-KEM-768 or ML-KEM-1024.
311#[cfg(feature = "x-wing")]
312pub mod x_wing {
313    pub use crypto_x_wing::{
314        generate_x_wing_1024_keypair, generate_x_wing_1024_keypair_derand,
315        generate_x_wing_768_keypair, generate_x_wing_768_keypair_derand, x_wing_1024_decapsulate,
316        x_wing_1024_encapsulate, x_wing_1024_encapsulate_derand, x_wing_768_decapsulate,
317        x_wing_768_encapsulate, x_wing_768_encapsulate_derand, X_WING_1024_CIPHERTEXT_LEN,
318        X_WING_1024_PUBLIC_KEY_LEN, X_WING_768_CIPHERTEXT_LEN, X_WING_768_PUBLIC_KEY_LEN,
319        X_WING_ENCAPS_SEED_LEN, X_WING_SECRET_KEY_LEN, X_WING_SHARED_SECRET_LEN,
320    };
321}
322
323/// RFC 9180 HPKE Base-mode encryption over supported DHKEM/HKDF/AEAD suites.
324#[cfg(feature = "hpke")]
325pub mod hpke {
326    pub use crypto_hpke::{
327        open_base, seal_base, HpkeError, HpkeOpenOutput, HpkeOpenRequest, HpkePrivateKeyBytes,
328        HpkeSealOutput, HpkeSealRequest, HpkeSuite, HPKE_AEAD_AES_256_GCM,
329        HPKE_AEAD_CHACHA20_POLY1305, HPKE_AEAD_TAG_LEN, HPKE_ENCAPSULATED_KEY_MAX_LEN,
330        HPKE_KDF_HKDF_SHA256, HPKE_KEM_DHKEM_P256_HKDF_SHA256, HPKE_KEM_DHKEM_X25519_HKDF_SHA256,
331        HPKE_P256_PRIVATE_KEY_LEN, HPKE_P256_PUBLIC_KEY_LEN, HPKE_X25519_PRIVATE_KEY_LEN,
332        HPKE_X25519_PUBLIC_KEY_LEN,
333    };
334}
335
336/// HKDF (RFC 5869) extract-and-expand key derivation over the SHA-2/SHA-3 suites,
337/// with domain-separated key derivation helpers.
338#[cfg(feature = "hkdf")]
339pub mod hkdf {
340    pub use crypto_hkdf::{
341        derive, derive_domain_key_32, DeriveRequest, DomainKeyPurpose, DomainTag, HkdfInfo,
342        HkdfInputKeyMaterial, HkdfOutput, HkdfSalt, HkdfSuite,
343    };
344}
345
346/// ML-DSA-44 (FIPS 204) post-quantum signatures: keygen, sign/verify, and
347/// public-key encoding.
348#[cfg(feature = "ml-dsa-44")]
349pub mod ml_dsa_44 {
350    pub use crypto_ml_dsa_44::{
351        decode_public_key, encode_public_key, generate_ml_dsa_44_keypair, sign_ml_dsa_44,
352        verify_ml_dsa_44,
353    };
354
355    // See the Ed25519 gate: pure wasm does not widen the JS host-provider
356    // contract for deterministic helpers.
357    #[cfg(not(all(feature = "wasm", target_arch = "wasm32", not(feature = "native"))))]
358    pub use crypto_ml_dsa_44::generate_ml_dsa_44_keypair_from_seed;
359}
360
361/// ML-DSA-65 (FIPS 204) post-quantum signatures: keygen, sign/verify, and
362/// public-key encoding.
363#[cfg(feature = "ml-dsa-65")]
364pub mod ml_dsa_65 {
365    pub use crypto_ml_dsa_65::{
366        decode_public_key, encode_public_key, generate_ml_dsa_65_keypair, sign_ml_dsa_65,
367        verify_ml_dsa_65,
368    };
369
370    // See the Ed25519 gate: pure wasm does not widen the JS host-provider
371    // contract for deterministic helpers.
372    #[cfg(not(all(feature = "wasm", target_arch = "wasm32", not(feature = "native"))))]
373    pub use crypto_ml_dsa_65::generate_ml_dsa_65_keypair_from_seed;
374}
375
376/// ML-DSA-87 (FIPS 204) post-quantum signatures: keygen, sign/verify, and
377/// public-key encoding.
378#[cfg(feature = "ml-dsa-87")]
379pub mod ml_dsa_87 {
380    pub use crypto_ml_dsa_87::{
381        decode_public_key, encode_public_key, generate_ml_dsa_87_keypair, sign_ml_dsa_87,
382        verify_ml_dsa_87,
383    };
384
385    // See the Ed25519 gate: pure wasm does not widen the JS host-provider
386    // contract for deterministic helpers.
387    #[cfg(not(all(feature = "wasm", target_arch = "wasm32", not(feature = "native"))))]
388    pub use crypto_ml_dsa_87::generate_ml_dsa_87_keypair_from_seed;
389}
390
391/// SLH-DSA-SHA2-128s (FIPS 205) hash-based post-quantum signatures.
392#[cfg(feature = "slh-dsa")]
393pub mod slh_dsa {
394    pub use crypto_slh_dsa::{
395        decode_slh_dsa_sha2_128s_public_key, derive_slh_dsa_sha2_128s_keypair,
396        encode_slh_dsa_sha2_128s_public_key, generate_slh_dsa_sha2_128s_keypair,
397        sign_slh_dsa_sha2_128s, verify_slh_dsa_sha2_128s, SLH_DSA_SHA2_128S_KEYGEN_SEED_LEN,
398        SLH_DSA_SHA2_128S_PUBLIC_KEY_LEN, SLH_DSA_SHA2_128S_SECRET_KEY_LEN,
399        SLH_DSA_SHA2_128S_SIGNATURE_LEN,
400    };
401}
402
403/// ML-KEM-512 (FIPS 203) post-quantum key encapsulation: keygen, encapsulate,
404/// and decapsulate.
405#[cfg(feature = "ml-kem-512")]
406pub mod ml_kem_512 {
407    pub use crypto_ml_kem_512::{
408        generate_ml_kem_512_keypair, ml_kem_512_decapsulate, ml_kem_512_encapsulate,
409    };
410
411    // See the Ed25519 gate: pure wasm does not widen the JS host-provider
412    // contract for deterministic helpers.
413    #[cfg(not(all(feature = "wasm", target_arch = "wasm32", not(feature = "native"))))]
414    pub use crypto_ml_kem_512::{
415        generate_ml_kem_512_keypair_from_seed, ml_kem_512_encapsulate_derand,
416    };
417}
418
419/// ML-KEM-768 (FIPS 203) post-quantum key encapsulation: keygen, encapsulate,
420/// and decapsulate.
421#[cfg(feature = "ml-kem-768")]
422pub mod ml_kem_768 {
423    pub use crypto_ml_kem_768::{
424        generate_ml_kem_768_keypair, ml_kem_768_decapsulate, ml_kem_768_encapsulate,
425    };
426
427    // See the Ed25519 gate: pure wasm does not widen the JS host-provider
428    // contract for deterministic helpers.
429    #[cfg(not(all(feature = "wasm", target_arch = "wasm32", not(feature = "native"))))]
430    pub use crypto_ml_kem_768::{
431        generate_ml_kem_768_keypair_from_seed, ml_kem_768_encapsulate_derand,
432    };
433}
434
435/// ML-KEM-1024 (FIPS 203) post-quantum key encapsulation: keygen, encapsulate,
436/// and decapsulate.
437#[cfg(feature = "ml-kem-1024")]
438pub mod ml_kem_1024 {
439    pub use crypto_ml_kem_1024::{
440        generate_ml_kem_1024_keypair, ml_kem_1024_decapsulate, ml_kem_1024_encapsulate,
441    };
442
443    // See the Ed25519 gate: pure wasm does not widen the JS host-provider
444    // contract for deterministic helpers.
445    #[cfg(not(all(feature = "wasm", target_arch = "wasm32", not(feature = "native"))))]
446    pub use crypto_ml_kem_1024::{
447        generate_ml_kem_1024_keypair_from_seed, ml_kem_1024_encapsulate_derand,
448    };
449}
450
451/// SHA-2-256 hashing and its fixed-length digest wrapper.
452#[cfg(feature = "sha2")]
453pub mod sha2 {
454    pub use crypto_sha2::{
455        digest_sha2_384, digest_sha2_512, Sha2_384Digest, Sha2_512Digest, SHA2_384_DIGEST_LENGTH,
456        SHA2_512_DIGEST_LENGTH,
457    };
458    pub use crypto_sha2_256::{digest, Sha2_256Digest, SHA2_256_DIGEST_LENGTH};
459}
460
461/// SHA-3-256 hashing and its fixed-length digest wrapper.
462#[cfg(feature = "sha3")]
463pub mod sha3 {
464    pub use crypto_sha3::{
465        digest_sha3_224, digest_sha3_384, digest_sha3_512, Sha3_224Digest, Sha3_384Digest,
466        Sha3_512Digest, SHA3_224_DIGEST_LENGTH, SHA3_384_DIGEST_LENGTH, SHA3_512_DIGEST_LENGTH,
467    };
468    pub use crypto_sha3_256::{digest, Sha3_256Digest, SHA3_256_DIGEST_LENGTH};
469}
470
471/// Encoding and serialization codecs: base64, base64url, DAG-CBOR, JCS, hex,
472/// multibase, multicodec, multikey, and PEM.
473#[cfg(feature = "codec")]
474pub mod codec {
475    /// Standard (RFC 4648) base64 encode/decode.
476    #[cfg(feature = "codec-base64")]
477    pub mod base64 {
478        pub use codec_base64::{base64_to_bytes, bytes_to_base64, Base64Error};
479    }
480
481    /// URL-safe (RFC 4648 §5) base64 encode/decode without padding.
482    #[cfg(feature = "codec-base64url")]
483    pub mod base64url {
484        pub use codec_base64url::{
485            base64url_bytes_to_bytes, base64url_to_bytes, bytes_to_base64url, Base64UrlError,
486        };
487
488        #[cfg(feature = "codec-base64url-serde")]
489        pub use codec_base64url::{serde_bytes, serde_option_bytes};
490    }
491
492    /// DAG-CBOR encode/decode and content-identifier (CID) computation and
493    /// verification.
494    #[cfg(feature = "codec-cbor")]
495    pub mod cbor {
496        pub use codec_cbor::{
497            compute_cid_dag_cbor, dag_cbor_multihash, decode_dag_cbor, encode_dag_cbor,
498            is_valid_cid_string, sha2_256_content_hash, try_parse_cid, verify_dag_cbor_cid,
499            CborError, CborValue, ContentHash, DagCborMultihash, DAG_CBOR_CODEC,
500        };
501    }
502
503    /// Canonical lowercase hexadecimal encode/decode helpers.
504    #[cfg(feature = "codec-hex")]
505    pub mod hex {
506        pub use codec_hex::{bytes_to_lower_hex, lower_hex_to_bytes, write_lower_hex, HexError};
507    }
508
509    /// JSON Canonicalization Scheme (RFC 8785) serialization.
510    #[cfg(feature = "codec-jcs")]
511    pub mod jcs {
512        pub use codec_jcs::{canonicalize_json, JcsError};
513    }
514
515    /// Multibase self-describing base encodings (base58btc and base64url).
516    #[cfg(feature = "codec-multibase")]
517    pub mod multibase {
518        pub use codec_multibase::{
519            base58btc_decode, base58btc_encode, bytes_to_multibase58btc,
520            bytes_to_multibase_base64url, multibase_to_bytes, Base58Error, MultibaseError,
521        };
522    }
523
524    /// Multicodec varint prefix lookup and stripping.
525    #[cfg(feature = "codec-multicodec")]
526    pub mod multicodec {
527        pub use codec_multicodec::{
528            lookup_codec_prefix, strip_codec_prefix, CodecLookupResult, CodecSpec, MULTICODEC_TABLE,
529        };
530    }
531
532    /// Multikey encoding/parsing that binds an algorithm to its public-key bytes.
533    #[cfg(feature = "codec-multikey")]
534    pub mod multikey {
535        pub use codec_multikey::{
536            binding_type_matches_codec, encode_multikey, parse_multikey, validate_key_binding,
537            KeyBindingInput, MultikeyError, ParsedMultikey,
538        };
539    }
540
541    /// PEM text armor parsing and encoding.
542    #[cfg(feature = "codec-pem")]
543    pub mod pem {
544        pub use codec_pem::{
545            decode_pem, encode_pem, PemDecodePolicy, PemDocument, PemEncodeOptions, PemError,
546            PemLabel, PemLineEnding,
547        };
548    }
549}