@@ -120,7 +120,7 @@ static int secp256k1_pubkey_load(const secp256k1_context* ctx, secp256k1_ge* ge,
120120 * representation inside secp256k1_pubkey, as conversion is very fast.
121121 * Note that secp256k1_pubkey_save must use the same representation. */
122122 secp256k1_ge_storage s ;
123- memcpy (& s , & pubkey -> data [0 ], 64 );
123+ memcpy (& s , & pubkey -> data [0 ], sizeof ( s ) );
124124 secp256k1_ge_from_storage (ge , & s );
125125 } else {
126126 /* 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) {
137137 if (sizeof (secp256k1_ge_storage ) == 64 ) {
138138 secp256k1_ge_storage s ;
139139 secp256k1_ge_to_storage (& s , ge );
140- memcpy (& pubkey -> data [0 ], & s , 64 );
140+ memcpy (& pubkey -> data [0 ], & s , sizeof ( s ) );
141141 } else {
142142 VERIFY_CHECK (!secp256k1_ge_is_infinity (ge ));
143143 secp256k1_fe_normalize_var (& ge -> x );
@@ -307,9 +307,14 @@ int secp256k1_ecdsa_verify(const secp256k1_context* ctx, const secp256k1_ecdsa_s
307307 secp256k1_ecdsa_sig_verify (& ctx -> ecmult_ctx , & r , & s , & q , & m ));
308308}
309309
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+
310315static int nonce_function_rfc6979 (unsigned char * nonce32 , const unsigned char * msg32 , const unsigned char * key32 , const unsigned char * algo16 , void * data , unsigned int counter ) {
311316 unsigned char keydata [112 ];
312- int keylen = 64 ;
317+ unsigned int offset = 0 ;
313318 secp256k1_rfc6979_hmac_sha256 rng ;
314319 unsigned int i ;
315320 /* 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
320325 * different argument mixtures to emulate each other and result in the same
321326 * nonces.
322327 */
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 );
325330 if (data != NULL ) {
326- memcpy (keydata + 64 , data , 32 );
327- keylen = 96 ;
331+ buffer_append (keydata , & offset , data , 32 );
328332 }
329333 if (algo16 != NULL ) {
330- memcpy (keydata + keylen , algo16 , 16 );
331- keylen += 16 ;
334+ buffer_append (keydata , & offset , algo16 , 16 );
332335 }
333- secp256k1_rfc6979_hmac_sha256_initialize (& rng , keydata , keylen );
336+ secp256k1_rfc6979_hmac_sha256_initialize (& rng , keydata , offset );
334337 memset (keydata , 0 , sizeof (keydata ));
335338 for (i = 0 ; i <= counter ; i ++ ) {
336339 secp256k1_rfc6979_hmac_sha256_generate (& rng , nonce32 , 32 );
0 commit comments