From 5f8bcacd7fa15b411e6540a7102e25ca68a3453f Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sun, 5 Jan 2020 05:00:36 +0300 Subject: [PATCH] More of 10793 --- src/base58.cpp | 4 ++-- src/bench/crypto_hash.cpp | 14 +++++++------- src/bip39.cpp | 10 +++++----- src/flat-database.h | 2 +- src/hdchain.cpp | 4 ++-- src/keepass.cpp | 14 +++++++------- src/messagesigner.cpp | 2 +- src/qt/walletmodel.cpp | 2 +- src/test/bip39_tests.cpp | 2 +- 9 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/base58.cpp b/src/base58.cpp index af91cd2a43..c5913e4493 100644 --- a/src/base58.cpp +++ b/src/base58.cpp @@ -276,11 +276,11 @@ bool CBitcoinAddress::GetIndexKey(uint160& hashBytes, int& type) const if (!IsValid()) { return false; } else if (vchVersion == Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS)) { - memcpy(&hashBytes, &vchData[0], 20); + memcpy(&hashBytes, vchData.data(), 20); type = 1; return true; } else if (vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS)) { - memcpy(&hashBytes, &vchData[0], 20); + memcpy(&hashBytes, vchData.data(), 20); type = 2; return true; } diff --git a/src/bench/crypto_hash.cpp b/src/bench/crypto_hash.cpp index 4ee66ebb1e..f518d62349 100644 --- a/src/bench/crypto_hash.cpp +++ b/src/bench/crypto_hash.cpp @@ -66,7 +66,7 @@ static void HASH_DSHA256_0032b(benchmark::State& state) std::vector in(32,0); while (state.KeepRunning()) { 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 in(32,0); 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) { std::vector in(80,0); 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) { std::vector in(128,0); 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) { std::vector in(512,0); 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) { std::vector in(1024,0); 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) { std::vector in(2048,0); 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) diff --git a/src/bip39.cpp b/src/bip39.cpp index 7a8f5fb346..458f5688b8 100644 --- a/src/bip39.cpp +++ b/src/bip39.cpp @@ -37,7 +37,7 @@ SecureString CMnemonic::Generate(int strength) return SecureString(); } SecureVector data(32); - GetStrongRandBytes(&data[0], 32); + GetStrongRandBytes(data.data(), 32); SecureString mnemonic = FromData(data, strength / 8); return mnemonic; } @@ -50,11 +50,11 @@ SecureString CMnemonic::FromData(const SecureVector& data, int len) } SecureVector checksum(32); - CSHA256().Write(&data[0], len).Finalize(&checksum[0]); + CSHA256().Write(data.data(), len).Finalize(checksum.data()); // data SecureVector bits(len); - memcpy(&bits[0], &data[0], len); + memcpy(bits.data(), data.data(), len); // checksum bits.push_back(checksum[0]); @@ -132,7 +132,7 @@ bool CMnemonic::Check(SecureString mnemonic) return false; } 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; if (nWordCount == 12) { @@ -158,5 +158,5 @@ void CMnemonic::ToSeed(SecureString mnemonic, SecureString passphrase, SecureVec // const unsigned char *salt, int saltlen, int iter, // const EVP_MD *digest, // 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()); } diff --git a/src/flat-database.h b/src/flat-database.h index 0f4ec0ad19..8ed7442635 100644 --- a/src/flat-database.h +++ b/src/flat-database.h @@ -97,7 +97,7 @@ private: // read data and checksum from file try { - filein.read((char *)&vchData[0], dataSize); + filein.read((char *)vchData.data(), dataSize); filein >> hashIn; } catch (std::exception &e) { diff --git a/src/hdchain.cpp b/src/hdchain.cpp index da6398dab6..04e943d92d 100644 --- a/src/hdchain.cpp +++ b/src/hdchain.cpp @@ -53,7 +53,7 @@ void CHDChain::Debug(const std::string& strName) const std::cout << "seed: " << HexStr(vchSeed).c_str() << std::endl; CExtKey extkey; - extkey.SetMaster(&vchSeed[0], vchSeed.size()); + extkey.SetMaster(vchSeed.data(), vchSeed.size()); CBitcoinExtKey b58extkey; 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 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 // (keys >= 0x80000000 are hardened after bip32) diff --git a/src/keepass.cpp b/src/keepass.cpp index ccc71dc4c8..33031f0a7d 100644 --- a/src/keepass.cpp +++ b/src/keepass.cpp @@ -41,7 +41,7 @@ SecureString DecodeBase64Secure(const SecureString& sInput) BIO *b64, *mem; b64 = BIO_new(BIO_f_base64()); 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); // Prepare buffer to receive decoded data @@ -53,7 +53,7 @@ SecureString DecodeBase64Secure(const SecureString& sInput) // Decode the string size_t nLen; - nLen = BIO_read(b64, (void *) &output[0], sInput.size()); + nLen = BIO_read(b64, (void *) output.data(), sInput.size()); output.resize(nLen); // Free memory @@ -72,7 +72,7 @@ SecureString EncodeBase64Secure(const SecureString& sInput) BIO_push(b64, mem); // Decode the string - BIO_write(b64, &sInput[0], sInput.size()); + BIO_write(b64, sInput.data(), sInput.size()); (void) BIO_flush(b64); // Create output variable from buffer mem ptr @@ -145,10 +145,10 @@ std::string CKeePassIntegrator::CKeePassRequest::getJson() void CKeePassIntegrator::CKeePassRequest::init() { 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 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("RequestType", strType); } @@ -228,7 +228,7 @@ SecureString CKeePassIntegrator::generateRandomKey(size_t nSize) SecureString sKey; sKey.resize(nSize); - GetStrongRandBytes((unsigned char *) &sKey[0], nSize); + GetStrongRandBytes((unsigned char *) sKey.data(), nSize); return sKey; } @@ -463,7 +463,7 @@ void CKeePassIntegrator::rpcAssociate(std::string& strIdRet, SecureString& sKeyB CKeePassRequest request(sKey, "associate"); sKeyBase64Ret = EncodeBase64Secure(sKey); - request.addStrParameter("Key", std::string(&sKeyBase64Ret[0], sKeyBase64Ret.size())); + request.addStrParameter("Key", std::string(sKeyBase64Ret.data(), sKeyBase64Ret.size())); int nStatus; std::string strResponse; diff --git a/src/messagesigner.cpp b/src/messagesigner.cpp index 80894dba30..bb1c91d0fd 100644 --- a/src/messagesigner.cpp +++ b/src/messagesigner.cpp @@ -65,7 +65,7 @@ bool CHashSigner::VerifyHash(const uint256& hash, const CKeyID& keyID, const std if(pubkeyFromSig.GetID() != keyID) { strErrorRet = strprintf("Keys don't match: pubkey=%s, pubkeyFromSig=%s, hash=%s, vchSig=%s", keyID.ToString(), pubkeyFromSig.GetID().ToString(), hash.ToString(), - EncodeBase64(&vchSig[0], vchSig.size())); + EncodeBase64(vchSig.data(), vchSig.size())); return false; } diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 0df954a942..9a3cb47a44 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -387,7 +387,7 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction &tran CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); 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, diff --git a/src/test/bip39_tests.cpp b/src/test/bip39_tests.cpp index 186c415d9f..fed0e8a893 100644 --- a/src/test/bip39_tests.cpp +++ b/src/test/bip39_tests.cpp @@ -54,7 +54,7 @@ BOOST_AUTO_TEST_CASE(bip39_vectors) CExtKey key; CExtPubKey pubkey; - key.SetMaster(&seed[0], 64); + key.SetMaster(seed.data(), 64); pubkey = key.Neuter(); CBitcoinExtKey b58key;