@@ -120,7 +120,7 @@ static int secp256k1_pubkey_load(const secp256k1_context* ctx, secp256k1_ge* ge,
120
120
* representation inside secp256k1_pubkey, as conversion is very fast.
121
121
* Note that secp256k1_pubkey_save must use the same representation. */
122
122
secp256k1_ge_storage s ;
123
- memcpy (& s , & pubkey -> data [0 ], 64 );
123
+ memcpy (& s , & pubkey -> data [0 ], sizeof ( s ) );
124
124
secp256k1_ge_from_storage (ge , & s );
125
125
} else {
126
126
/* Otherwise, fall back to 32-byte big endian for X and Y. */
@@ -137,7 +137,7 @@ static void secp256k1_pubkey_save(secp256k1_pubkey* pubkey, secp256k1_ge* ge) {
137
137
if (sizeof (secp256k1_ge_storage ) == 64 ) {
138
138
secp256k1_ge_storage s ;
139
139
secp256k1_ge_to_storage (& s , ge );
140
- memcpy (& pubkey -> data [0 ], & s , 64 );
140
+ memcpy (& pubkey -> data [0 ], & s , sizeof ( s ) );
141
141
} else {
142
142
VERIFY_CHECK (!secp256k1_ge_is_infinity (ge ));
143
143
secp256k1_fe_normalize_var (& ge -> x );
@@ -307,9 +307,14 @@ int secp256k1_ecdsa_verify(const secp256k1_context* ctx, const secp256k1_ecdsa_s
307
307
secp256k1_ecdsa_sig_verify (& ctx -> ecmult_ctx , & r , & s , & q , & m ));
308
308
}
309
309
310
+ static SECP256K1_INLINE void buffer_append (unsigned char * buf , unsigned int * offset , const void * data , unsigned int len ) {
311
+ memcpy (buf + * offset , data , len );
312
+ * offset += len ;
313
+ }
314
+
310
315
static int nonce_function_rfc6979 (unsigned char * nonce32 , const unsigned char * msg32 , const unsigned char * key32 , const unsigned char * algo16 , void * data , unsigned int counter ) {
311
316
unsigned char keydata [112 ];
312
- int keylen = 64 ;
317
+ unsigned int offset = 0 ;
313
318
secp256k1_rfc6979_hmac_sha256 rng ;
314
319
unsigned int i ;
315
320
/* We feed a byte array to the PRNG as input, consisting of:
@@ -320,17 +325,15 @@ static int nonce_function_rfc6979(unsigned char *nonce32, const unsigned char *m
320
325
* different argument mixtures to emulate each other and result in the same
321
326
* nonces.
322
327
*/
323
- memcpy (keydata , key32 , 32 );
324
- memcpy (keydata + 32 , msg32 , 32 );
328
+ buffer_append (keydata , & offset , key32 , 32 );
329
+ buffer_append (keydata , & offset , msg32 , 32 );
325
330
if (data != NULL ) {
326
- memcpy (keydata + 64 , data , 32 );
327
- keylen = 96 ;
331
+ buffer_append (keydata , & offset , data , 32 );
328
332
}
329
333
if (algo16 != NULL ) {
330
- memcpy (keydata + keylen , algo16 , 16 );
331
- keylen += 16 ;
334
+ buffer_append (keydata , & offset , algo16 , 16 );
332
335
}
333
- secp256k1_rfc6979_hmac_sha256_initialize (& rng , keydata , keylen );
336
+ secp256k1_rfc6979_hmac_sha256_initialize (& rng , keydata , offset );
334
337
memset (keydata , 0 , sizeof (keydata ));
335
338
for (i = 0 ; i <= counter ; i ++ ) {
336
339
secp256k1_rfc6979_hmac_sha256_generate (& rng , nonce32 , 32 );
0 commit comments