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