@@ -20,7 +20,7 @@ static void get_secp_ctx(secp256k1_context** ctx) {
2020
2121    * ctx  =  secp256k1_context_create (
2222        SECP256K1_CONTEXT_SIGN  | SECP256K1_CONTEXT_VERIFY );
23-     unsigned char   rand [33 ];
23+     unsigned char   rand [32 ];
2424    randombytes_buf (rand , 32 );
2525    assert (secp256k1_context_randomize (* ctx , rand ));
2626}
@@ -257,10 +257,10 @@ int bip32_derive(bip32_key *target, const char* source, const char* path) {
257257        }
258258    }
259259    else  if  (strspn (source , "0123456789abcdefABCDEF" ) ==  source_len ) {
260-         // TODO error if seed is more than 256  
261-         unsigned char   seedbytes [256 ];
260+         // Note: BIP32 supports a maximum of 512 bytes of seed.  
261+         unsigned char   seedbytes [512 ];
262262        size_t  bin_len ;
263-         if  (sodium_hex2bin (seedbytes , 256 , source , strlen (source ), ": " , & bin_len , NULL ) !=  0 ) {
263+         if  (sodium_hex2bin (seedbytes , 512 , source , strlen (source ), ": " , & bin_len , NULL ) !=  0 ) {
264264            return  0 ;
265265        }
266266        if  (!bip32_from_seed (& basekey , seedbytes , bin_len )) {
@@ -286,7 +286,7 @@ int bip32_derive(bip32_key *target, const char* source, const char* path) {
286286        }
287287
288288        if  (* end  ==  '\''  ||  * end  ==  'h'  ||  * end  ==  'H'  ||  * end  ==  'p'  ||  * end  ==  'P' ) {
289-             path_index  |= 0x80000000 ;
289+             path_index  |= HARDENED_INDEX ;
290290            end ++ ;
291291        }
292292
0 commit comments