X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fcrypter.cpp;h=3a7f997acce0f1ed61217f54bf1f6b5adca41280;hb=5f487b1f0242499f67a4adf48d888ebf4731b7ed;hp=2501305edc2b3ba55b9f08fe0b2a8c9b9d6165cf;hpb=66116c3847eeb3f0619bc084d96f5add41a156c8;p=novacoin.git diff --git a/src/crypter.cpp b/src/crypter.cpp index 2501305..3a7f997 100644 --- a/src/crypter.cpp +++ b/src/crypter.cpp @@ -6,35 +6,40 @@ #include #include #include -#include "headers.h" #ifdef WIN32 #include #endif #include "crypter.h" -#include "main.h" -#include "util.h" +#include "scrypt.h" bool CCrypter::SetKeyFromPassphrase(const SecureString& strKeyData, const std::vector& chSalt, const unsigned int nRounds, const unsigned int nDerivationMethod) { if (nRounds < 1 || chSalt.size() != WALLET_CRYPTO_SALT_SIZE) return false; - // Try to keep the keydata out of swap (and be a bit over-careful to keep the IV that we don't even use out of swap) - // Note that this does nothing about suspend-to-disk (which will put all our key data on disk) - // Note as well that at no point in this program is any attempt made to prevent stealing of keys by reading the memory of the running process. - mlock(&chKey[0], sizeof chKey); - mlock(&chIV[0], sizeof chIV); - int i = 0; if (nDerivationMethod == 0) + { i = EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha512(), &chSalt[0], (unsigned char *)&strKeyData[0], strKeyData.size(), nRounds, chKey, chIV); + } + + if (nDerivationMethod == 1) + { + // Passphrase conversion + uint256 scryptHash = scrypt_salted_multiround_hash((const void*)strKeyData.c_str(), strKeyData.size(), &chSalt[0], 8, nRounds); + + i = EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha512(), &chSalt[0], + (unsigned char *)&scryptHash, sizeof scryptHash, nRounds, chKey, chIV); + OPENSSL_cleanse(&scryptHash, sizeof scryptHash); + } + if (i != (int)WALLET_CRYPTO_KEY_SIZE) { - memset(&chKey, 0, sizeof chKey); - memset(&chIV, 0, sizeof chIV); + OPENSSL_cleanse(&chKey, sizeof chKey); + OPENSSL_cleanse(&chIV, sizeof chIV); return false; } @@ -47,12 +52,6 @@ bool CCrypter::SetKey(const CKeyingMaterial& chNewKey, const std::vector