From 31a1862b80a06d01c8037e61cb1ced7f70b0b3f0 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Fri, 18 Nov 2016 09:00:35 +0800 Subject: [PATCH] decrypt function updated --- src/tools.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/tools.cpp b/src/tools.cpp index a123280..e889274 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -796,12 +796,17 @@ namespace xmreg const size_t prefix_size = sizeof(chacha8_iv) + (authenticated ? sizeof(crypto::signature) : 0); + if (ciphertext.size() < prefix_size) + { + cerr << "Unexpected ciphertext size" << endl; + return {}; + } 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() - prefix_size); @@ -813,6 +818,11 @@ namespace xmreg crypto::public_key pkey; crypto::secret_key_to_public_key(skey, pkey); + const crypto::signature &signature = + *(const crypto::signature*)&ciphertext[ciphertext.size() + - sizeof(crypto::signature)]; + + const crypto::signature &signature = *(const crypto::signature*)&ciphertext[ciphertext.size() - sizeof(crypto::signature)];