Skip to main content

commonware_math/
lib.rs

1#![doc = include_str!("../README.md")]
2#![doc(
3    html_logo_url = "https://commonware.xyz/imgs/rustdoc_logo.svg",
4    html_favicon_url = "https://commonware.xyz/favicon.ico"
5)]
6#![cfg_attr(not(any(feature = "std", test)), no_std)]
7
8#[cfg(not(feature = "std"))]
9extern crate alloc;
10
11commonware_macros::stability_scope!(ALPHA {
12    pub mod fields {
13        pub mod goldilocks;
14    }
15    pub mod ntt;
16});
17commonware_macros::stability_scope!(BETA {
18    pub mod algebra;
19    pub mod poly;
20});
21
22commonware_macros::stability_scope!(ALPHA {
23    #[cfg(any(test, feature = "fuzz"))]
24    pub(crate) mod test;
25});
26
27commonware_macros::stability_scope!(ALPHA {
28    #[cfg(feature = "fuzz")]
29    pub mod fuzz {
30        use arbitrary::{Arbitrary, Unstructured};
31
32        #[derive(Debug, Arbitrary)]
33        pub enum Plan {
34            Poly(crate::poly::fuzz::Plan),
35            Algebra(crate::algebra::fuzz::Plan),
36            Goldilocks(crate::fields::goldilocks::fuzz::Plan),
37            Test(crate::test::fuzz::Plan),
38            Ntt(crate::ntt::fuzz::Plan),
39        }
40
41        impl Plan {
42            pub fn run(self, u: &mut Unstructured<'_>) -> arbitrary::Result<()> {
43                match self {
44                    Self::Poly(plan) => plan.run(u),
45                    Self::Algebra(plan) => plan.run(u),
46                    Self::Goldilocks(plan) => plan.run(u),
47                    Self::Test(plan) => plan.run(u),
48                    Self::Ntt(plan) => plan.run(u),
49                }
50            }
51        }
52    }
53});