aboutsummaryrefslogtreecommitdiff
path: root/providers/implementations/macs
diff options
context:
space:
mode:
authorTomas Mraz <tomas@openssl.org>2022-10-12 11:30:56 +0200
committerTomas Mraz <tomas@openssl.org>2022-11-11 16:56:37 +0100
commitd90a4c7d5a18300153340a6d54e7aba03eebe268 (patch)
treefbb3ac2b281f33b122a9c086f157718c9cb713ea /providers/implementations/macs
parent66c4f141369f29b61159a9f77e33e15b9d1c6638 (diff)
downloadopenssl-d90a4c7d5a18300153340a6d54e7aba03eebe268.zip
openssl-d90a4c7d5a18300153340a6d54e7aba03eebe268.tar.gz
openssl-d90a4c7d5a18300153340a6d54e7aba03eebe268.tar.bz2
cmac_set_ctx_params(): Fail if cipher mode is not CBC
Also add negative test cases for CMAC and GMAC using a cipher with wrong mode. Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/19401) (cherry picked from commit 94976a1e8d9b127999df14c2e0c38e918c2badda)
Diffstat (limited to 'providers/implementations/macs')
-rw-r--r--providers/implementations/macs/cmac_prov.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/providers/implementations/macs/cmac_prov.c b/providers/implementations/macs/cmac_prov.c
index 96da429..fc9f911 100644
--- a/providers/implementations/macs/cmac_prov.c
+++ b/providers/implementations/macs/cmac_prov.c
@@ -18,6 +18,8 @@
#include <openssl/params.h>
#include <openssl/evp.h>
#include <openssl/cmac.h>
+#include <openssl/err.h>
+#include <openssl/proverr.h>
#include "prov/implementations.h"
#include "prov/provider_ctx.h"
@@ -195,8 +197,16 @@ static int cmac_set_ctx_params(void *vmacctx, const OSSL_PARAM params[])
if (params == NULL)
return 1;
- if (!ossl_prov_cipher_load_from_params(&macctx->cipher, params, ctx))
- return 0;
+ if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_CIPHER)) != NULL) {
+ if (!ossl_prov_cipher_load_from_params(&macctx->cipher, params, ctx))
+ return 0;
+
+ if (EVP_CIPHER_get_mode(ossl_prov_cipher_cipher(&macctx->cipher))
+ != EVP_CIPH_CBC_MODE) {
+ ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_MODE);
+ return 0;
+ }
+ }
if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_KEY)) != NULL) {
if (p->data_type != OSSL_PARAM_OCTET_STRING)