From 9fa352282f7550b1226e819c458005375d77f11b Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Wed, 9 Nov 2016 14:18:11 -0500 Subject: Check missing Pipe::read return values --- src/lib/misc/aont/package.cpp | 6 ++++-- src/lib/misc/cryptobox/cryptobox.cpp | 12 ++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/lib/misc/aont/package.cpp b/src/lib/misc/aont/package.cpp index a3be898d8..cec07d298 100644 --- a/src/lib/misc/aont/package.cpp +++ b/src/lib/misc/aont/package.cpp @@ -31,7 +31,8 @@ void aont_package(RandomNumberGenerator& rng, Pipe pipe(new StreamCipher_Filter(new CTR_BE(cipher), package_key)); pipe.process_msg(input, input_len); - pipe.read(output, pipe.remaining()); + const size_t remaining = pipe.remaining(); + BOTAN_ASSERT_EQUAL(remaining, pipe.read(output, remaining), "Expected read size"); // Set K0 (the all zero key) cipher->set_key(SymmetricKey(all_zeros)); @@ -113,7 +114,8 @@ void aont_unpackage(BlockCipher* cipher, pipe.process_msg(input, input_len - BLOCK_SIZE); - pipe.read(output, pipe.remaining()); + const size_t remaining = pipe.remaining(); + BOTAN_ASSERT_EQUAL(remaining, pipe.read(output, remaining), "Expected read size"); } } diff --git a/src/lib/misc/cryptobox/cryptobox.cpp b/src/lib/misc/cryptobox/cryptobox.cpp index c0fc9b777..95cdda149 100644 --- a/src/lib/misc/cryptobox/cryptobox.cpp +++ b/src/lib/misc/cryptobox/cryptobox.cpp @@ -88,9 +88,13 @@ std::string encrypt(const byte input[], size_t input_len, copy_mem(&out_buf[VERSION_CODE_LEN], pbkdf_salt.data(), PBKDF_SALT_LEN); - pipe.read(&out_buf[VERSION_CODE_LEN + PBKDF_SALT_LEN], MAC_OUTPUT_LEN, 1); - pipe.read(&out_buf[VERSION_CODE_LEN + PBKDF_SALT_LEN + MAC_OUTPUT_LEN], - ciphertext_len, 0); + BOTAN_ASSERT_EQUAL( + pipe.read(&out_buf[VERSION_CODE_LEN + PBKDF_SALT_LEN], MAC_OUTPUT_LEN, 1), + MAC_OUTPUT_LEN, "MAC output"); + BOTAN_ASSERT_EQUAL( + pipe.read(&out_buf[VERSION_CODE_LEN + PBKDF_SALT_LEN + MAC_OUTPUT_LEN], + ciphertext_len, 0), + ciphertext_len, "Ciphertext size"); return PEM_Code::encode(out_buf, "BOTAN CRYPTOBOX MESSAGE"); } @@ -139,7 +143,7 @@ std::string decrypt(const byte input[], size_t input_len, ciphertext.size() - ciphertext_offset); byte computed_mac[MAC_OUTPUT_LEN]; - pipe.read(computed_mac, MAC_OUTPUT_LEN, 1); + BOTAN_ASSERT_EQUAL(MAC_OUTPUT_LEN, pipe.read(computed_mac, MAC_OUTPUT_LEN, 1), "MAC size"); if(!same_mem(computed_mac, &ciphertext[VERSION_CODE_LEN + PBKDF_SALT_LEN], -- cgit v1.2.3