Skip to main content

bouncycastle_utils/
lib.rs

1//! Basic utilities for the crypto crates.
2//!
3//! The functions contained here are not really intended to be used by end users, but you
4//! are welcome to do so if you wish.
5//!
6//! That said, beware that this crate is not necessarily documented to the same standard as other crates.
7//! Since many of the contained helpers are security-critical (such as the constant time module),
8//! we will prioritize fixing security bugs over maintaining a stable API for this crate.
9//!
10//! This crate intentionally does not have `#![forbid(unsafe_code)]` because some of the constant-time
11//! and zeroization techniques require unsafe code in order to force the compiler into specific
12//! assembly-level behaviours. The idea is to contain the unsafe code in a central location rather
13//! so that the higher-level primitives can stick to safe rust.
14
15#![no_std]
16#![forbid(missing_docs)]
17#![allow(private_bounds)]
18
19pub mod ct;
20pub mod secret;
21
22/// Basic max function. If they are equal, it returns the first one.
23pub fn max<'a, T: PartialOrd>(x: &'a T, y: &'a T) -> &'a T {
24    if x >= y { x } else { y }
25}
26
27/// Basic min function. If they are equal, it returns the first one.
28pub fn min<'a, T: PartialOrd>(x: &'a T, y: &'a T) -> &'a T {
29    if x <= y { x } else { y }
30}