1+ //! User functions impl for some user-side operations, including:
2+ //! blind, unblind and proof of knowledge of committed values.
3+
14use ark_bn254:: { G1Affine as G1 , G1Projective as G1Projective , Fr as Scalar } ;
25use ark_ec:: CurveGroup ;
36use ark_ff:: PrimeField ;
@@ -7,20 +10,19 @@ use sha2::{Digest, Sha256};
710
811use crate :: bbs_bn254:: structs:: { BlindedCommitment , CommitmentProof , Parameters } ;
912
10- /// User functions impl for BBS+ signatures over BN254.
11- /// Includes blind, unblind, proofgen
12-
1313/// Create a blinded commitment for a list of messages.
1414/// Returns `Err` if message length exceeds available parameters.
15- pub fn blind ( params : & Parameters , messages : & [ Scalar ] ) -> Result < BlindedCommitment , & ' static str > {
15+ /// data with index at and behind `blind_index` will be blinded, should be between 1 and messages.len() - 1
16+ pub fn blind ( params : & Parameters , messages : & [ Scalar ] , blind_index : usize ) -> Result < BlindedCommitment , & ' static str > {
1617 let mut rng = ark_std:: test_rng ( ) ;
17- blind_with_rng ( params, messages, & mut rng)
18+ blind_with_rng ( params, messages, blind_index , & mut rng)
1819}
1920
2021/// Create a blinded commitment using a caller-supplied RNG.
2122pub fn blind_with_rng < R : RngCore > (
2223 params : & Parameters ,
2324 messages : & [ Scalar ] ,
25+ blind_index : usize ,
2426 rng : & mut R ,
2527) -> Result < BlindedCommitment , & ' static str > {
2628 if messages. len ( ) > params. L {
@@ -29,11 +31,17 @@ pub fn blind_with_rng<R: RngCore>(
2931 if params. H . len ( ) < messages. len ( ) + 1 {
3032 return Err ( "parameters do not include enough message base points" ) ;
3133 }
34+ if blind_index == 0 || blind_index >= messages. len ( ) {
35+ return Err ( "invalid blind index" ) ;
36+ }
3237
38+ // calc r*H_1
3339 let blinding_factor = Scalar :: rand ( rng) ;
3440 let mut commitment = params. H [ 0 ] * blinding_factor;
35- for ( i, m) in messages. iter ( ) . enumerate ( ) {
36- commitment += params. H [ i + 1 ] * m;
41+
42+ // calc m_j*H_{j+1}
43+ for j in ( blind_index - 1 ) ..messages. len ( ) {
44+ commitment += params. H [ j + 1 ] * messages[ j] ;
3745 }
3846
3947 Ok ( BlindedCommitment {
@@ -140,7 +148,7 @@ mod tests {
140148 let messages = vec ! [ Scalar :: from( 1u64 ) , Scalar :: from( 2u64 ) , Scalar :: from( 3u64 ) ] ;
141149
142150 let mut rng = ark_std:: test_rng ( ) ;
143- let commitment = blind_with_rng ( & params, & messages, & mut rng) . unwrap ( ) ;
151+ let commitment = blind_with_rng ( & params, & messages, 1 , & mut rng) . unwrap ( ) ;
144152 let proof = commitment_pok_prove_with_rng ( & params, & commitment, & messages, & mut rng) . unwrap ( ) ;
145153
146154 let ok = commitment_pok_verify ( & params, & commitment, & proof) . unwrap ( ) ;
0 commit comments