diff options
author | Riccardo Spagni <ric@spagni.net> | 2016-11-24 12:52:54 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2016-11-24 12:52:54 +0200 |
commit | 2121f3b2f0905c0638dfd37123131f30aecbe6c3 (patch) | |
tree | 1e018aae5718cdd68f18fe2d61b3814336109e7c | |
parent | Merge pull request #1197 (diff) | |
parent | wallet2: fix decrypting a bit too much in authenticated mode (diff) | |
download | monero-2121f3b2f0905c0638dfd37123131f30aecbe6c3.tar.xz |
Merge pull request #1351
e6264a2 wallet2: fix decrypting a bit too much in authenticated mode (moneromooo-monero)
-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 57a9cff99..597c56ff3 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -4915,14 +4915,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; @@ -4933,7 +4934,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); } //---------------------------------------------------------------------------------------------------- |