1mod algorithm;
18mod erased_stack;
19mod error;
20mod hkdf;
21#[cfg(feature = "openssl")]
22mod openssl_ctr;
23mod provider;
24pub mod rfc6979;
25mod rsa_pkcs1;
26mod secret;
27mod traits;
28
29#[cfg(any(feature = "crypto-ring", feature = "crypto-aws-lc-rs"))]
30mod common;
31pub mod providers;
32
33#[cfg(feature = "test-support")]
34pub mod conformance;
35
36#[cfg(all(
39 any(fuzzing, test),
40 any(feature = "crypto-ring", feature = "crypto-aws-lc-rs")
41))]
42pub mod fuzzing;
43
44pub use algorithm::*;
45pub use erased_stack::on_erased_stack;
46pub use error::CryptoError;
47pub use hkdf::{hkdf_expand, hkdf_expand_label, hkdf_extract};
48#[cfg(feature = "openssl")]
49pub use openssl_ctr::openssl_aes_ctr;
50pub use provider::default_provider;
51pub use rsa_pkcs1::{rsa_pkcs1_hash, verify_rsa_pkcs1_without_digest_parameters};
52pub use secret::{SecretVec, record_stack_erasure, scrub_stack, set_record_stack_erasure};
53pub use traits::*;
54
55#[must_use]
57pub fn constant_time_eq(left: &[u8], right: &[u8]) -> bool {
58 use subtle::ConstantTimeEq;
59
60 left.len() == right.len() && bool::from(left.ct_eq(right))
61}
62
63const _: () = {
64 #[allow(dead_code)]
65 #[allow(clippy::too_many_arguments)]
66 fn assert_dyn_compatible(
67 _provider: &dyn RTCCryptoProvider,
68 _crypto: &dyn RTCCrypto,
69 _random: &dyn RTCRandom,
70 _mac: &dyn Mac,
71 _stream: &dyn StreamCipher,
72 _aead: &dyn AeadCipher,
73 _cbc: &dyn CbcCipher,
74 _mask: &dyn HeaderMask,
75 _exchange: &dyn ActiveKeyExchange,
76 _signing_key: &dyn SigningKey,
77 ) {
78 }
79};
80
81#[cfg(test)]
82mod tests {
83 use super::*;
84
85 #[test]
86 fn secret_debug_is_redacted() {
87 let secret = SecretVec::new(vec![1, 2, 3, 4]);
88 let debug = format!("{secret:?}");
89 assert!(debug.contains("REDACTED"));
90 assert!(debug.contains("len: 4"));
91 assert!(!debug.contains("1, 2, 3, 4"));
92 }
93
94 #[test]
95 fn secret_into_bytes_is_explicit() {
96 let secret = SecretVec::new(vec![1, 2, 3]);
97 assert_eq!(secret.into_bytes(), vec![1, 2, 3]);
98 }
99
100 #[test]
101 fn errors_have_provider_neutral_text() {
102 assert_eq!(
103 CryptoError::AuthenticationFailed.to_string(),
104 "authentication failed"
105 );
106 assert_eq!(
107 CryptoError::InvalidSignature.to_string(),
108 "signature verification failed"
109 );
110 }
111
112 #[test]
113 fn constant_time_equality_checks_length_and_content() {
114 assert!(constant_time_eq(b"same", b"same"));
115 assert!(!constant_time_eq(b"same", b"diff"));
116 assert!(!constant_time_eq(b"same", b"same-longer"));
117 }
118}