1#![cfg_attr(docsrs, feature(doc_cfg))]
27#![cfg_attr(not(any(test, feature = "std")), no_std)]
28#![warn(
29 clippy::pedantic,
30 clippy::nursery,
31 clippy::all
32)]
33#![allow(clippy::cast_possible_truncation)]
36#![allow(clippy::module_name_repetitions)]
38#![allow(clippy::cast_possible_wrap)]
40#![allow(clippy::cast_lossless)]
41#![allow(clippy::must_use_candidate)]
43#![allow(clippy::needless_pass_by_value)]
46#![allow(clippy::manual_assert)]
49#![allow(clippy::inline_always)]
51#![allow(clippy::cast_sign_loss)]
53#![allow(clippy::used_underscore_binding)]
55#![allow(clippy::result_large_err)]
59#![allow(clippy::redundant_pub_crate)]
61#![allow(clippy::similar_names)]
62
63#![warn(missing_docs)]
64
65#[cfg(any(test, feature = "alloc"))]
66extern crate alloc;
67
68#[cfg(test)]
69extern crate std;
70
71extern crate core;
72
73#[macro_use]
74mod macros;
75
76mod ptr;
77pub mod buf;
78pub mod opaque_res;
79mod sealed;
80
81pub mod aes;
84pub mod hash;
85mod error;
86
87non_fips! { pub mod chacha;
89}
90
91pub mod aead;
92pub mod mac;
93pub(crate) mod ct;
94pub mod kdf;
95
96pub use ct::ct_eq;
97
98pub mod hex {
99 pub use super::ct::HexError;
102
103 pub use super::ct::hex_encode as encode_into;
104 pub use super::ct::hex_encode_str as encode_str;
105 pub use super::ct::hex_decode as decode_into;
106
107 alloc! {
108 pub use super::ct::hex_encode_alloc as encode;
109 pub use super::ct::hex_decode_alloc as decode;
110 }
111}
112
113pub use error::Unspecified;
114pub use error::MakeOpaque;
115
116#[cfg(not(target_pointer_width = "32"))]
117#[inline]
118#[must_use]
119pub(crate) const fn const_can_cast_u32<const S: usize>() -> bool {
120 const_lte::<S, { u32::MAX }>()
121}
122
123#[cfg(not(target_pointer_width = "32"))]
124#[inline]
125#[must_use]
126pub(crate) const fn can_cast_u32(len: usize) -> bool {
127 len <= (u32::MAX as usize)
128}
129
130#[cfg(target_pointer_width = "32")]
131#[inline]
132#[must_use]
133pub(crate) const fn const_can_cast_u32<const S: usize>() -> bool {
134 true
135}
136
137#[cfg(target_pointer_width = "32")]
138#[inline]
139#[must_use]
140pub(crate) const fn can_cast_u32(_len: usize) -> bool {
141 true
142}
143
144#[inline]
145#[must_use]
146pub(crate) const fn const_can_cast_i32<const S: usize>() -> bool {
147 const_lte::<S, { i32::MAX as u32 }>()
148}
149
150#[inline]
151#[must_use]
152pub(crate) const fn can_cast_i32(len: usize) -> bool {
153 len <= (i32::MAX as usize)
154}
155
156#[must_use]
157pub(crate) const fn const_lte<const L: usize, const MAX: u32>() -> bool {
158 L <= (MAX as usize)
159}
160
161#[cfg_attr(not(feature = "allow-non-fips"), allow(dead_code))]
162#[must_use]
163pub(crate) const fn const_gte<const L: usize, const MIN: usize>() -> bool {
164 L >= MIN
165}
166
167#[allow(dead_code)]
168#[inline]
169#[must_use]
170pub(crate) const fn lte<const MAX: usize>(value: usize) -> bool {
171 value <= MAX
172}
173
174#[cfg_attr(not(feature = "allow-non-fips"), allow(dead_code))]
175#[inline]
176#[must_use]
177pub(crate) const fn gte<const MIN: usize>(value: usize) -> bool {
178 value >= MIN
179}
180
181#[cfg(not(target_pointer_width = "32"))]
182#[inline]
183#[must_use]
184pub(crate) const fn to_u32(num: usize) -> Option<u32> {
185 if can_cast_u32(num) {
186 Some(num as u32)
187 } else {
188 None
189 }
190}
191
192#[cfg(target_pointer_width = "32")]
193#[inline]
194#[must_use]
195pub(crate) const fn to_u32(num: usize) -> Option<u32> {
196 Some(num as u32)
197}
198
199pub trait Fips: sealed::FipsSealed {}
201
202pub const fn ensure_fips<F: Fips>() {}