dcrypt_algorithms/
lib.rs

1//! Cryptographic primitives library with constant-time implementation
2//!
3//! This crate provides implementations of various cryptographic primitives
4//! with a focus on constant-time operations and resistance to side-channel attacks.
5//! The library is designed to be usable in both `std` and `no_std` environments.
6//!
7//! # Security Features
8//!
9//! This library implements comprehensive security patterns to protect sensitive
10//! cryptographic material, including:
11//!
12//! - Secure memory handling with automatic zeroization
13//! - Constant-time comparison operations
14//! - Memory barrier utilities
15//! - Secure operation patterns
16
17#![cfg_attr(not(feature = "std"), no_std)]
18#![forbid(unsafe_code)]
19#![deny(missing_docs)]
20
21#[cfg(feature = "alloc")]
22extern crate alloc;
23
24// Error module and re-exports
25pub mod error;
26pub use error::{validate, Error, Result, ResultExt, SecureErrorHandling};
27
28// Block cipher implementations
29pub mod block;
30pub use block::{Aes128, Aes192, Aes256, Cbc, Ctr};
31
32// Hash function implementations
33pub mod hash;
34pub use hash::{
35    Blake2b, Blake2s, Sha1, Sha224, Sha256, Sha384, Sha3_224, Sha3_256, Sha3_384, Sha3_512, Sha512,
36    Shake128, Shake256,
37};
38
39// AEAD cipher implementations
40#[cfg(feature = "alloc")]
41pub mod aead;
42#[cfg(feature = "alloc")]
43pub use aead::{AeadCipher, ChaCha20Poly1305, ChaCha20Poly1305Cipher, Gcm, XChaCha20Poly1305};
44
45// MAC implementations
46pub mod mac;
47pub use mac::{Hmac, Poly1305};
48
49// Stream cipher implementations
50pub mod stream;
51pub use stream::chacha::chacha20::ChaCha20;
52
53// KDF implementations
54#[cfg(feature = "alloc")]
55pub mod kdf;
56#[cfg(feature = "alloc")]
57pub use kdf::{Argon2, Hkdf, KeyDerivationFunction, PasswordHashFunction, Pbkdf2};
58
59// Elliptic Curve primitives
60pub mod ec;
61pub use ec::{
62    // Re-export curve-specific modules
63    p256,
64    p384,
65    p521,
66    // Re-export common EC types
67    P256Point,
68    P256Scalar,
69    P384Point,
70    P384Scalar,
71    P521Point,
72    P521Scalar,
73};
74
75// Type system
76pub mod types;
77pub use types::{
78    ByteSerializable, ConstantTimeEq, Digest, FixedSize, Nonce, RandomGeneration, Salt,
79    SecretBytes, SecureZeroingType, Tag,
80};
81
82// Re-export security types from dcrypt-core
83pub use dcrypt_common::security::{
84    barrier, EphemeralSecret, SecretBuffer, SecretVec, SecureCompare, SecureOperation,
85    SecureOperationBuilder, SecureOperationExt, ZeroizeGuard,
86};
87
88// Algorithm types and compatibility traits
89pub use types::{
90    // Algorithm marker types
91    algorithms::{
92        Aes128 as Aes128Algorithm, Aes256 as Aes256Algorithm, ChaCha20 as ChaCha20Algorithm,
93        ChaCha20Poly1305 as ChaCha20Poly1305Algorithm, Ed25519 as Ed25519Algorithm,
94        P521 as P521Algorithm, X25519 as X25519Algorithm,
95    },
96
97    digest::{Blake2bCompatible, Sha256Compatible, Sha512Compatible},
98    // Key types
99    key::{AsymmetricPublicKey, AsymmetricSecretKey, SymmetricKey},
100
101    // Compatibility traits for specific algorithms
102    nonce::{AesCtrCompatible, AesGcmCompatible, ChaCha20Compatible, XChaCha20Compatible},
103    salt::{Argon2Compatible, HkdfCompatible, Pbkdf2Compatible},
104    tag::{ChaCha20Poly1305Compatible, GcmCompatible, HmacCompatible, Poly1305Compatible},
105};
106
107// XOF implementations (if enabled)
108#[cfg(feature = "xof")]
109pub mod xof;
110#[cfg(feature = "xof")]
111pub use xof::{Blake3Xof, ExtendableOutputFunction, ShakeXof128, ShakeXof256};
112
113// **NEW** PQC Math Primitive Modules
114#[cfg(feature = "alloc")] // Polynomial arithmetic often benefits from dynamic allocation
115pub mod poly;
116
117// Re-export polynomial types for easier access
118#[cfg(feature = "alloc")]
119pub use poly::{
120    ntt::{montgomery_reduce, CooleyTukeyNtt, InverseNttOperator, NttOperator},
121    params::{DilithiumParams, Kyber256Params, Modulus, NttModulus},
122    polynomial::Polynomial,
123    prelude,
124    sampling::{CbdSampler, DefaultSamplers, GaussianSampler, UniformSampler},
125    serialize::{CoefficientPacker, CoefficientUnpacker, DefaultCoefficientSerde},
126};
127
128#[cfg(feature = "alloc")]
129pub mod lattice; // Re-exports poly
130
131// Stubs for future PQC math engines
132#[cfg(feature = "alloc")]
133pub mod code;
134#[cfg(feature = "alloc")]
135pub mod mq;