sunscreen_math/misc_traits.rs
1/// For an algebraic structure, this defines the additive identity.
2pub trait Zero
3where
4 Self: Sized,
5{
6 /// The additive identity.
7 fn zero() -> Self;
8
9 /// Whether or not this item is zero.
10 fn vartime_is_zero(&self) -> bool;
11}
12
13/// For an algebraic structure, this defines the multiplicative identity.
14pub trait One
15where
16 Self: Sized,
17{
18 /// The multiplicative identity.
19 fn one() -> Self;
20}
21
22/// Methods for switching elements between finite rings.
23pub trait ModSwitch<R> {
24 /// Treat the input value as unsigned in the current Ring and produce
25 /// the same unsigned value in the ring `R`.
26 fn mod_switch_unsigned(&self) -> R;
27
28 /// Treat the input value as signed in the current field
29 /// (i.e. [-q/2, q/2]) and produce the same signed value in `R`
30 /// (i.e. [-p/2, p/2]).
31 fn mod_switch_signed(&self) -> R;
32}
33
34pub use num::traits::ToBytes;