diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2016-11-17 20:21:11 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2016-11-17 20:31:00 +0000 |
commit | e6264a2c359a0b6dc946034e7025af327d4623b4 (patch) | |
tree | 02fedc986345c87f7ad45d9988c6b55e1abf8132 /src | |
parent | Merge pull request #1346 (diff) | |
download | monero-e6264a2c359a0b6dc946034e7025af327d4623b4.tar.xz |
wallet2: fix decrypting a bit too much in authenticated mode
Diffstat (limited to 'src')
-rw-r--r-- | src/wallet/wallet2.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 15a134257..e48c78123 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -4889,14 +4889,15 @@ std::string wallet2::encrypt_with_view_secret_key(const std::string &plaintext, //---------------------------------------------------------------------------------------------------- std::string wallet2::decrypt(const std::string &ciphertext, const crypto::secret_key &skey, bool authenticated) const { - THROW_WALLET_EXCEPTION_IF(ciphertext.size() < sizeof(chacha8_iv), - error::wallet_internal_error, "key_image generated ephemeral public key not matched with output_key"); + const size_t prefix_size = sizeof(chacha8_iv) + (authenticated ? sizeof(crypto::signature) : 0); + THROW_WALLET_EXCEPTION_IF(ciphertext.size() < prefix_size, + error::wallet_internal_error, "Unexpected ciphertext size"); crypto::chacha8_key key; crypto::generate_chacha8_key(&skey, sizeof(skey), key); const crypto::chacha8_iv &iv = *(const crypto::chacha8_iv*)&ciphertext[0]; std::string plaintext; - plaintext.resize(ciphertext.size() - sizeof(iv) - (authenticated ? sizeof(crypto::signature) : 0)); + plaintext.resize(ciphertext.size() - prefix_size); if (authenticated) { crypto::hash hash; @@ -4907,7 +4908,7 @@ std::string wallet2::decrypt(const std::string &ciphertext, const crypto::secret THROW_WALLET_EXCEPTION_IF(!crypto::check_signature(hash, pkey, signature), error::wallet_internal_error, "Failed to authenticate criphertext"); } - crypto::chacha8(ciphertext.data() + sizeof(iv), ciphertext.size() - sizeof(iv), key, iv, &plaintext[0]); + crypto::chacha8(ciphertext.data() + sizeof(iv), ciphertext.size() - prefix_size, key, iv, &plaintext[0]); return std::move(plaintext); } //---------------------------------------------------------------------------------------------------- |