From da029bead896b5bbae1fb0d66999220cbe4fd055 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Thu, 31 Aug 2017 13:15:28 -0500 Subject: [PATCH] unit: Use overlapped in/out buffers Since aes_wrap & aes_unwrap advertise support for overlapped in/out buffers, make sure that the unit test actually tests this as well. valgrind will complain if the memory is overlapped and memcpy is used instead of memmove. --- unit/test-crypto.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/unit/test-crypto.c b/unit/test-crypto.c index e5091afd..925330ab 100644 --- a/unit/test-crypto.c +++ b/unit/test-crypto.c @@ -351,18 +351,18 @@ static void aes_wrap_test(const void *data) 0xae, 0xf3, 0x4b, 0xd8, 0xfb, 0x5a, 0x7b, 0x82, 0x9d, 0x3e, 0x86, 0x23, 0x71, 0xd2, 0xcf, 0xe5, }; - uint8_t out[24]; + uint8_t buf[24]; - memset(out, 0, 24); + memcpy(buf, key_data, sizeof(key_data)); + assert(aes_wrap(kek, buf, sizeof(key_data), buf)); + assert(!memcmp(buf, ciphertext, sizeof(ciphertext))); - assert(aes_wrap(kek, key_data, sizeof(key_data), out)); - assert(!memcmp(out, ciphertext, sizeof(ciphertext))); + buf[10] = 10; + assert(!aes_unwrap(kek, buf, sizeof(ciphertext), buf)); - out[10] = 10; - assert(!aes_unwrap(kek, out, sizeof(ciphertext), out)); - - assert(aes_unwrap(kek, ciphertext, sizeof(ciphertext), out)); - assert(!memcmp(out, key_data, sizeof(key_data))); + memcpy(buf, ciphertext, sizeof(ciphertext)); + assert(aes_unwrap(kek, buf, sizeof(ciphertext), buf)); + assert(!memcmp(buf, key_data, sizeof(key_data))); } int main(int argc, char *argv[])