aboutsummaryrefslogtreecommitdiff
path: root/crypto/cmac/cmac.c
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2020-05-27 11:37:39 +0100
committerMatt Caswell <matt@openssl.org>2020-06-10 12:58:26 +0100
commitb896d9436d69c67f9d10ffcc8aed15db42c08766 (patch)
treece4a86124c05c3d1bce880aa4977ce605d88cf04 /crypto/cmac/cmac.c
parent317ffa576bc6d0eacec310f50f951c5d895c802e (diff)
downloadopenssl-b896d9436d69c67f9d10ffcc8aed15db42c08766.zip
openssl-b896d9436d69c67f9d10ffcc8aed15db42c08766.tar.gz
openssl-b896d9436d69c67f9d10ffcc8aed15db42c08766.tar.bz2
Ensure we never use a partially initialised CMAC_CTX
If the CMAC_CTX is partially initialised then we make a note of this so that future operations will fail if the initialisation has not been completed. Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/11972)
Diffstat (limited to 'crypto/cmac/cmac.c')
-rw-r--r--crypto/cmac/cmac.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/crypto/cmac/cmac.c b/crypto/cmac/cmac.c
index 7f55c46..ffe2847 100644
--- a/crypto/cmac/cmac.c
+++ b/crypto/cmac/cmac.c
@@ -125,12 +125,18 @@ int CMAC_Init(CMAC_CTX *ctx, const void *key, size_t keylen,
return 1;
}
/* Initialise context */
- if (cipher && !EVP_EncryptInit_ex(ctx->cctx, cipher, impl, NULL, NULL))
- return 0;
+ if (cipher != NULL) {
+ /* Ensure we can't use this ctx until we also have a key */
+ ctx->nlast_block = -1;
+ if (!EVP_EncryptInit_ex(ctx->cctx, cipher, impl, NULL, NULL))
+ return 0;
+ }
/* Non-NULL key means initialisation complete */
- if (key) {
+ if (key != NULL) {
int bl;
+ /* If anything fails then ensure we can't use this ctx */
+ ctx->nlast_block = -1;
if (!EVP_CIPHER_CTX_cipher(ctx->cctx))
return 0;
if (!EVP_CIPHER_CTX_set_key_length(ctx->cctx, keylen))