use crate::traits::ToFromBytes;
pub trait Randomize<
PubKey: ToFromBytes,
Scalar,
H: HashToScalar<Scalar>,
const PUBLIC_KEY_LENGTH: usize,
>: Sized
{
fn randomize_internal(&self, r: &Scalar) -> Self;
fn randomize(&self, pk: &PubKey, pks: &[PubKey]) -> Self {
self.randomize_internal(
&randomization_scalar::<PubKey, Scalar, H, PUBLIC_KEY_LENGTH>(pk, pks),
)
}
}
pub trait HashToScalar<Scalar> {
fn hash_to_scalar(bytes: &[u8]) -> Scalar;
}
pub(crate) fn randomization_scalar<
PubKey: ToFromBytes,
Scalar,
H: HashToScalar<Scalar>,
const PUBLIC_KEY_LENGTH: usize,
>(
pk: &PubKey,
pks: &[PubKey],
) -> Scalar {
let mut seed: Vec<u8> = Vec::with_capacity(PUBLIC_KEY_LENGTH * (pks.len() + 1));
seed.extend_from_slice(pk.as_bytes());
for pki in pks {
seed.extend_from_slice(pki.as_bytes());
}
H::hash_to_scalar(seed.as_slice())
}