Skip to content

Commit

Permalink
Check that we have enough padding characters.
Browse files Browse the repository at this point in the history
Reviewed-by: Emilia Käsper <emilia@openssl.org>

CVE-2016-2107

MR: #2572
  • Loading branch information
kroeckx authored and mattcaswell committed May 3, 2016
1 parent 643e8e9 commit 68595c0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crypto/evp/e_aes_cbc_hmac_sha1.c
Expand Up @@ -60,6 +60,7 @@
# include <openssl/sha.h> # include <openssl/sha.h>
# include <openssl/rand.h> # include <openssl/rand.h>
# include "modes_lcl.h" # include "modes_lcl.h"
# include "constant_time_locl.h"


# ifndef EVP_CIPH_FLAG_AEAD_CIPHER # ifndef EVP_CIPH_FLAG_AEAD_CIPHER
# define EVP_CIPH_FLAG_AEAD_CIPHER 0x200000 # define EVP_CIPH_FLAG_AEAD_CIPHER 0x200000
Expand Down Expand Up @@ -578,6 +579,8 @@ static int aesni_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
maxpad |= (255 - maxpad) >> (sizeof(maxpad) * 8 - 8); maxpad |= (255 - maxpad) >> (sizeof(maxpad) * 8 - 8);
maxpad &= 255; maxpad &= 255;


ret &= constant_time_ge(maxpad, pad);

inp_len = len - (SHA_DIGEST_LENGTH + pad + 1); inp_len = len - (SHA_DIGEST_LENGTH + pad + 1);
mask = (0 - ((inp_len - len) >> (sizeof(inp_len) * 8 - 1))); mask = (0 - ((inp_len - len) >> (sizeof(inp_len) * 8 - 1)));
inp_len &= mask; inp_len &= mask;
Expand Down
3 changes: 3 additions & 0 deletions crypto/evp/e_aes_cbc_hmac_sha256.c
Expand Up @@ -60,6 +60,7 @@
# include <openssl/sha.h> # include <openssl/sha.h>
# include <openssl/rand.h> # include <openssl/rand.h>
# include "modes_lcl.h" # include "modes_lcl.h"
# include "constant_time_locl.h"


# ifndef EVP_CIPH_FLAG_AEAD_CIPHER # ifndef EVP_CIPH_FLAG_AEAD_CIPHER
# define EVP_CIPH_FLAG_AEAD_CIPHER 0x200000 # define EVP_CIPH_FLAG_AEAD_CIPHER 0x200000
Expand Down Expand Up @@ -589,6 +590,8 @@ static int aesni_cbc_hmac_sha256_cipher(EVP_CIPHER_CTX *ctx,
maxpad |= (255 - maxpad) >> (sizeof(maxpad) * 8 - 8); maxpad |= (255 - maxpad) >> (sizeof(maxpad) * 8 - 8);
maxpad &= 255; maxpad &= 255;


ret &= constant_time_ge(maxpad, pad);

inp_len = len - (SHA256_DIGEST_LENGTH + pad + 1); inp_len = len - (SHA256_DIGEST_LENGTH + pad + 1);
mask = (0 - ((inp_len - len) >> (sizeof(inp_len) * 8 - 1))); mask = (0 - ((inp_len - len) >> (sizeof(inp_len) * 8 - 1)));
inp_len &= mask; inp_len &= mask;
Expand Down

0 comments on commit 68595c0

Please sign in to comment.