Skip to content

Commit 9c39b3e

Browse files
committed
Don't check for duplicate scalars
Signed-off-by: maurges <nikita@dfns.co>
1 parent 2bfa3f1 commit 9c39b3e

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

key-share/src/trusted_dealer.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,12 @@ impl<E: Curve> TrustedDealerBuilder<E> {
128128
self,
129129
rng: &mut (impl rand_core::RngCore + rand_core::CryptoRng),
130130
) -> Result<Vec<CoreKeyShare<E>>, TrustedDealerError> {
131-
let mut points = Vec::with_capacity(self.n.into());
132-
'each_point: for _ in 0..self.n {
133-
for _ in 0..u16::MAX {
134-
let point = generic_ec::NonZero::<Scalar<E>>::random(rng);
135-
if !points.contains(&point) {
136-
points.push(point);
137-
continue 'each_point;
138-
}
139-
}
140-
// if we did not continue in inner loop, it means we couldn't
141-
// generate a distinct scalar
142-
return Err(Reason::BadRandom.into());
143-
}
131+
// The chance of scalars repeating is negligible for usual fields in EC.
132+
// But in any case the dupliactes are checked during the validation of
133+
// CoreKeyShare
134+
let points = (0..self.n)
135+
.map(|_| generic_ec::NonZero::<Scalar<E>>::random(rng))
136+
.collect();
144137
self.generate_shares_at(points, rng)
145138
}
146139

@@ -255,8 +248,6 @@ enum Reason {
255248
ZeroShare,
256249
#[displaydoc("invalid share preimages given")]
257250
InvalidPreimages,
258-
#[displaydoc("randomness source doesn't have enough entropy")]
259-
BadRandom,
260251
}
261252

262253
impl From<Reason> for TrustedDealerError {

0 commit comments

Comments
 (0)