From 35c14c786e4cc7e20ac5b551819db005cfed295a Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Fri, 16 Dec 2016 22:11:16 -0500 Subject: Fix clang-analyzer warning in AES code The previous assert had been already put there for the benefit of clang-analyzer, but in Clang 3.9 it does not help. Instead test X value directly, which works. --- src/lib/block/aes/aes.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/lib/block') diff --git a/src/lib/block/aes/aes.cpp b/src/lib/block/aes/aes.cpp index 8c7000135..f0e66bc1b 100644 --- a/src/lib/block/aes/aes.cpp +++ b/src/lib/block/aes/aes.cpp @@ -345,12 +345,6 @@ void aes_key_schedule(const byte key[], size_t length, secure_vector& ME, secure_vector& MD) { - - // if length is < 4, X = 0, the first for loop is not entered and in - // the second for loop "RC[(i-X)/X]" = division by zero - // But obviously valid aes length values are only 16, 24 and 32 - BOTAN_ASSERT( length >= 4, "aes key length has valid size" ); - static const u32bit RC[10] = { 0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000, 0x20000000, 0x40000000, 0x80000000, 0x1B000000, 0x36000000 }; @@ -360,6 +354,10 @@ void aes_key_schedule(const byte key[], size_t length, secure_vector XEK(length + 32), XDK(length + 32); const size_t X = length / 4; + + // Make clang-analyzer happy + BOTAN_ASSERT(X == 4 || X == 6 || X == 8, "Valid AES key size"); + for(size_t i = 0; i != X; ++i) XEK[i] = load_be(key, i); -- cgit v1.2.3