Skip to content

Commit 21ce388

Browse files
committed
sync fix to sg_enc on dkg branch
1 parent e830b3a commit 21ce388

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

timeboost-crypto/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub struct KeyShare<C: CurveGroup> {
134134
index: u32,
135135
}
136136

137-
#[derive(Debug, Clone)]
137+
#[derive(Debug, Clone, PartialEq)]
138138
pub struct Plaintext(Vec<u8>);
139139

140140
#[serde_as]

timeboost-crypto/src/mre.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ pub struct LabeledDecryptionKey<C: CurveGroup> {
110110
}
111111

112112
impl<C: CurveGroup> LabeledDecryptionKey<C> {
113+
/// Returns the node idx for this decryption key.
114+
pub fn node_idx(&self) -> usize {
115+
self.node_idx
116+
}
117+
113118
/// Decryption for an individual ciphertext produced and extracted from [`encrypt()`]
114119
pub fn decrypt<H: Digest>(
115120
&self,

timeboost-crypto/src/sg_encryption.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ use aes_gcm::{AeadCore, Aes256Gcm, aead};
22
use anyhow::anyhow;
33
use ark_ec::{AffineRepr, CurveGroup, hashing::HashToCurve};
44
use ark_ff::{PrimeField, UniformRand};
5-
use ark_poly::EvaluationDomain;
6-
use ark_poly::Radix2EvaluationDomain;
7-
use ark_poly::{DenseUVPolynomial, polynomial::univariate::DensePolynomial};
5+
use ark_poly::{DenseUVPolynomial, Polynomial, polynomial::univariate::DensePolynomial};
86
use ark_std::rand::Rng;
97
use ark_std::rand::rngs::OsRng;
108
use digest::{Digest, generic_array::GenericArray};
@@ -73,12 +71,15 @@ where
7371
let generator = C::generator();
7472
let mut poly: DensePolynomial<_> = DensePolynomial::rand(degree, rng);
7573

76-
let domain = Radix2EvaluationDomain::<C::ScalarField>::new(committee_size)
77-
.ok_or_else(|| ThresholdEncError::Internal(anyhow!("Unable to create eval domain")))?;
78-
7974
let mut alpha_0 = poly[0];
80-
let mut evals: Vec<_> = domain.fft(&poly);
81-
evals.truncate(committee_size); // FFT might produce to next_power_of_two(committee_size)
75+
76+
// Evaluate polynomial at points 1, 2, 3, ..., committee_size (same as Feldman VSS)
77+
let mut evals = Vec::with_capacity(committee_size);
78+
for i in 0..committee_size {
79+
let eval_point = C::ScalarField::from((i + 1) as u64);
80+
let eval = poly.evaluate(&eval_point);
81+
evals.push(eval);
82+
}
8283

8384
let u_0 = generator * alpha_0;
8485
let pub_key = PublicKey { key: u_0 };
@@ -178,7 +179,6 @@ where
178179
ciphertext: &Self::Ciphertext,
179180
aad: &Self::AssociatedData,
180181
) -> Result<Self::Plaintext, ThresholdEncError> {
181-
let committee_size: usize = committee.size().get();
182182
let threshold = committee.one_honest_threshold().get();
183183
let generator = C::generator();
184184

@@ -188,13 +188,6 @@ where
188188
if dec_shares.len() < threshold {
189189
return Err(ThresholdEncError::NotEnoughShares);
190190
}
191-
let domain: Radix2EvaluationDomain<C::ScalarField> =
192-
Radix2EvaluationDomain::new(committee_size).ok_or_else(|| {
193-
ThresholdEncError::Internal(anyhow!(
194-
"Unable to create eval domain for size {:?}",
195-
committee_size
196-
))
197-
})?;
198191

199192
let (v, nonce, data) = (
200193
ciphertext.v,
@@ -229,11 +222,11 @@ where
229222
return Err(ThresholdEncError::FaultySubset(faulty_subset));
230223
}
231224

232-
// Collect eval points for decryption shares
225+
// Collect eval points using simple evaluation points (same as Feldman VSS)
233226
let (x, w_vec): (Vec<_>, Vec<_>) = dec_shares
234227
.iter()
235228
.take(threshold)
236-
.map(|share| (domain.element(share.index as usize), share.w))
229+
.map(|share| (C::ScalarField::from((share.index + 1) as u64), share.w))
237230
.unzip();
238231

239232
// interpolate in the exponent

0 commit comments

Comments
 (0)