@@ -9,7 +9,7 @@ use midnight_circuits::instructions::HashToCurveCPU;
99
1010use group:: Group ;
1111
12- use crate :: schnorr_signature:: {
12+ pub ( crate ) use crate :: schnorr_signature:: {
1313 DST_SIGNATURE , JubjubHashToCurve , get_coordinates, hash_msg_to_jubjubbase,
1414 jubjub_base_to_scalar,
1515} ;
@@ -67,53 +67,52 @@ impl SchnorrSigningKey {
6767 rng : & mut ( impl RngCore + CryptoRng ) ,
6868 ) -> Result < SchnorrSignature > {
6969 // Use the subgroup generator to compute the curve points
70- let g = JubjubSubgroup :: generator ( ) ;
71- let vk = SchnorrVerificationKey :: from ( self ) ;
70+ let generator = JubjubSubgroup :: generator ( ) ;
71+ let verification_key = SchnorrVerificationKey :: from ( self ) ;
7272
7373 // First hashing the message to a scalar then hashing it to a curve point
74- let hash = JubjubHashToCurve :: hash_to_curve ( & [ hash_msg_to_jubjubbase ( msg) ?] ) ;
74+ let hash_msg = JubjubHashToCurve :: hash_to_curve ( & [ hash_msg_to_jubjubbase ( msg) ?] ) ;
7575
7676 // sigma = H(Sha256(msg)) * sk
77- let sigma = hash * self . 0 ;
77+ let sigma = hash_msg * self . 0 ;
7878
7979 // Compute the random part of the signature with
8080 // r1 = H(msg) * r
8181 // r2 = g * r
82- let r = JubjubScalar :: random ( rng) ;
83- let r1 = hash * r ;
84- let r2 = g * r ;
82+ let random_scalar = JubjubScalar :: random ( rng) ;
83+ let random_value_1 = hash_msg * random_scalar ;
84+ let random_value_2 = generator * random_scalar ;
8585
8686 // Since the hash function takes as input scalar elements
8787 // We need to convert the EC points to their coordinates
8888 // I use gx and gy for now but maybe we can replace them by a DST?
89- let ( hashx , hashy ) = get_coordinates ( hash ) ;
90- let ( vkx , vky ) = get_coordinates ( vk . 0 ) ;
91- let ( sigmax , sigmay ) = get_coordinates ( sigma) ;
92- let ( r1x , r1y ) = get_coordinates ( r1 ) ;
93- let ( r2x , r2y ) = get_coordinates ( r2 ) ;
89+ let ( hash_msg_x , hash_msg_y ) = get_coordinates ( hash_msg ) ;
90+ let ( verification_key_x , verification_key_y ) = get_coordinates ( verification_key . 0 ) ;
91+ let ( sigma_x , sigma_y ) = get_coordinates ( sigma) ;
92+ let ( random_value_1_x , random_value_1_y ) = get_coordinates ( random_value_1 ) ;
93+ let ( random_value_2_x , random_value_2_y ) = get_coordinates ( random_value_2 ) ;
9494
95- let c = PoseidonChip :: < JubjubBase > :: hash ( & [
95+ let challenge = PoseidonChip :: < JubjubBase > :: hash ( & [
9696 DST_SIGNATURE ,
97- hashx ,
98- hashy ,
99- vkx ,
100- vky ,
101- sigmax ,
102- sigmay ,
103- r1x ,
104- r1y ,
105- r2x ,
106- r2y ,
97+ hash_msg_x ,
98+ hash_msg_y ,
99+ verification_key_x ,
100+ verification_key_y ,
101+ sigma_x ,
102+ sigma_y ,
103+ random_value_1_x ,
104+ random_value_1_y ,
105+ random_value_2_x ,
106+ random_value_2_y ,
107107 ] ) ;
108108
109109 // We want to use the from_raw function because the result of
110110 // the poseidon hash might not fit into the smaller modulus
111111 // the Fr scalar field
112- // TODO: Refactor this
113- let c_scalar = jubjub_base_to_scalar ( & c) ?;
114- let s = r - c_scalar * self . 0 ;
112+ let challenge_scalar = jubjub_base_to_scalar ( & challenge) ?;
113+ let signature = random_scalar - challenge_scalar * self . 0 ;
115114
116- Ok ( SchnorrSignature { sigma, s , c } )
115+ Ok ( SchnorrSignature { sigma, signature , challenge } )
117116 }
118117
119118 pub ( crate ) fn to_bytes ( & self ) -> [ u8 ; 32 ] {
@@ -130,6 +129,7 @@ impl SchnorrSigningKey {
130129 . get ( ..32 )
131130 . ok_or ( anyhow ! ( "Not enough bytes to create a signing key." ) ) ?
132131 . try_into ( ) ?;
132+
133133 // Jubjub returs a CtChoice so I convert it to an option that looses the const time property
134134 match JubjubScalar :: from_bytes ( bytes) . into_option ( ) {
135135 Some ( sk) => Ok ( Self ( sk) ) ,
@@ -144,7 +144,7 @@ impl SchnorrSigningKey {
144144//
145145#[ cfg( test) ]
146146mod tests {
147- use super :: * ;
147+ pub ( crate ) use super :: * ;
148148 use rand_chacha:: ChaCha20Rng ;
149149 use rand_core:: SeedableRng ;
150150
0 commit comments