1#![allow(non_snake_case)]
6
7use num_bigint::BigInt;
8use num_traits::identities::Zero;
9use std::collections::HashMap;
10use std::vec::Vec;
11
12use crate::group::Group;
13
14#[derive(Debug, Clone)]
22pub struct GenericShareBox<G: Group> {
23 pub publickey: G::Element,
24 pub share: G::Element,
25 pub challenge: G::Scalar,
26 pub response: G::Scalar,
27}
28
29impl<G: Group> Default for GenericShareBox<G>
30where
31 G::Element: Default,
32 G::Scalar: Default,
33{
34 fn default() -> Self {
35 GenericShareBox {
36 publickey: Default::default(),
37 share: Default::default(),
38 challenge: Default::default(),
39 response: Default::default(),
40 }
41 }
42}
43
44impl<G: Group> GenericShareBox<G> {
45 pub fn new() -> Self
46 where
47 G::Element: Default,
48 G::Scalar: Default,
49 {
50 Self::default()
51 }
52
53 pub fn init(
54 &mut self,
55 publickey: G::Element,
56 share: G::Element,
57 challenge: G::Scalar,
58 response: G::Scalar,
59 ) {
60 self.publickey = publickey;
61 self.share = share;
62 self.challenge = challenge;
63 self.response = response;
64 }
65}
66
67#[derive(Debug, Clone)]
75pub struct GenericDistributionSharesBox<G: Group> {
76 pub commitments: Vec<G::Element>,
77 pub positions: HashMap<Vec<u8>, i64>,
79 pub shares: HashMap<Vec<u8>, G::Element>,
81 pub publickeys: Vec<G::Element>,
82 pub challenge: G::Scalar,
83 pub responses: HashMap<Vec<u8>, G::Scalar>,
85 pub U: BigInt, }
87
88impl<G: Group> Default for GenericDistributionSharesBox<G>
89where
90 G::Scalar: Default,
91{
92 fn default() -> Self {
93 GenericDistributionSharesBox {
94 commitments: Vec::new(),
95 positions: HashMap::new(),
96 shares: HashMap::new(),
97 publickeys: Vec::new(),
98 challenge: Default::default(),
99 responses: HashMap::new(),
100 U: BigInt::zero(),
101 }
102 }
103}
104
105impl<G: Group> GenericDistributionSharesBox<G> {
106 pub fn new() -> Self
107 where
108 G::Scalar: Default,
109 {
110 Self::default()
111 }
112
113 #[allow(clippy::too_many_arguments)]
117 pub fn init(
118 &mut self,
119 commitments: &[G::Element],
120 positions: HashMap<Vec<u8>, i64>,
121 shares: HashMap<Vec<u8>, G::Element>,
122 publickeys: &[G::Element],
123 challenge: &G::Scalar,
124 responses: HashMap<Vec<u8>, G::Scalar>,
125 U: &BigInt,
126 ) {
127 self.commitments = commitments.to_vec();
128 self.positions = positions;
129 self.shares = shares;
130 self.publickeys = publickeys.to_vec();
131 self.challenge = challenge.clone();
132 self.responses = responses;
133 self.U = U.clone();
134 }
135}
136
137pub type ShareBox<G> = GenericShareBox<G>;
144
145pub type DistributionSharesBox<G> = GenericDistributionSharesBox<G>;