@@ -20,7 +20,7 @@ use crate::{
2020/// the message and the signing key.
2121/// This value is used in the lottery process to determine the correct indices.
2222#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
23- pub ( crate ) struct SchnorrSignature {
23+ pub struct SchnorrSignature {
2424 /// Deterministic value depending on the message and secret key
2525 pub ( crate ) sigma : JubjubSubgroup ,
2626 /// Part of the Schnorr signature depending on the secret key
@@ -58,24 +58,24 @@ impl SchnorrSignature {
5858 /// to their coordinates representation to feed them to the hash function.
5959 /// - Check: c == c_tilde
6060 ///
61- pub ( crate ) fn verify ( & self , msg : & [ u8 ] , vk : & SchnorrVerificationKey ) -> Result < ( ) > {
62- let g = JubjubSubgroup :: generator ( ) ;
61+ pub fn verify ( & self , msg : & [ u8 ] , vk : & SchnorrVerificationKey ) -> Result < ( ) > {
62+ let generator = JubjubSubgroup :: generator ( ) ;
6363
6464 // First hashing the message to a scalar then hashing it to a curve point
65- let hash = JubjubHashToCurve :: hash_to_curve ( & [ hash_msg_to_jubjubbase ( msg) ?] ) ;
65+ let hash_msg = JubjubHashToCurve :: hash_to_curve ( & [ hash_msg_to_jubjubbase ( msg) ?] ) ;
6666
6767 // Computing R1 = H(msg) * s + sigma * c
68- let c_scalar = jubjub_base_to_scalar ( & self . challenge ) ?;
69- let h_s = hash * self . signature ;
70- let sigma_c = self . sigma * c_scalar ;
68+ let challenge_scalar = jubjub_base_to_scalar ( & self . challenge ) ?;
69+ let h_s = hash_msg * self . signature ;
70+ let sigma_c = self . sigma * challenge_scalar ;
7171 let r1_tilde = h_s + sigma_c;
7272
7373 // Computing R2 = g * s + vk * c
74- let g_s = g * self . signature ;
75- let vk_c = vk. 0 * c_scalar ;
74+ let g_s = generator * self . signature ;
75+ let vk_c = vk. 0 * challenge_scalar ;
7676 let r2_tilde = g_s + vk_c;
7777
78- let ( hashx, hashy) = get_coordinates ( hash ) ;
78+ let ( hashx, hashy) = get_coordinates ( hash_msg ) ;
7979 let ( vkx, vky) = get_coordinates ( vk. 0 ) ;
8080 let ( sigmax, sigmay) = get_coordinates ( self . sigma ) ;
8181 let ( r1x, r1y) = get_coordinates ( r1_tilde) ;
@@ -108,7 +108,7 @@ impl SchnorrSignature {
108108 /// We need to convert the inputs to fit in a Poseidon hash.
109109 /// The order of the hash input must be the same as the one in the SNARK circuit
110110 /// `ev = H(DST || msg || index || σ) <- MSP.Eval(msg,index,σ)` given in paper.
111- fn evaluate_dense_mapping ( & self , msg : & [ u8 ] , index : Index ) -> Result < [ u8 ; 32 ] > {
111+ pub ( crate ) fn evaluate_dense_mapping ( & self , msg : & [ u8 ] , index : Index ) -> Result < [ u8 ; 32 ] > {
112112 let hash = JubjubHashToCurve :: hash_to_curve ( & [ hash_msg_to_jubjubbase ( msg) ?] ) ;
113113 let ( hashx, hashy) = get_coordinates ( hash) ;
114114 // TODO: Check if this is the correct way to add the index
@@ -121,7 +121,7 @@ impl SchnorrSignature {
121121 }
122122
123123 /// Convert an `SchnorrSignature` to a byte representation.
124- pub ( crate ) fn to_bytes ( self ) -> [ u8 ; 96 ] {
124+ pub fn to_bytes ( self ) -> [ u8 ; 96 ] {
125125 let mut out = [ 0 ; 96 ] ;
126126 out[ 0 ..32 ] . copy_from_slice ( & self . sigma . to_bytes ( ) ) ;
127127 out[ 32 ..64 ] . copy_from_slice ( & self . signature . to_bytes ( ) ) ;
@@ -133,11 +133,8 @@ impl SchnorrSignature {
133133 /// Convert a string of bytes into a `SchnorrSignature`.
134134 ///
135135 /// Not sure the sigma, s and c creation can fail if the 96 bytes are correctly extracted.
136- /// TODO: Do we want to fail conversion if there are more than 96 bytes?
137- pub ( crate ) fn from_bytes ( bytes : & [ u8 ] ) -> Result < Self > {
138- let bytes = bytes
139- . get ( ..96 )
140- . ok_or ( anyhow ! ( "Not enough bytes to create a signature." ) ) ?;
136+ pub fn from_bytes ( bytes : & [ u8 ] ) -> Result < Self > {
137+ let bytes: [ u8 ; 96 ] = bytes. try_into ( ) ?;
141138 let sigma = JubjubSubgroup :: from_bytes ( & bytes[ 0 ..32 ] . try_into ( ) ?)
142139 . into_option ( )
143140 . ok_or ( anyhow ! ( "Unable to convert bytes into a sigma value." ) ) ?;
0 commit comments