mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-10 21:19:24 +00:00
3.8.5 Let the caller pass in a DST for the aggregation hash function
Also moves the aggregator over to Digest. While a bit verbose for this context, as all appended items were fixed length, it's length prefixing is solid and the API is pleasant. The downside is the additional dependency which is in tree and quite compact.
This commit is contained in:
@@ -79,15 +79,17 @@ pub(crate) fn batch_verify<C: Ciphersuite>() {
|
||||
}
|
||||
|
||||
pub(crate) fn aggregate<C: Ciphersuite>() {
|
||||
const DST: &[u8] = b"Schnorr Aggregator Test";
|
||||
|
||||
// Create 5 signatures
|
||||
let mut keys = vec![];
|
||||
let mut challenges = vec![];
|
||||
let mut aggregator = SchnorrAggregator::<Sha256, C>::new();
|
||||
let mut aggregator = SchnorrAggregator::<Sha256, C>::new(DST);
|
||||
for i in 0 .. 5 {
|
||||
keys.push(Zeroizing::new(C::random_nonzero_F(&mut OsRng)));
|
||||
// In practice, this MUST be a secure challenge binding to the nonce, key, and any message
|
||||
challenges.push(C::random_nonzero_F(&mut OsRng));
|
||||
aggregator.aggregate(
|
||||
C::generator() * keys[i].deref(),
|
||||
challenges[i],
|
||||
SchnorrSignature::<C>::sign(
|
||||
&keys[i],
|
||||
@@ -101,12 +103,13 @@ pub(crate) fn aggregate<C: Ciphersuite>() {
|
||||
let aggregate =
|
||||
SchnorrAggregate::<C>::read::<&[u8]>(&mut aggregate.serialize().as_ref()).unwrap();
|
||||
assert!(aggregate.verify::<Sha256>(
|
||||
DST,
|
||||
keys
|
||||
.iter()
|
||||
.map(|key| C::generator() * key.deref())
|
||||
.zip(challenges.iter().cloned())
|
||||
.collect::<Vec<_>>()
|
||||
.as_ref()
|
||||
.as_ref(),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user