More of 10793

This commit is contained in:
UdjinM6 2020-01-05 05:00:36 +03:00 committed by Pasta
parent 5857ec7154
commit 5f8bcacd7f
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984
9 changed files with 27 additions and 27 deletions

View File

@ -276,11 +276,11 @@ bool CBitcoinAddress::GetIndexKey(uint160& hashBytes, int& type) const
if (!IsValid()) { if (!IsValid()) {
return false; return false;
} else if (vchVersion == Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS)) { } else if (vchVersion == Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS)) {
memcpy(&hashBytes, &vchData[0], 20); memcpy(&hashBytes, vchData.data(), 20);
type = 1; type = 1;
return true; return true;
} else if (vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS)) { } else if (vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS)) {
memcpy(&hashBytes, &vchData[0], 20); memcpy(&hashBytes, vchData.data(), 20);
type = 2; type = 2;
return true; return true;
} }

View File

@ -66,7 +66,7 @@ static void HASH_DSHA256_0032b(benchmark::State& state)
std::vector<uint8_t> in(32,0); std::vector<uint8_t> in(32,0);
while (state.KeepRunning()) { while (state.KeepRunning()) {
for (int i = 0; i < 1000000; i++) { for (int i = 0; i < 1000000; i++) {
CHash256().Write(in.data(), in.size()).Finalize(&in[0]); CHash256().Write(in.data(), in.size()).Finalize(in.data());
} }
} }
} }
@ -123,42 +123,42 @@ static void HASH_DSHA256_0032b_single(benchmark::State& state)
{ {
std::vector<uint8_t> in(32,0); std::vector<uint8_t> in(32,0);
while (state.KeepRunning()) while (state.KeepRunning())
CHash256().Write(in.data(), in.size()).Finalize(&in[0]); CHash256().Write(in.data(), in.size()).Finalize(in.data());
} }
static void HASH_DSHA256_0080b_single(benchmark::State& state) static void HASH_DSHA256_0080b_single(benchmark::State& state)
{ {
std::vector<uint8_t> in(80,0); std::vector<uint8_t> in(80,0);
while (state.KeepRunning()) while (state.KeepRunning())
CHash256().Write(in.data(), in.size()).Finalize(&in[0]); CHash256().Write(in.data(), in.size()).Finalize(in.data());
} }
static void HASH_DSHA256_0128b_single(benchmark::State& state) static void HASH_DSHA256_0128b_single(benchmark::State& state)
{ {
std::vector<uint8_t> in(128,0); std::vector<uint8_t> in(128,0);
while (state.KeepRunning()) while (state.KeepRunning())
CHash256().Write(in.data(), in.size()).Finalize(&in[0]); CHash256().Write(in.data(), in.size()).Finalize(in.data());
} }
static void HASH_DSHA256_0512b_single(benchmark::State& state) static void HASH_DSHA256_0512b_single(benchmark::State& state)
{ {
std::vector<uint8_t> in(512,0); std::vector<uint8_t> in(512,0);
while (state.KeepRunning()) while (state.KeepRunning())
CHash256().Write(in.data(), in.size()).Finalize(&in[0]); CHash256().Write(in.data(), in.size()).Finalize(in.data());
} }
static void HASH_DSHA256_1024b_single(benchmark::State& state) static void HASH_DSHA256_1024b_single(benchmark::State& state)
{ {
std::vector<uint8_t> in(1024,0); std::vector<uint8_t> in(1024,0);
while (state.KeepRunning()) while (state.KeepRunning())
CHash256().Write(in.data(), in.size()).Finalize(&in[0]); CHash256().Write(in.data(), in.size()).Finalize(in.data());
} }
static void HASH_DSHA256_2048b_single(benchmark::State& state) static void HASH_DSHA256_2048b_single(benchmark::State& state)
{ {
std::vector<uint8_t> in(2048,0); std::vector<uint8_t> in(2048,0);
while (state.KeepRunning()) while (state.KeepRunning())
CHash256().Write(in.data(), in.size()).Finalize(&in[0]); CHash256().Write(in.data(), in.size()).Finalize(in.data());
} }
static void HASH_X11(benchmark::State& state) static void HASH_X11(benchmark::State& state)

View File

@ -37,7 +37,7 @@ SecureString CMnemonic::Generate(int strength)
return SecureString(); return SecureString();
} }
SecureVector data(32); SecureVector data(32);
GetStrongRandBytes(&data[0], 32); GetStrongRandBytes(data.data(), 32);
SecureString mnemonic = FromData(data, strength / 8); SecureString mnemonic = FromData(data, strength / 8);
return mnemonic; return mnemonic;
} }
@ -50,11 +50,11 @@ SecureString CMnemonic::FromData(const SecureVector& data, int len)
} }
SecureVector checksum(32); SecureVector checksum(32);
CSHA256().Write(&data[0], len).Finalize(&checksum[0]); CSHA256().Write(data.data(), len).Finalize(checksum.data());
// data // data
SecureVector bits(len); SecureVector bits(len);
memcpy(&bits[0], &data[0], len); memcpy(bits.data(), data.data(), len);
// checksum // checksum
bits.push_back(checksum[0]); bits.push_back(checksum[0]);
@ -132,7 +132,7 @@ bool CMnemonic::Check(SecureString mnemonic)
return false; return false;
} }
bits[32] = bits[nWordCount * 4 / 3]; bits[32] = bits[nWordCount * 4 / 3];
CSHA256().Write(&bits[0], nWordCount * 4 / 3).Finalize(&bits[0]); CSHA256().Write(bits.data(), nWordCount * 4 / 3).Finalize(bits.data());
bool fResult = 0; bool fResult = 0;
if (nWordCount == 12) { if (nWordCount == 12) {
@ -158,5 +158,5 @@ void CMnemonic::ToSeed(SecureString mnemonic, SecureString passphrase, SecureVec
// const unsigned char *salt, int saltlen, int iter, // const unsigned char *salt, int saltlen, int iter,
// const EVP_MD *digest, // const EVP_MD *digest,
// int keylen, unsigned char *out); // int keylen, unsigned char *out);
PKCS5_PBKDF2_HMAC(mnemonic.c_str(), mnemonic.size(), &vchSalt[0], vchSalt.size(), 2048, EVP_sha512(), 64, &seedRet[0]); PKCS5_PBKDF2_HMAC(mnemonic.c_str(), mnemonic.size(), vchSalt.data(), vchSalt.size(), 2048, EVP_sha512(), 64, seedRet.data());
} }

View File

@ -97,7 +97,7 @@ private:
// read data and checksum from file // read data and checksum from file
try { try {
filein.read((char *)&vchData[0], dataSize); filein.read((char *)vchData.data(), dataSize);
filein >> hashIn; filein >> hashIn;
} }
catch (std::exception &e) { catch (std::exception &e) {

View File

@ -53,7 +53,7 @@ void CHDChain::Debug(const std::string& strName) const
std::cout << "seed: " << HexStr(vchSeed).c_str() << std::endl; std::cout << "seed: " << HexStr(vchSeed).c_str() << std::endl;
CExtKey extkey; CExtKey extkey;
extkey.SetMaster(&vchSeed[0], vchSeed.size()); extkey.SetMaster(vchSeed.data(), vchSeed.size());
CBitcoinExtKey b58extkey; CBitcoinExtKey b58extkey;
b58extkey.SetKey(extkey); b58extkey.SetKey(extkey);
@ -158,7 +158,7 @@ void CHDChain::DeriveChildExtKey(uint32_t nAccountIndex, bool fInternal, uint32_
CExtKey changeKey; //key at m/purpose'/coin_type'/account'/change CExtKey changeKey; //key at m/purpose'/coin_type'/account'/change
CExtKey childKey; //key at m/purpose'/coin_type'/account'/change/address_index CExtKey childKey; //key at m/purpose'/coin_type'/account'/change/address_index
masterKey.SetMaster(&vchSeed[0], vchSeed.size()); masterKey.SetMaster(vchSeed.data(), vchSeed.size());
// Use hardened derivation for purpose, coin_type and account // Use hardened derivation for purpose, coin_type and account
// (keys >= 0x80000000 are hardened after bip32) // (keys >= 0x80000000 are hardened after bip32)

View File

@ -41,7 +41,7 @@ SecureString DecodeBase64Secure(const SecureString& sInput)
BIO *b64, *mem; BIO *b64, *mem;
b64 = BIO_new(BIO_f_base64()); b64 = BIO_new(BIO_f_base64());
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); //Do not use newlines to flush buffer BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); //Do not use newlines to flush buffer
mem = BIO_new_mem_buf((void *) &sInput[0], sInput.size()); mem = BIO_new_mem_buf((void *) sInput.data(), sInput.size());
BIO_push(b64, mem); BIO_push(b64, mem);
// Prepare buffer to receive decoded data // Prepare buffer to receive decoded data
@ -53,7 +53,7 @@ SecureString DecodeBase64Secure(const SecureString& sInput)
// Decode the string // Decode the string
size_t nLen; size_t nLen;
nLen = BIO_read(b64, (void *) &output[0], sInput.size()); nLen = BIO_read(b64, (void *) output.data(), sInput.size());
output.resize(nLen); output.resize(nLen);
// Free memory // Free memory
@ -72,7 +72,7 @@ SecureString EncodeBase64Secure(const SecureString& sInput)
BIO_push(b64, mem); BIO_push(b64, mem);
// Decode the string // Decode the string
BIO_write(b64, &sInput[0], sInput.size()); BIO_write(b64, sInput.data(), sInput.size());
(void) BIO_flush(b64); (void) BIO_flush(b64);
// Create output variable from buffer mem ptr // Create output variable from buffer mem ptr
@ -145,10 +145,10 @@ std::string CKeePassIntegrator::CKeePassRequest::getJson()
void CKeePassIntegrator::CKeePassRequest::init() void CKeePassIntegrator::CKeePassRequest::init()
{ {
SecureString sIVSecure = generateRandomKey(KEEPASS_CRYPTO_BLOCK_SIZE); SecureString sIVSecure = generateRandomKey(KEEPASS_CRYPTO_BLOCK_SIZE);
strIV = std::string(&sIVSecure[0], sIVSecure.size()); strIV = std::string(sIVSecure.data(), sIVSecure.size());
// Generate Nonce, Verifier and RequestType // Generate Nonce, Verifier and RequestType
SecureString sNonceBase64Secure = EncodeBase64Secure(sIVSecure); SecureString sNonceBase64Secure = EncodeBase64Secure(sIVSecure);
addStrParameter("Nonce", std::string(&sNonceBase64Secure[0], sNonceBase64Secure.size())); // Plain addStrParameter("Nonce", std::string(sNonceBase64Secure.data(), sNonceBase64Secure.size())); // Plain
addStrParameter("Verifier", sNonceBase64Secure); // Encoded addStrParameter("Verifier", sNonceBase64Secure); // Encoded
addStrParameter("RequestType", strType); addStrParameter("RequestType", strType);
} }
@ -228,7 +228,7 @@ SecureString CKeePassIntegrator::generateRandomKey(size_t nSize)
SecureString sKey; SecureString sKey;
sKey.resize(nSize); sKey.resize(nSize);
GetStrongRandBytes((unsigned char *) &sKey[0], nSize); GetStrongRandBytes((unsigned char *) sKey.data(), nSize);
return sKey; return sKey;
} }
@ -463,7 +463,7 @@ void CKeePassIntegrator::rpcAssociate(std::string& strIdRet, SecureString& sKeyB
CKeePassRequest request(sKey, "associate"); CKeePassRequest request(sKey, "associate");
sKeyBase64Ret = EncodeBase64Secure(sKey); sKeyBase64Ret = EncodeBase64Secure(sKey);
request.addStrParameter("Key", std::string(&sKeyBase64Ret[0], sKeyBase64Ret.size())); request.addStrParameter("Key", std::string(sKeyBase64Ret.data(), sKeyBase64Ret.size()));
int nStatus; int nStatus;
std::string strResponse; std::string strResponse;

View File

@ -65,7 +65,7 @@ bool CHashSigner::VerifyHash(const uint256& hash, const CKeyID& keyID, const std
if(pubkeyFromSig.GetID() != keyID) { if(pubkeyFromSig.GetID() != keyID) {
strErrorRet = strprintf("Keys don't match: pubkey=%s, pubkeyFromSig=%s, hash=%s, vchSig=%s", strErrorRet = strprintf("Keys don't match: pubkey=%s, pubkeyFromSig=%s, hash=%s, vchSig=%s",
keyID.ToString(), pubkeyFromSig.GetID().ToString(), hash.ToString(), keyID.ToString(), pubkeyFromSig.GetID().ToString(), hash.ToString(),
EncodeBase64(&vchSig[0], vchSig.size())); EncodeBase64(vchSig.data(), vchSig.size()));
return false; return false;
} }

View File

@ -387,7 +387,7 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction &tran
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
ssTx << *newTx->tx; ssTx << *newTx->tx;
transaction_array.append(&(ssTx[0]), ssTx.size()); transaction_array.append(ssTx.data(), ssTx.size());
} }
// Add addresses / update labels that we've sent to the address book, // Add addresses / update labels that we've sent to the address book,

View File

@ -54,7 +54,7 @@ BOOST_AUTO_TEST_CASE(bip39_vectors)
CExtKey key; CExtKey key;
CExtPubKey pubkey; CExtPubKey pubkey;
key.SetMaster(&seed[0], 64); key.SetMaster(seed.data(), 64);
pubkey = key.Neuter(); pubkey = key.Neuter();
CBitcoinExtKey b58key; CBitcoinExtKey b58key;