Skip to content

Commit e839fe7

Browse files
committed
bindings/rust/src/lib.rs: add aggregate_with_randomness().
1 parent c7cf208 commit e839fe7

File tree

1 file changed

+47
-18
lines changed

1 file changed

+47
-18
lines changed

bindings/rust/src/lib.rs

+47-18
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use alloc::boxed::Box;
1414
use alloc::vec;
1515
use alloc::vec::Vec;
1616
use core::any::Any;
17-
use core::mem::MaybeUninit;
17+
use core::mem::{transmute, MaybeUninit};
1818
use core::ptr;
1919
use zeroize::Zeroize;
2020

@@ -34,7 +34,6 @@ trait ThreadPoolExt {
3434
#[cfg(all(not(feature = "no-threads"), feature = "std"))]
3535
mod mt {
3636
use super::*;
37-
use core::mem::transmute;
3837
use std::sync::{Mutex, Once};
3938
use threadpool::ThreadPool;
4039

@@ -951,6 +950,21 @@ macro_rules! sig_variant_impl {
951950
Ok(agg_pk)
952951
}
953952

953+
pub fn aggregate_with_randomness(
954+
pks: &[PublicKey],
955+
randomness: &[u8],
956+
nbits: usize,
957+
pks_groupcheck: bool,
958+
) -> Result<Self, BLST_ERROR> {
959+
if pks.len() == 0 {
960+
return Err(BLST_ERROR::BLST_AGGR_TYPE_MISMATCH);
961+
}
962+
if pks_groupcheck {
963+
pks.validate()?;
964+
}
965+
Ok(pks.mult(randomness, nbits))
966+
}
967+
954968
pub fn aggregate_serialized(
955969
pks: &[&[u8]],
956970
pks_validate: bool,
@@ -1516,6 +1530,21 @@ macro_rules! sig_variant_impl {
15161530
Ok(agg_sig)
15171531
}
15181532

1533+
pub fn aggregate_with_randomness(
1534+
sigs: &[Signature],
1535+
randomness: &[u8],
1536+
nbits: usize,
1537+
sigs_groupcheck: bool,
1538+
) -> Result<Self, BLST_ERROR> {
1539+
if sigs.len() == 0 {
1540+
return Err(BLST_ERROR::BLST_AGGR_TYPE_MISMATCH);
1541+
}
1542+
if sigs_groupcheck {
1543+
sigs.validate()?;
1544+
}
1545+
Ok(sigs.mult(randomness, nbits))
1546+
}
1547+
15191548
pub fn aggregate_serialized(
15201549
sigs: &[&[u8]],
15211550
sigs_groupcheck: bool,
@@ -1585,43 +1614,43 @@ macro_rules! sig_variant_impl {
15851614

15861615
fn mult(&self, scalars: &[u8], nbits: usize) -> Self::Output {
15871616
Self::Output {
1588-
point: unsafe {
1589-
core::mem::transmute::<&[_], &[$pk_aff]>(self)
1590-
}
1591-
.mult(scalars, nbits),
1617+
point: unsafe { transmute::<&[_], &[$pk_aff]>(self) }
1618+
.mult(scalars, nbits),
15921619
}
15931620
}
15941621

15951622
fn add(&self) -> Self::Output {
15961623
Self::Output {
1597-
point: unsafe {
1598-
core::mem::transmute::<&[_], &[$pk_aff]>(self)
1599-
}
1600-
.add(),
1624+
point: unsafe { transmute::<&[_], &[$pk_aff]>(self) }
1625+
.add(),
16011626
}
16021627
}
1628+
1629+
fn validate(&self) -> Result<(), BLST_ERROR> {
1630+
unsafe { transmute::<&[_], &[$pk_aff]>(self) }.validate()
1631+
}
16031632
}
16041633

16051634
impl MultiPoint for [Signature] {
16061635
type Output = AggregateSignature;
16071636

16081637
fn mult(&self, scalars: &[u8], nbits: usize) -> Self::Output {
16091638
Self::Output {
1610-
point: unsafe {
1611-
core::mem::transmute::<&[_], &[$sig_aff]>(self)
1612-
}
1613-
.mult(scalars, nbits),
1639+
point: unsafe { transmute::<&[_], &[$sig_aff]>(self) }
1640+
.mult(scalars, nbits),
16141641
}
16151642
}
16161643

16171644
fn add(&self) -> Self::Output {
16181645
Self::Output {
1619-
point: unsafe {
1620-
core::mem::transmute::<&[_], &[$sig_aff]>(self)
1621-
}
1622-
.add(),
1646+
point: unsafe { transmute::<&[_], &[$sig_aff]>(self) }
1647+
.add(),
16231648
}
16241649
}
1650+
1651+
fn validate(&self) -> Result<(), BLST_ERROR> {
1652+
unsafe { transmute::<&[_], &[$sig_aff]>(self) }.validate()
1653+
}
16251654
}
16261655

16271656
#[cfg(test)]

0 commit comments

Comments
 (0)