group_math/lib.rs
1// Copyright (C) myl7
2// SPDX-License-Identifier: Apache-2.0
3
4#![feature(portable_simd)]
5
6use std::fmt::Debug;
7use std::ops::{Add, AddAssign};
8
9#[cfg(feature = "byte")]
10pub mod byte;
11#[cfg(feature = "int")]
12pub mod int;
13#[cfg(feature = "int-prime")]
14pub mod int_prime;
15
16/// Group (mathematics) that can be converted from a byte array
17///
18/// `Into<[u8; LAMBDA]>` is not used in any fss crate so not included.
19/// But it is implemented by all groups in the submodules.
20pub trait Group<const LAMBDA: usize>
21where
22 Self: Add<Output = Self>
23 + AddAssign
24 + PartialEq
25 + Eq
26 + Debug
27 + Sized
28 + Clone
29 + Sync
30 + Send
31 + From<[u8; LAMBDA]>,
32{
33 /// Zero in the group
34 fn zero() -> Self;
35
36 /// Additive inverse in the group, e.g., `-x` for `x` in the integer group
37 fn add_inverse(self) -> Self;
38 /// Helper to get the additive inverse if true.
39 /// Used for expressions like `$(-1)^n x$`, in which `t` can be computed from `n`.
40 fn add_inverse_if(self, t: bool) -> Self {
41 if t {
42 self.add_inverse()
43 } else {
44 self
45 }
46 }
47}