Move gcm decryption tag check higher up in the callstack
authorShane Lontis <shane.lontis@oracle.com>
Thu, 19 Sep 2019 08:40:07 +0000 (18:40 +1000)
committerShane Lontis <shane.lontis@oracle.com>
Fri, 20 Sep 2019 02:25:28 +0000 (12:25 +1000)
Code was updated for s390 that accidently removed the check inside the final method.
Moving the check up before the final method is called is a better way of handling this.
The oneshot method also calls the final method but doesnt need to do this check.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9945)

providers/common/ciphers/cipher_gcm.c
providers/common/ciphers/cipher_gcm_hw.c

index 9a61eabdfc546f95b5b43ce072edf78b87f18b3a..b5c79daee747f57c41030be10347aa28b8c89e72 100644 (file)
@@ -344,7 +344,9 @@ static int gcm_cipher_internal(PROV_GCM_CTX *ctx, unsigned char *out,
                 goto err;
         }
     } else {
-        /* Finished when in == NULL */
+        /* The tag must be set before actually decrypting data */
+        if (!ctx->enc && ctx->taglen == UNINITIALISED_SIZET)
+            goto err;
         if (!hw->cipherfinal(ctx, ctx->buf))
             goto err;
         ctx->iv_state = IV_STATE_FINISHED; /* Don't reuse the IV */
index e2587f2e5e3529fd64216ef1559e3091bcbc138c..8b2913c695cab39a5a3e870b40a50c9d375bae0a 100644 (file)
@@ -90,8 +90,7 @@ int gcm_cipher_final(PROV_GCM_CTX *ctx, unsigned char *tag)
         CRYPTO_gcm128_tag(&ctx->gcm, tag, GCM_TAG_MAX_SIZE);
         ctx->taglen = GCM_TAG_MAX_SIZE;
     } else {
-        if (ctx->taglen == UNINITIALISED_SIZET
-            || CRYPTO_gcm128_finish(&ctx->gcm, tag, ctx->taglen) != 0)
+        if (CRYPTO_gcm128_finish(&ctx->gcm, tag, ctx->taglen) != 0)
             return 0;
     }
     return 1;