1#[cfg(all(feature = "bigint", any(feature = "alloc", feature = "std")))]
4mod biguint;
5#[cfg(all(feature = "bigint", any(feature = "alloc", feature = "std")))]
6pub mod boxed_uint;
7#[cfg(feature = "curve")]
8mod group_element;
9#[cfg(feature = "bigint")]
10mod monty_residue;
11#[cfg(feature = "curve")]
12mod prime_field;
13#[cfg(feature = "primitive")]
14mod primitive;
15#[cfg(feature = "bigint")]
16mod residue;
17#[cfg(feature = "bigint")]
18pub mod uint;
19
20#[cfg(all(feature = "bigint", any(feature = "alloc", feature = "std")))]
21pub use biguint::*;
22#[cfg(all(feature = "bigint", any(feature = "alloc", feature = "std")))]
23pub use boxed_uint::*;
24#[cfg(feature = "curve")]
25pub use group_element::*;
26#[cfg(feature = "bigint")]
27pub use monty_residue::*;
28#[cfg(feature = "curve")]
29pub use prime_field::*;
30#[cfg(feature = "primitive")]
31pub use primitive::*;
32#[cfg(feature = "bigint")]
33pub use residue::*;
34
35use crate::*;
36
37use core::{
38 fmt::Debug,
39 ops::{Add, AddAssign, Deref, DerefMut, Mul, MulAssign, Neg, Sub, SubAssign},
40};
41use rand_core::CryptoRng;
42use subtle::Choice;
43
44pub trait ShareElement:
47 Sized
48 + Clone
49 + Default
50 + Debug
51 + Eq
52 + PartialEq
53 + Deref<Target = Self::Inner>
54 + DerefMut<Target = Self::Inner>
55 + AsRef<Self::Inner>
56 + AsMut<Self::Inner>
57 + From<Self::Inner>
58{
59 type Serialization: AsRef<[u8]> + AsMut<[u8]> + 'static;
61 type Inner: ShareElementInner;
63
64 fn random(rng: impl CryptoRng) -> Self;
66 fn zero() -> Self;
68 fn one() -> Self;
70 fn is_zero(&self) -> Choice;
72 fn serialize(&self) -> Self::Serialization;
74 fn deserialize(serialized: &Self::Serialization) -> VsssResult<Self>;
76 fn from_slice(slice: &[u8]) -> VsssResult<Self>;
78 #[cfg(any(feature = "alloc", feature = "std"))]
79 fn to_vec(&self) -> Vec<u8>;
81}
82
83pub trait ShareIdentifier: ShareElement<Inner: ShareIdentifierInner> {
85 fn inc(&mut self, increment: &Self);
87
88 fn invert(&self) -> VsssResult<Self>;
90
91 fn random_coefficient(rng: impl CryptoRng) -> Self {
105 <Self as ShareElement>::random(rng)
106 }
107}
108
109pub trait ShareVerifier<S: Share>:
111 ShareElement
112 + Copy
113 + Add<Output = Self>
114 + Sub<Output = Self>
115 + AddAssign
116 + SubAssign
117 + Neg<Output = Self>
118 + Mul<S::Identifier, Output = Self>
119 + Mul<S::Value, Output = Self>
120 + MulAssign<S::Identifier>
121 + MulAssign<S::Value>
122 + for<'a> Mul<&'a S::Identifier, Output = Self>
123 + for<'a> Mul<&'a S::Value, Output = Self>
124 + for<'a> MulAssign<&'a S::Identifier>
125 + for<'a> MulAssign<&'a S::Value>
126{
127}
128
129impl<
130 S: Share,
131 SV: ShareElement
132 + Copy
133 + Add<Output = Self>
134 + Sub<Output = Self>
135 + AddAssign
136 + SubAssign
137 + Neg<Output = Self>
138 + Mul<S::Identifier, Output = Self>
139 + Mul<S::Value, Output = Self>
140 + MulAssign<S::Identifier>
141 + MulAssign<S::Value>
142 + for<'a> Mul<&'a S::Identifier, Output = Self>
143 + for<'a> Mul<&'a S::Value, Output = Self>
144 + for<'a> MulAssign<&'a S::Identifier>
145 + for<'a> MulAssign<&'a S::Value>,
146> ShareVerifier<S> for SV
147{
148}
149
150pub trait ShareElementInner:
152 Sized
153 + Debug
154 + Eq
155 + PartialEq
156 + Clone
157 + Default
158 + 'static
159 + Add<Output = Self>
160 + Sub<Output = Self>
161 + AddAssign
162 + SubAssign
163 + for<'a> Add<&'a Self, Output = Self>
164 + for<'a> Sub<&'a Self, Output = Self>
165 + for<'a> AddAssign<&'a Self>
166 + for<'a> SubAssign<&'a Self>
167{
168}
169
170impl<
171 I: Sized
172 + Debug
173 + Eq
174 + PartialEq
175 + Clone
176 + Default
177 + 'static
178 + Add<Output = Self>
179 + Sub<Output = Self>
180 + AddAssign
181 + SubAssign
182 + for<'a> Add<&'a Self, Output = Self>
183 + for<'a> Sub<&'a Self, Output = Self>
184 + for<'a> AddAssign<&'a Self>
185 + for<'a> SubAssign<&'a Self>,
186> ShareElementInner for I
187{
188}
189
190pub trait ShareIdentifierInner:
192 ShareElementInner
193 + Mul<Output = Self>
194 + MulAssign
195 + for<'a> Mul<&'a Self, Output = Self>
196 + for<'a> MulAssign<&'a Self>
197{
198}
199
200impl<
201 E: ShareElementInner
202 + Mul<Output = Self>
203 + MulAssign
204 + for<'a> Mul<&'a Self, Output = Self>
205 + for<'a> MulAssign<&'a Self>,
206> ShareIdentifierInner for E
207{
208}