use elliptic_curve::{Field, Group};
use rand_core::CryptoRngCore;
use serde::Serialize;
use crate::{compat::CSCurve, math::Polynomial, protocol::Participant};
#[derive(Clone, Debug, Serialize, PartialEq, Eq)]
pub struct TriplePub<C: CSCurve> {
pub big_a: C::AffinePoint,
pub big_b: C::AffinePoint,
pub big_c: C::AffinePoint,
pub participants: Vec<Participant>,
pub threshold: usize,
}
#[derive(Clone, Debug)]
pub struct TripleShare<C: CSCurve> {
pub a: C::Scalar,
pub b: C::Scalar,
pub c: C::Scalar,
}
pub fn deal<C: CSCurve>(
rng: &mut impl CryptoRngCore,
participants: &[Participant],
threshold: usize,
) -> (TriplePub<C>, Vec<TripleShare<C>>) {
let a = C::Scalar::random(&mut *rng);
let b = C::Scalar::random(&mut *rng);
let c = a * b;
let f_a = Polynomial::<C>::extend_random(rng, threshold, &a);
let f_b = Polynomial::<C>::extend_random(rng, threshold, &b);
let f_c = Polynomial::<C>::extend_random(rng, threshold, &c);
let mut shares = Vec::with_capacity(participants.len());
let mut participants_owned = Vec::with_capacity(participants.len());
for p in participants {
participants_owned.push(*p);
let p_scalar = p.scalar::<C>();
shares.push(TripleShare {
a: f_a.evaluate(&p_scalar),
b: f_b.evaluate(&p_scalar),
c: f_c.evaluate(&p_scalar),
});
}
let triple_pub = TriplePub {
big_a: (C::ProjectivePoint::generator() * a).into(),
big_b: (C::ProjectivePoint::generator() * b).into(),
big_c: (C::ProjectivePoint::generator() * c).into(),
participants: participants_owned,
threshold,
};
(triple_pub, shares)
}
mod batch_random_ot;
mod bits;
mod correlated_ot_extension;
mod generation;
mod mta;
mod multiplication;
mod random_ot_extension;
pub use generation::{generate_triple, TripleGenerationOutput};