diff --git a/src/bip39.cpp b/src/bip39.cpp index 2134f98dec..61c19bdbd6 100644 --- a/src/bip39.cpp +++ b/src/bip39.cpp @@ -147,11 +147,11 @@ bool CMnemonic::Check(SecureString mnemonic) return fResult; } -// passphrase must be at most 256 characters or code may crash +// passphrase must be at most 256 characters otherwise it would be truncated void CMnemonic::ToSeed(SecureString mnemonic, SecureString passphrase, SecureVector& seedRet) { SecureString ssSalt = SecureString("mnemonic") + passphrase; - SecureVector vchSalt(ssSalt.begin(), ssSalt.end()); + SecureVector vchSalt(ssSalt.begin(), ssSalt.begin() + strnlen(ssSalt.data(), 256)); seedRet.resize(64); PKCS5_PBKDF2_HMAC_SHA512(mnemonic.c_str(), mnemonic.size(), vchSalt.data(), vchSalt.size(), 2048, 64, seedRet.data()); } diff --git a/src/bip39.h b/src/bip39.h index 9c6426b244..30f3a6880e 100644 --- a/src/bip39.h +++ b/src/bip39.h @@ -32,7 +32,7 @@ public: static SecureString Generate(int strength); // strength in bits static SecureString FromData(const SecureVector& data, int len); static bool Check(SecureString mnemonic); - // passphrase must be at most 256 characters or code may crash + // passphrase must be at most 256 characters otherwise it would be truncated static void ToSeed(SecureString mnemonic, SecureString passphrase, SecureVector& seedRet); };