@@ -13,40 +13,74 @@ use crate::{
1313} ;
1414
1515#[ allow( non_snake_case) ]
16- /// Compute a binding value from the party ID, public nonces, and signed message using XMD-based expansion.
17- pub fn binding ( id : & Scalar , B : & [ PublicNonce ] , msg : & [ u8 ] ) -> Scalar {
18- let prefix = b"WSTS/binding " ;
16+ /// Compute the group commitment from the list of PartyIDs and nonce commitments using XMD-based expansion.
17+ pub fn group_commitment ( commitment_list : & [ ( Scalar , PublicNonce ) ] ) -> Scalar {
18+ let prefix = b"WSTS/group_commitment " ;
1919
20- // Serialize all input into a buffer
2120 let mut buf = Vec :: new ( ) ;
22- buf. extend_from_slice ( & id. to_bytes ( ) ) ;
23-
24- for b in B {
25- buf. extend_from_slice ( b. D . compress ( ) . as_bytes ( ) ) ;
26- buf. extend_from_slice ( b. E . compress ( ) . as_bytes ( ) ) ;
21+ for ( id, public_nonce) in commitment_list {
22+ buf. extend_from_slice ( & id. to_bytes ( ) ) ;
23+ buf. extend_from_slice ( public_nonce. D . compress ( ) . as_bytes ( ) ) ;
24+ buf. extend_from_slice ( public_nonce. E . compress ( ) . as_bytes ( ) ) ;
2725 }
2826
29- buf. extend_from_slice ( msg) ;
27+ expand_to_scalar ( & buf, prefix)
28+ . expect ( "FATAL: DST is less than 256 bytes so operation should not fail" )
29+ }
30+
31+ #[ allow( non_snake_case) ]
32+ /// Compute the group commitment from the list of PartyIDs and nonce commitments using XMD-based expansion.
33+ pub fn group_commitment_compressed ( commitment_list : & [ ( Scalar , Compressed , Compressed ) ] ) -> Scalar {
34+ let prefix = b"WSTS/group_commitment" ;
35+
36+ let mut buf = Vec :: new ( ) ;
37+ for ( id, hiding_commitment, binding_commitment) in commitment_list {
38+ buf. extend_from_slice ( & id. to_bytes ( ) ) ;
39+ buf. extend_from_slice ( hiding_commitment. as_bytes ( ) ) ;
40+ buf. extend_from_slice ( binding_commitment. as_bytes ( ) ) ;
41+ }
3042
3143 expand_to_scalar ( & buf, prefix)
3244 . expect ( "FATAL: DST is less than 256 bytes so operation should not fail" )
3345}
3446
3547#[ allow( non_snake_case) ]
3648/// Compute a binding value from the party ID, public nonces, and signed message using XMD-based expansion.
37- pub fn binding_compressed ( id : & Scalar , B : & [ ( Compressed , Compressed ) ] , msg : & [ u8 ] ) -> Scalar {
49+ pub fn binding (
50+ id : & Scalar ,
51+ group_public_key : Point ,
52+ commitment_list : & [ ( Scalar , PublicNonce ) ] ,
53+ msg : & [ u8 ] ,
54+ ) -> Scalar {
3855 let prefix = b"WSTS/binding" ;
56+ let encoded_group_commitment = group_commitment ( commitment_list) ;
3957
40- // Serialize all input into a buffer
4158 let mut buf = Vec :: new ( ) ;
4259 buf. extend_from_slice ( & id. to_bytes ( ) ) ;
60+ buf. extend_from_slice ( group_public_key. compress ( ) . as_bytes ( ) ) ;
61+ buf. extend_from_slice ( msg) ;
62+ buf. extend_from_slice ( & encoded_group_commitment. to_bytes ( ) ) ;
4363
44- for ( D , E ) in B {
45- buf. extend_from_slice ( D . as_bytes ( ) ) ;
46- buf. extend_from_slice ( E . as_bytes ( ) ) ;
47- }
64+ expand_to_scalar ( & buf, prefix)
65+ . expect ( "FATAL: DST is less than 256 bytes so operation should not fail" )
66+ }
67+
68+ #[ allow( non_snake_case) ]
69+ /// Compute a binding value from the party ID, public nonces, and signed message using XMD-based expansion.
70+ pub fn binding_compressed (
71+ id : & Scalar ,
72+ group_public_key : Point ,
73+ commitment_list : & [ ( Scalar , Compressed , Compressed ) ] ,
74+ msg : & [ u8 ] ,
75+ ) -> Scalar {
76+ let prefix = b"WSTS/binding" ;
77+ let encoded_group_commitment = group_commitment_compressed ( commitment_list) ;
4878
79+ let mut buf = Vec :: new ( ) ;
80+ buf. extend_from_slice ( & id. to_bytes ( ) ) ;
81+ buf. extend_from_slice ( group_public_key. compress ( ) . as_bytes ( ) ) ;
4982 buf. extend_from_slice ( msg) ;
83+ buf. extend_from_slice ( & encoded_group_commitment. to_bytes ( ) ) ;
5084
5185 expand_to_scalar ( & buf, prefix)
5286 . expect ( "FATAL: DST is less than 256 bytes so operation should not fail" )
@@ -82,10 +116,20 @@ pub fn lambda(i: u32, key_ids: &[u32]) -> Scalar {
82116// Is this the best way to return these values?
83117#[ allow( non_snake_case) ]
84118/// Compute the intermediate values used in both the parties and the aggregator
85- pub fn intermediate ( msg : & [ u8 ] , party_ids : & [ u32 ] , nonces : & [ PublicNonce ] ) -> ( Vec < Point > , Point ) {
119+ pub fn intermediate (
120+ msg : & [ u8 ] ,
121+ group_key : Point ,
122+ party_ids : & [ u32 ] ,
123+ nonces : & [ PublicNonce ] ,
124+ ) -> ( Vec < Point > , Point ) {
125+ let commitment_list: Vec < ( Scalar , PublicNonce ) > = party_ids
126+ . iter ( )
127+ . zip ( nonces)
128+ . map ( |( i, nonce) | ( Scalar :: from ( * i) , nonce. clone ( ) ) )
129+ . collect ( ) ;
86130 let rhos: Vec < Scalar > = party_ids
87131 . iter ( )
88- . map ( |& i| binding ( & id ( i) , nonces , msg) )
132+ . map ( |i| binding ( & id ( * i) , group_key , & commitment_list , msg) )
89133 . collect ( ) ;
90134 let R_vec : Vec < Point > = zip ( nonces, rhos)
91135 . map ( |( nonce, rho) | nonce. D + rho * nonce. E )
@@ -99,19 +143,21 @@ pub fn intermediate(msg: &[u8], party_ids: &[u32], nonces: &[PublicNonce]) -> (V
99143/// Compute the aggregate nonce
100144pub fn aggregate_nonce (
101145 msg : & [ u8 ] ,
146+ group_key : Point ,
102147 party_ids : & [ u32 ] ,
103148 nonces : & [ PublicNonce ] ,
104149) -> Result < Point , PointError > {
105- let compressed_nonces : Vec < ( Compressed , Compressed ) > = nonces
150+ let commitment_list : Vec < ( Scalar , Compressed , Compressed ) > = party_ids
106151 . iter ( )
107- . map ( |nonce| ( nonce. D . compress ( ) , nonce. E . compress ( ) ) )
152+ . zip ( nonces)
153+ . map ( |( id, nonce) | ( Scalar :: from ( * id) , nonce. D . compress ( ) , nonce. E . compress ( ) ) )
108154 . collect ( ) ;
109155 let scalars: Vec < Scalar > = party_ids
110156 . iter ( )
111157 . flat_map ( |& i| {
112158 [
113159 Scalar :: from ( 1 ) ,
114- binding_compressed ( & id ( i) , & compressed_nonces , msg) ,
160+ binding_compressed ( & id ( i) , group_key , & commitment_list , msg) ,
115161 ]
116162 } )
117163 . collect ( ) ;
0 commit comments