@@ -108,42 +108,42 @@ int secp256k1_ec_pubkey_serialize(const secp256k1_context_t* ctx, unsigned char
108
108
return secp256k1_eckey_pubkey_serialize (& Q , output , outputlen , compressed );
109
109
}
110
110
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 ) {
112
112
if (sizeof (secp256k1_scalar_t ) == 32 ) {
113
113
/* When the secp256k1_scalar_t type is exactly 32 byte, use its
114
114
* representation inside secp256k1_ecdsa_signature_t, as conversion is very fast.
115
115
* 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 );
118
118
} 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 );
121
121
}
122
122
if (recid ) {
123
123
* recid = sig -> data [64 ];
124
124
}
125
125
}
126
126
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 ) {
128
128
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 );
131
131
} 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 );
134
134
}
135
135
sig -> data [64 ] = recid ;
136
136
}
137
137
138
138
int 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 ;
140
140
141
141
(void )ctx ;
142
142
DEBUG_CHECK (sig != NULL );
143
143
DEBUG_CHECK (input != NULL );
144
144
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 );
147
147
return 1 ;
148
148
} else {
149
149
memset (sig , 0 , sizeof (* sig ));
@@ -152,50 +152,50 @@ int secp256k1_ecdsa_signature_parse_der(const secp256k1_context_t* ctx, secp256k
152
152
}
153
153
154
154
int 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 ;
156
156
int ret = 1 ;
157
157
int overflow = 0 ;
158
158
159
159
(void )ctx ;
160
160
DEBUG_CHECK (sig != NULL );
161
161
DEBUG_CHECK (input64 != NULL );
162
162
163
- secp256k1_scalar_set_b32 (& s . r , & input64 [0 ], & overflow );
163
+ secp256k1_scalar_set_b32 (& r , & input64 [0 ], & overflow );
164
164
ret &= !overflow ;
165
- secp256k1_scalar_set_b32 (& s . s , & input64 [32 ], & overflow );
165
+ secp256k1_scalar_set_b32 (& s , & input64 [32 ], & overflow );
166
166
ret &= !overflow ;
167
167
ret &= (recid == -1 || (recid >= 0 && recid < 4 ));
168
168
if (ret ) {
169
- secp256k1_ecdsa_signature_save (sig , & s , recid );
169
+ secp256k1_ecdsa_signature_save (sig , & r , & s , recid );
170
170
} else {
171
171
memset (sig , 0 , sizeof (* sig ));
172
172
}
173
173
return ret ;
174
174
}
175
175
176
176
int 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 ;
178
178
179
179
(void )ctx ;
180
180
DEBUG_CHECK (output != NULL );
181
181
DEBUG_CHECK (outputlen != NULL );
182
182
DEBUG_CHECK (sig != NULL );
183
183
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 );
186
186
}
187
187
188
188
int 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 ;
190
190
int rec ;
191
191
192
192
(void )ctx ;
193
193
DEBUG_CHECK (output64 != NULL );
194
194
DEBUG_CHECK (sig != NULL );
195
195
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 );
199
199
if (recid ) {
200
200
DEBUG_CHECK (rec >= 0 && rec < 4 );
201
201
* recid = rec ;
@@ -205,7 +205,7 @@ int secp256k1_ecdsa_signature_serialize_compact(const secp256k1_context_t* ctx,
205
205
206
206
int secp256k1_ecdsa_verify (const secp256k1_context_t * ctx , const unsigned char * msg32 , const secp256k1_ecdsa_signature_t * sig , const secp256k1_pubkey_t * pubkey ) {
207
207
secp256k1_ge_t q ;
208
- secp256k1_ecdsa_sig_t s ;
208
+ secp256k1_scalar_t r , s ;
209
209
secp256k1_scalar_t m ;
210
210
DEBUG_CHECK (ctx != NULL );
211
211
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 *
215
215
216
216
secp256k1_scalar_set_b32 (& m , msg32 , NULL );
217
217
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 );
220
220
}
221
221
222
222
static 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
245
245
const secp256k1_nonce_function_t secp256k1_nonce_function_default = nonce_function_rfc6979 ;
246
246
247
247
int 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 ;
249
249
secp256k1_scalar_t sec , non , msg ;
250
250
int recid ;
251
251
int ret = 0 ;
@@ -273,7 +273,7 @@ int secp256k1_ecdsa_sign(const secp256k1_context_t* ctx, const unsigned char *ms
273
273
secp256k1_scalar_set_b32 (& non , nonce32 , & overflow );
274
274
memset (nonce32 , 0 , 32 );
275
275
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 )) {
277
277
break ;
278
278
}
279
279
}
@@ -284,7 +284,7 @@ int secp256k1_ecdsa_sign(const secp256k1_context_t* ctx, const unsigned char *ms
284
284
secp256k1_scalar_clear (& sec );
285
285
}
286
286
if (ret ) {
287
- secp256k1_ecdsa_signature_save (signature , & sig , recid );
287
+ secp256k1_ecdsa_signature_save (signature , & r , & s , recid );
288
288
} else {
289
289
memset (signature , 0 , sizeof (* signature ));
290
290
}
@@ -293,7 +293,7 @@ int secp256k1_ecdsa_sign(const secp256k1_context_t* ctx, const unsigned char *ms
293
293
294
294
int secp256k1_ecdsa_recover (const secp256k1_context_t * ctx , const unsigned char * msg32 , const secp256k1_ecdsa_signature_t * signature , secp256k1_pubkey_t * pubkey ) {
295
295
secp256k1_ge_t q ;
296
- secp256k1_ecdsa_sig_t sig ;
296
+ secp256k1_scalar_t r , s ;
297
297
secp256k1_scalar_t m ;
298
298
int recid ;
299
299
DEBUG_CHECK (ctx != NULL );
@@ -302,10 +302,10 @@ int secp256k1_ecdsa_recover(const secp256k1_context_t* ctx, const unsigned char
302
302
DEBUG_CHECK (signature != NULL );
303
303
DEBUG_CHECK (pubkey != NULL );
304
304
305
- secp256k1_ecdsa_signature_load (& sig , & recid , signature );
305
+ secp256k1_ecdsa_signature_load (& r , & s , & recid , signature );
306
306
DEBUG_CHECK (recid >= 0 && recid < 4 );
307
307
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 )) {
309
309
secp256k1_pubkey_save (pubkey , & q );
310
310
return 1 ;
311
311
} else {
0 commit comments