diff options
author | Jack Lloyd <[email protected]> | 2018-11-17 14:54:21 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-11-17 22:50:26 -0500 |
commit | 432d31546eb335bb96c6b2a8c58f0168266387ec (patch) | |
tree | 2397468c243906a08eea08b9376a9922346e6856 /src/tests | |
parent | 6b3a827fb493ad884c7443092ba8f9967636b3c8 (diff) |
Avoid calling memset, memcpy within library code
Prefer using wrappers in mem_utils for this.
Current exception is where memcpy is being used to convert between
two different types, since copy_mem requires input and output
pointers have the same type. There should be a new function to
handle conversion-via-memcpy operation.
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/test_block.cpp | 4 | ||||
-rw-r--r-- | src/tests/test_rng.h | 7 | ||||
-rw-r--r-- | src/tests/test_tls.cpp | 7 | ||||
-rw-r--r-- | src/tests/test_utils.cpp | 3 |
4 files changed, 14 insertions, 7 deletions
diff --git a/src/tests/test_block.cpp b/src/tests/test_block.cpp index a53ff2633..ceda8ca07 100644 --- a/src/tests/test_block.cpp +++ b/src/tests/test_block.cpp @@ -137,7 +137,7 @@ class Block_Cipher_Tests final : public Text_Based_Test // Now test misaligned buffers const size_t blocks = input.size() / cipher->block_size(); buf.resize(input.size() + 1); - std::memcpy(buf.data() + 1, input.data(), input.size()); + Botan::copy_mem(buf.data() + 1, input.data(), input.size()); for(size_t i = 0; i != iterations; ++i) { @@ -149,7 +149,7 @@ class Block_Cipher_Tests final : public Text_Based_Test expected.data(), expected.size()); // always decrypt expected ciphertext vs what we produced above - std::memcpy(buf.data() + 1, expected.data(), expected.size()); + Botan::copy_mem(buf.data() + 1, expected.data(), expected.size()); for(size_t i = 0; i != iterations; ++i) { diff --git a/src/tests/test_rng.h b/src/tests/test_rng.h index 37501da2e..822536971 100644 --- a/src/tests/test_rng.h +++ b/src/tests/test_rng.h @@ -212,7 +212,12 @@ class Request_Counting_RNG final : public Botan::RandomNumberGenerator void randomize(uint8_t out[], size_t out_len) override { - std::memset(out, 0x80, out_len); + /* + The HMAC_DRBG and ChaCha reseed KATs assume this RNG type + outputs all 0x80 + */ + for(size_t i = 0; i != out_len; ++i) + out[i] = 0x80; m_randomize_count++; } diff --git a/src/tests/test_tls.cpp b/src/tests/test_tls.cpp index af13a83b8..8a327b652 100644 --- a/src/tests/test_tls.cpp +++ b/src/tests/test_tls.cpp @@ -110,7 +110,8 @@ class TLS_CBC_Tests final : public Text_Based_Test void final_result(uint8_t out[]) override { - std::memset(out, 0, m_mac_len); + for(size_t i = 0; i != m_mac_len; ++i) + out[i] = 0; } Botan::Key_Length_Specification key_spec() const override @@ -133,12 +134,12 @@ class TLS_CBC_Tests final : public Text_Based_Test void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override { - std::memmove(out, in, blocks * m_bs); + Botan::copy_mem(out, in, blocks * m_bs); } void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override { - std::memmove(out, in, blocks * m_bs); + Botan::copy_mem(out, in, blocks * m_bs); } size_t block_size() const override { return m_bs; } diff --git a/src/tests/test_utils.cpp b/src/tests/test_utils.cpp index b6eb4bbc7..7bbe3745c 100644 --- a/src/tests/test_utils.cpp +++ b/src/tests/test_utils.cpp @@ -843,7 +843,8 @@ class UUID_Tests : public Test void randomize(uint8_t out[], size_t len) override { - std::memset(out, m_val, len); + for(size_t i = 0; i != len; ++i) + out[i] = m_val; } std::string name() const override { return "zeros"; } |