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    pub mod synthetic;
17});
18commonware_macros::stability_scope!(BETA {
19    pub mod algebra;
20    pub mod poly;
21});
22
23commonware_macros::stability_scope!(ALPHA {
24    #[cfg(any(test, feature = "arbitrary"))]
25    pub mod test;
26});
27
28commonware_macros::stability_scope!(ALPHA {
29    #[cfg(feature = "fuzz")]
30    pub mod fuzz {
31        use arbitrary::{Arbitrary, Unstructured};
32
33        #[derive(Debug, Arbitrary)]
34        pub enum Plan {
35            Poly(crate::poly::fuzz::Plan),
36            Algebra(crate::algebra::fuzz::Plan),
37            Goldilocks(crate::fields::goldilocks::fuzz::Plan),
38            Test(crate::test::fuzz::Plan),
39            Ntt(crate::ntt::fuzz::Plan),
40            Synthetic(crate::synthetic::fuzz::Plan),
41        }
42
43        impl Plan {
44            pub fn run(self, u: &mut Unstructured<'_>) -> arbitrary::Result<()> {
45                match self {
46                    Self::Poly(plan) => plan.run(u),
47                    Self::Algebra(plan) => plan.run(u),
48                    Self::Goldilocks(plan) => plan.run(u),
49                    Self::Test(plan) => plan.run(u),
50                    Self::Ntt(plan) => plan.run(u),
51                    Self::Synthetic(plan) => plan.run(u),
52                }
53            }
54        }
55    }
56});