Check that we have enough padding characters.
authorKurt Roeckx <kurt@roeckx.be>
Sat, 16 Apr 2016 21:08:56 +0000 (23:08 +0200)
committerMatt Caswell <matt@openssl.org>
Tue, 3 May 2016 12:15:39 +0000 (13:15 +0100)
Reviewed-by: Emilia Käsper <emilia@openssl.org>
CVE-2016-2107

MR: #2572

crypto/evp/e_aes_cbc_hmac_sha1.c
crypto/evp/e_aes_cbc_hmac_sha256.c

index 394a380aa00f9fcbc237cddf3e96a7d3a4ae290c..2d5131f2842997d2168eb94eb9c16f36270390cb 100644 (file)
@@ -59,6 +59,7 @@
 #include <openssl/rand.h>
 #include "modes_lcl.h"
 #include "internal/evp_int.h"
+#include "internal/constant_time_locl.h"
 
 #ifndef EVP_CIPH_FLAG_AEAD_CIPHER
 # define EVP_CIPH_FLAG_AEAD_CIPHER       0x200000
@@ -583,6 +584,8 @@ static int aesni_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
             maxpad |= (255 - maxpad) >> (sizeof(maxpad) * 8 - 8);
             maxpad &= 255;
 
+            ret &= constant_time_ge(maxpad, pad);
+
             inp_len = len - (SHA_DIGEST_LENGTH + pad + 1);
             mask = (0 - ((inp_len - len) >> (sizeof(inp_len) * 8 - 1)));
             inp_len &= mask;
index 956cd58a05005cb7e9c3297c957f70f887529069..3ac59abc34da8b34ad76fed3605e5f9d7d59f792 100644 (file)
@@ -59,6 +59,7 @@
 #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
@@ -594,6 +595,8 @@ static int aesni_cbc_hmac_sha256_cipher(EVP_CIPHER_CTX *ctx,
             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;