@ -125,8 +125,8 @@ bool CKey::Check(const unsigned char *vch) {
void CKey : : MakeNewKey ( bool fCompressedIn ) {
void CKey : : MakeNewKey ( bool fCompressedIn ) {
do {
do {
GetStrongRandBytes ( vch , sizeof ( vch ) ) ;
GetStrongRandBytes ( keydata . data ( ) , keydata . size ( ) ) ;
} while ( ! Check ( vch ) ) ;
} while ( ! Check ( keydata . data ( ) ) ) ;
fValid = true ;
fValid = true ;
fCompressed = fCompressedIn ;
fCompressed = fCompressedIn ;
}
}
@ -224,20 +224,18 @@ bool CKey::Load(CPrivKey &privkey, CPubKey &vchPubKey, bool fSkipCheck=false) {
bool CKey : : Derive ( CKey & keyChild , ChainCode & ccChild , unsigned int nChild , const ChainCode & cc ) const {
bool CKey : : Derive ( CKey & keyChild , ChainCode & ccChild , unsigned int nChild , const ChainCode & cc ) const {
assert ( IsValid ( ) ) ;
assert ( IsValid ( ) ) ;
assert ( IsCompressed ( ) ) ;
assert ( IsCompressed ( ) ) ;
unsigned char out [ 64 ] ;
std : : vector < unsigned char , secure_allocator < unsigned char > > vout ( 64 ) ;
LockObject ( out ) ;
if ( ( nChild > > 31 ) = = 0 ) {
if ( ( nChild > > 31 ) = = 0 ) {
CPubKey pubkey = GetPubKey ( ) ;
CPubKey pubkey = GetPubKey ( ) ;
assert ( pubkey . begin ( ) + 33 = = pubkey . end ( ) ) ;
assert ( pubkey . begin ( ) + 33 = = pubkey . end ( ) ) ;
BIP32Hash ( cc , nChild , * pubkey . begin ( ) , pubkey . begin ( ) + 1 , out ) ;
BIP32Hash ( cc , nChild , * pubkey . begin ( ) , pubkey . begin ( ) + 1 , v out. data ( ) ) ;
} else {
} else {
assert ( begin ( ) + 32 = = end ( ) ) ;
assert ( begin ( ) + 32 = = end ( ) ) ;
BIP32Hash ( cc , nChild , 0 , begin ( ) , out ) ;
BIP32Hash ( cc , nChild , 0 , begin ( ) , v out. data ( ) ) ;
}
}
memcpy ( ccChild . begin ( ) , out + 32 , 32 ) ;
memcpy ( ccChild . begin ( ) , v out. data ( ) + 32 , 32 ) ;
memcpy ( ( unsigned char * ) keyChild . begin ( ) , begin ( ) , 32 ) ;
memcpy ( ( unsigned char * ) keyChild . begin ( ) , begin ( ) , 32 ) ;
bool ret = secp256k1_ec_privkey_tweak_add ( secp256k1_context_sign , ( unsigned char * ) keyChild . begin ( ) , out ) ;
bool ret = secp256k1_ec_privkey_tweak_add ( secp256k1_context_sign , ( unsigned char * ) keyChild . begin ( ) , vout . data ( ) ) ;
UnlockObject ( out ) ;
keyChild . fCompressed = true ;
keyChild . fCompressed = true ;
keyChild . fValid = ret ;
keyChild . fValid = ret ;
return ret ;
return ret ;
@ -253,12 +251,10 @@ bool CExtKey::Derive(CExtKey &out, unsigned int _nChild) const {
void CExtKey : : SetMaster ( const unsigned char * seed , unsigned int nSeedLen ) {
void CExtKey : : SetMaster ( const unsigned char * seed , unsigned int nSeedLen ) {
static const unsigned char hashkey [ ] = { ' B ' , ' i ' , ' t ' , ' c ' , ' o ' , ' i ' , ' n ' , ' ' , ' s ' , ' e ' , ' e ' , ' d ' } ;
static const unsigned char hashkey [ ] = { ' B ' , ' i ' , ' t ' , ' c ' , ' o ' , ' i ' , ' n ' , ' ' , ' s ' , ' e ' , ' e ' , ' d ' } ;
unsigned char out [ 64 ] ;
std : : vector < unsigned char , secure_allocator < unsigned char > > vout ( 64 ) ;
LockObject ( out ) ;
CHMAC_SHA512 ( hashkey , sizeof ( hashkey ) ) . Write ( seed , nSeedLen ) . Finalize ( vout . data ( ) ) ;
CHMAC_SHA512 ( hashkey , sizeof ( hashkey ) ) . Write ( seed , nSeedLen ) . Finalize ( out ) ;
key . Set ( & vout [ 0 ] , & vout [ 32 ] , true ) ;
key . Set ( & out [ 0 ] , & out [ 32 ] , true ) ;
memcpy ( chaincode . begin ( ) , & vout [ 32 ] , 32 ) ;
memcpy ( chaincode . begin ( ) , & out [ 32 ] , 32 ) ;
UnlockObject ( out ) ;
nDepth = 0 ;
nDepth = 0 ;
nChild = 0 ;
nChild = 0 ;
memset ( vchFingerprint , 0 , sizeof ( vchFingerprint ) ) ;
memset ( vchFingerprint , 0 , sizeof ( vchFingerprint ) ) ;
@ -308,12 +304,10 @@ void ECC_Start() {
{
{
// Pass in a random blinding seed to the secp256k1 context.
// Pass in a random blinding seed to the secp256k1 context.
unsigned char seed [ 32 ] ;
std : : vector < unsigned char , secure_allocator < unsigned char > > vseed ( 32 ) ;
LockObject ( seed ) ;
GetRandBytes ( vseed . data ( ) , 32 ) ;
GetRandBytes ( seed , 32 ) ;
bool ret = secp256k1_context_randomize ( ctx , vseed . data ( ) ) ;
bool ret = secp256k1_context_randomize ( ctx , seed ) ;
assert ( ret ) ;
assert ( ret ) ;
UnlockObject ( seed ) ;
}
}
secp256k1_context_sign = ctx ;
secp256k1_context_sign = ctx ;