use crate::{sha256, Evaluation, LagrangePolynomial, Polynomial, StandardFormPolynomial};
use secp::{MaybePoint, MaybeScalar};
pub type SecretShare = Evaluation<MaybeScalar, MaybeScalar>;
pub type PointShare = Evaluation<MaybeScalar, MaybePoint>;
pub type SecretSharingPolynomial = StandardFormPolynomial<MaybeScalar>;
pub type PointSharingPolynomial = StandardFormPolynomial<MaybePoint>;
pub type InterpolatedSecretPolynomial = LagrangePolynomial<MaybeScalar, MaybeScalar>;
pub type InterpolatedPointPolynomial = LagrangePolynomial<MaybeScalar, MaybePoint>;
macro_rules! impl_issue_share {
( $t:ty, $share:ty ) => {
impl $t {
pub fn issue_share(&self, x: MaybeScalar) -> $share {
Evaluation {
input: x,
output: self.evaluate(x),
}
}
}
};
}
impl_issue_share! { SecretSharingPolynomial, SecretShare }
impl_issue_share! { PointSharingPolynomial, PointShare }
impl_issue_share! { InterpolatedSecretPolynomial, SecretShare }
impl_issue_share! { InterpolatedPointPolynomial, PointShare }
macro_rules! impl_derive_secret {
( $t:ty ) => {
impl $t {
pub fn derive_secret(&self, x: MaybeScalar) -> [u8; 32] {
sha256(&self.evaluate(x).serialize())
}
}
};
}
impl_derive_secret! { PointSharingPolynomial }
impl_derive_secret! { InterpolatedPointPolynomial }