@@ -108,42 +108,42 @@ int secp256k1_ec_pubkey_serialize(const secp256k1_context_t* ctx, unsigned char
108108 return secp256k1_eckey_pubkey_serialize (& Q , output , outputlen , compressed );
109109}
110110
111- static void secp256k1_ecdsa_signature_load (secp256k1_ecdsa_sig_t * s , int * recid , const secp256k1_ecdsa_signature_t * sig ) {
111+ static void secp256k1_ecdsa_signature_load (secp256k1_scalar_t * r , secp256k1_scalar_t * s , int * recid , const secp256k1_ecdsa_signature_t * sig ) {
112112 if (sizeof (secp256k1_scalar_t ) == 32 ) {
113113 /* When the secp256k1_scalar_t type is exactly 32 byte, use its
114114 * representation inside secp256k1_ecdsa_signature_t, as conversion is very fast.
115115 * Note that secp256k1_ecdsa_signature_save must use the same representation. */
116- memcpy (& s -> r , & sig -> data [0 ], 32 );
117- memcpy (& s -> s , & sig -> data [32 ], 32 );
116+ memcpy (r , & sig -> data [0 ], 32 );
117+ memcpy (s , & sig -> data [32 ], 32 );
118118 } else {
119- secp256k1_scalar_set_b32 (& s -> r , & sig -> data [0 ], NULL );
120- secp256k1_scalar_set_b32 (& s -> s , & sig -> data [32 ], NULL );
119+ secp256k1_scalar_set_b32 (r , & sig -> data [0 ], NULL );
120+ secp256k1_scalar_set_b32 (s , & sig -> data [32 ], NULL );
121121 }
122122 if (recid ) {
123123 * recid = sig -> data [64 ];
124124 }
125125}
126126
127- static void secp256k1_ecdsa_signature_save (secp256k1_ecdsa_signature_t * sig , const secp256k1_ecdsa_sig_t * s , int recid ) {
127+ static void secp256k1_ecdsa_signature_save (secp256k1_ecdsa_signature_t * sig , const secp256k1_scalar_t * r , const secp256k1_scalar_t * s , int recid ) {
128128 if (sizeof (secp256k1_scalar_t ) == 32 ) {
129- memcpy (& sig -> data [0 ], & s -> r , 32 );
130- memcpy (& sig -> data [32 ], & s -> s , 32 );
129+ memcpy (& sig -> data [0 ], r , 32 );
130+ memcpy (& sig -> data [32 ], s , 32 );
131131 } else {
132- secp256k1_scalar_get_b32 (& sig -> data [0 ], & s -> r );
133- secp256k1_scalar_get_b32 (& sig -> data [32 ], & s -> s );
132+ secp256k1_scalar_get_b32 (& sig -> data [0 ], r );
133+ secp256k1_scalar_get_b32 (& sig -> data [32 ], s );
134134 }
135135 sig -> data [64 ] = recid ;
136136}
137137
138138int secp256k1_ecdsa_signature_parse_der (const secp256k1_context_t * ctx , secp256k1_ecdsa_signature_t * sig , const unsigned char * input , int inputlen ) {
139- secp256k1_ecdsa_sig_t s ;
139+ secp256k1_scalar_t r , s ;
140140
141141 (void )ctx ;
142142 DEBUG_CHECK (sig != NULL );
143143 DEBUG_CHECK (input != NULL );
144144
145- if (secp256k1_ecdsa_sig_parse (& s , input , inputlen )) {
146- secp256k1_ecdsa_signature_save (sig , & s , -1 );
145+ if (secp256k1_ecdsa_sig_parse (& r , & s , input , inputlen )) {
146+ secp256k1_ecdsa_signature_save (sig , & r , & s , -1 );
147147 return 1 ;
148148 } else {
149149 memset (sig , 0 , sizeof (* sig ));
@@ -152,50 +152,50 @@ int secp256k1_ecdsa_signature_parse_der(const secp256k1_context_t* ctx, secp256k
152152}
153153
154154int secp256k1_ecdsa_signature_parse_compact (const secp256k1_context_t * ctx , secp256k1_ecdsa_signature_t * sig , const unsigned char * input64 , int recid ) {
155- secp256k1_ecdsa_sig_t s ;
155+ secp256k1_scalar_t r , s ;
156156 int ret = 1 ;
157157 int overflow = 0 ;
158158
159159 (void )ctx ;
160160 DEBUG_CHECK (sig != NULL );
161161 DEBUG_CHECK (input64 != NULL );
162162
163- secp256k1_scalar_set_b32 (& s . r , & input64 [0 ], & overflow );
163+ secp256k1_scalar_set_b32 (& r , & input64 [0 ], & overflow );
164164 ret &= !overflow ;
165- secp256k1_scalar_set_b32 (& s . s , & input64 [32 ], & overflow );
165+ secp256k1_scalar_set_b32 (& s , & input64 [32 ], & overflow );
166166 ret &= !overflow ;
167167 ret &= (recid == -1 || (recid >= 0 && recid < 4 ));
168168 if (ret ) {
169- secp256k1_ecdsa_signature_save (sig , & s , recid );
169+ secp256k1_ecdsa_signature_save (sig , & r , & s , recid );
170170 } else {
171171 memset (sig , 0 , sizeof (* sig ));
172172 }
173173 return ret ;
174174}
175175
176176int secp256k1_ecdsa_signature_serialize_der (const secp256k1_context_t * ctx , unsigned char * output , int * outputlen , const secp256k1_ecdsa_signature_t * sig ) {
177- secp256k1_ecdsa_sig_t s ;
177+ secp256k1_scalar_t r , s ;
178178
179179 (void )ctx ;
180180 DEBUG_CHECK (output != NULL );
181181 DEBUG_CHECK (outputlen != NULL );
182182 DEBUG_CHECK (sig != NULL );
183183
184- secp256k1_ecdsa_signature_load (& s , NULL , sig );
185- return secp256k1_ecdsa_sig_serialize (output , outputlen , & s );
184+ secp256k1_ecdsa_signature_load (& r , & s , NULL , sig );
185+ return secp256k1_ecdsa_sig_serialize (output , outputlen , & r , & s );
186186}
187187
188188int secp256k1_ecdsa_signature_serialize_compact (const secp256k1_context_t * ctx , unsigned char * output64 , int * recid , const secp256k1_ecdsa_signature_t * sig ) {
189- secp256k1_ecdsa_sig_t s ;
189+ secp256k1_scalar_t r , s ;
190190 int rec ;
191191
192192 (void )ctx ;
193193 DEBUG_CHECK (output64 != NULL );
194194 DEBUG_CHECK (sig != NULL );
195195
196- secp256k1_ecdsa_signature_load (& s , & rec , sig );
197- secp256k1_scalar_get_b32 (& output64 [0 ], & s . r );
198- secp256k1_scalar_get_b32 (& output64 [32 ], & s . s );
196+ secp256k1_ecdsa_signature_load (& r , & s , & rec , sig );
197+ secp256k1_scalar_get_b32 (& output64 [0 ], & r );
198+ secp256k1_scalar_get_b32 (& output64 [32 ], & s );
199199 if (recid ) {
200200 DEBUG_CHECK (rec >= 0 && rec < 4 );
201201 * recid = rec ;
@@ -205,7 +205,7 @@ int secp256k1_ecdsa_signature_serialize_compact(const secp256k1_context_t* ctx,
205205
206206int secp256k1_ecdsa_verify (const secp256k1_context_t * ctx , const unsigned char * msg32 , const secp256k1_ecdsa_signature_t * sig , const secp256k1_pubkey_t * pubkey ) {
207207 secp256k1_ge_t q ;
208- secp256k1_ecdsa_sig_t s ;
208+ secp256k1_scalar_t r , s ;
209209 secp256k1_scalar_t m ;
210210 DEBUG_CHECK (ctx != NULL );
211211 DEBUG_CHECK (secp256k1_ecmult_context_is_built (& ctx -> ecmult_ctx ));
@@ -215,8 +215,8 @@ int secp256k1_ecdsa_verify(const secp256k1_context_t* ctx, const unsigned char *
215215
216216 secp256k1_scalar_set_b32 (& m , msg32 , NULL );
217217 secp256k1_pubkey_load (& q , pubkey );
218- secp256k1_ecdsa_signature_load (& s , NULL , sig );
219- return secp256k1_ecdsa_sig_verify (& ctx -> ecmult_ctx , & s , & q , & m );
218+ secp256k1_ecdsa_signature_load (& r , & s , NULL , sig );
219+ return secp256k1_ecdsa_sig_verify (& ctx -> ecmult_ctx , & r , & s , & q , & m );
220220}
221221
222222static int nonce_function_rfc6979 (unsigned char * nonce32 , const unsigned char * msg32 , const unsigned char * key32 , unsigned int counter , const void * data ) {
@@ -245,7 +245,7 @@ const secp256k1_nonce_function_t secp256k1_nonce_function_rfc6979 = nonce_functi
245245const secp256k1_nonce_function_t secp256k1_nonce_function_default = nonce_function_rfc6979 ;
246246
247247int secp256k1_ecdsa_sign (const secp256k1_context_t * ctx , const unsigned char * msg32 , secp256k1_ecdsa_signature_t * signature , const unsigned char * seckey , secp256k1_nonce_function_t noncefp , const void * noncedata ) {
248- secp256k1_ecdsa_sig_t sig ;
248+ secp256k1_scalar_t r , s ;
249249 secp256k1_scalar_t sec , non , msg ;
250250 int recid ;
251251 int ret = 0 ;
@@ -273,7 +273,7 @@ int secp256k1_ecdsa_sign(const secp256k1_context_t* ctx, const unsigned char *ms
273273 secp256k1_scalar_set_b32 (& non , nonce32 , & overflow );
274274 memset (nonce32 , 0 , 32 );
275275 if (!secp256k1_scalar_is_zero (& non ) && !overflow ) {
276- if (secp256k1_ecdsa_sig_sign (& ctx -> ecmult_gen_ctx , & sig , & sec , & msg , & non , & recid )) {
276+ if (secp256k1_ecdsa_sig_sign (& ctx -> ecmult_gen_ctx , & r , & s , & sec , & msg , & non , & recid )) {
277277 break ;
278278 }
279279 }
@@ -284,7 +284,7 @@ int secp256k1_ecdsa_sign(const secp256k1_context_t* ctx, const unsigned char *ms
284284 secp256k1_scalar_clear (& sec );
285285 }
286286 if (ret ) {
287- secp256k1_ecdsa_signature_save (signature , & sig , recid );
287+ secp256k1_ecdsa_signature_save (signature , & r , & s , recid );
288288 } else {
289289 memset (signature , 0 , sizeof (* signature ));
290290 }
@@ -293,7 +293,7 @@ int secp256k1_ecdsa_sign(const secp256k1_context_t* ctx, const unsigned char *ms
293293
294294int secp256k1_ecdsa_recover (const secp256k1_context_t * ctx , const unsigned char * msg32 , const secp256k1_ecdsa_signature_t * signature , secp256k1_pubkey_t * pubkey ) {
295295 secp256k1_ge_t q ;
296- secp256k1_ecdsa_sig_t sig ;
296+ secp256k1_scalar_t r , s ;
297297 secp256k1_scalar_t m ;
298298 int recid ;
299299 DEBUG_CHECK (ctx != NULL );
@@ -302,10 +302,10 @@ int secp256k1_ecdsa_recover(const secp256k1_context_t* ctx, const unsigned char
302302 DEBUG_CHECK (signature != NULL );
303303 DEBUG_CHECK (pubkey != NULL );
304304
305- secp256k1_ecdsa_signature_load (& sig , & recid , signature );
305+ secp256k1_ecdsa_signature_load (& r , & s , & recid , signature );
306306 DEBUG_CHECK (recid >= 0 && recid < 4 );
307307 secp256k1_scalar_set_b32 (& m , msg32 , NULL );
308- if (secp256k1_ecdsa_sig_recover (& ctx -> ecmult_ctx , & sig , & q , & m , recid )) {
308+ if (secp256k1_ecdsa_sig_recover (& ctx -> ecmult_ctx , & r , & s , & q , & m , recid )) {
309309 secp256k1_pubkey_save (pubkey , & q );
310310 return 1 ;
311311 } else {
0 commit comments