Skip to main content

mldsa_native_rs/
lib.rs

1#![doc = include_str!("../README.md")]
2//!
3//! # About `randombytes`
4//!
5//! Consumers of this crate must provide a `randombytes`
6//! function whose exported symbol matches the value of
7//! [`crate::randombytes::RANDOMBYTES_INTERNAL_NAME`].
8//! The [`crate::randombytes`] module provides helpers and further
9//! details.
10//!
11//! **This function is at the FFI boundary with the backend C
12//! implementation, and must adhere to the expected C ABI and
13//! semantics.**
14//!
15//! Consumers who do not wish to provide their own implementation may
16//! enable **both** the `rand` and `extern-C-randombytes` Cargo
17//! features.
18//! This makes the crate self-contained by exporting a default
19//! implementation backed by [`rand::fill`].
20//!
21//! ### Security
22//!
23//! The `randombytes` function is a critical cryptographic dependency.
24//! It must produce fresh, unpredictable bytes from a cryptographically
25//! secure random number generator (CSPRNG).
26//!
27//! Any weakness in the provided randomness source directly compromises
28//! the security of all non-deterministic operations performed by
29//! `mldsa-native`.
30
31/// Bindings to the underlying functions and constants from mldsa-native.
32///
33/// This module also re-exports the C types from [`core::ffi`] for convenience.
34pub mod ffi {
35    #![allow(non_upper_case_globals)]
36    #![allow(non_camel_case_types)]
37    #![allow(non_snake_case)]
38
39    include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
40
41    // C types (c_int etc.)
42    pub use core::ffi::*;
43
44    /// The return code that indicates a successful operation.
45    pub const SUCCESS: c_int = 0;
46
47    /// The return code that indicates a failed operation.
48    pub const FAILURE: c_int = -1;
49}
50
51pub mod randombytes;
52
53#[cfg(feature = "wrapper")]
54mod wrapper;
55#[cfg(feature = "wrapper")]
56pub use wrapper::*;
57
58#[cfg(feature = "native")]
59mod cpufeatures;
60
61#[cfg(feature = "built_info")]
62pub mod built_info;