Check that we have enough padding characters.
[openssl.git] / crypto / evp / e_aes_cbc_hmac_sha256.c
index 956cd58a05005cb7e9c3297c957f70f887529069..3ac59abc34da8b34ad76fed3605e5f9d7d59f792 100644 (file)
@@ -59,6 +59,7 @@
 #include <openssl/sha.h>
 #include <openssl/rand.h>
 #include "modes_lcl.h"
 #include <openssl/sha.h>
 #include <openssl/rand.h>
 #include "modes_lcl.h"
+#include "internal/constant_time_locl.h"
 #include "internal/evp_int.h"
 
 #ifndef EVP_CIPH_FLAG_AEAD_CIPHER
 #include "internal/evp_int.h"
 
 #ifndef EVP_CIPH_FLAG_AEAD_CIPHER
@@ -594,6 +595,8 @@ static int aesni_cbc_hmac_sha256_cipher(EVP_CIPHER_CTX *ctx,
             maxpad |= (255 - maxpad) >> (sizeof(maxpad) * 8 - 8);
             maxpad &= 255;
 
             maxpad |= (255 - maxpad) >> (sizeof(maxpad) * 8 - 8);
             maxpad &= 255;
 
+            ret &= constant_time_ge(maxpad, pad);
+
             inp_len = len - (SHA256_DIGEST_LENGTH + pad + 1);
             mask = (0 - ((inp_len - len) >> (sizeof(inp_len) * 8 - 1)));
             inp_len &= mask;
             inp_len = len - (SHA256_DIGEST_LENGTH + pad + 1);
             mask = (0 - ((inp_len - len) >> (sizeof(inp_len) * 8 - 1)));
             inp_len &= mask;