Sanity check lengths for AES wrap algorithm.
authorDr. Stephen Henson <steve@openssl.org>
Thu, 17 Jul 2014 01:50:48 +0000 (02:50 +0100)
committerDr. Stephen Henson <steve@openssl.org>
Thu, 17 Jul 2014 11:58:42 +0000 (12:58 +0100)
Reviewed-by: Tim Hudson <tjh@openssl.org>
(cherry picked from commit d12eef15016e49fc09d6c96653c61624e032d1a3)

crypto/evp/e_aes.c
crypto/modes/wrap128.c

index 8150e02f878949920acf6f936a523384b5d3807c..d20cecaaadedd8138960293631843bd1a54b14e8 100644 (file)
@@ -2076,7 +2076,11 @@ static int aes_wrap_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
        EVP_AES_WRAP_CTX *wctx = ctx->cipher_data;
        size_t rv;
        if (inlen % 8)
-               return 0;
+               return -1;
+       if (ctx->encrypt && inlen < 8)
+               return -1;
+       if (!ctx->encrypt && inlen < 16)
+               return -1;
        if (!out)
                {
                if (ctx->encrypt)
index 18785320f29ffa9a320ff400151f8b5ee58088bd..c6c14cdaaa06b9845947343543a773c6cd8afafa 100644 (file)
@@ -106,7 +106,7 @@ size_t CRYPTO_128_unwrap(void *key, const unsigned char *iv,
        unsigned char *A, B[16], *R;
        size_t i, j, t;
        inlen -= 8;
-       if ((inlen & 0x7) || (inlen < 8) || (inlen > CRYPTO128_WRAP_MAX))
+       if ((inlen & 0x7) || (inlen < 16) || (inlen > CRYPTO128_WRAP_MAX))
                return 0;
        A = B;
        t =  6 * (inlen >> 3);