aboutsummaryrefslogtreecommitdiff
path: root/providers/implementations/macs
diff options
context:
space:
mode:
authorPauli <ppzgs1@gmail.com>2021-02-25 13:54:13 +1000
committerPauli <ppzgs1@gmail.com>2021-02-28 17:25:49 +1000
commit0a56b3c2e58930e6c6e958bf59a80ef026f6f1b2 (patch)
tree6add2c5ace59929c69d9785e06983dd1fd99b921 /providers/implementations/macs
parent005b190297e1ed7a930a1085b49c95c6f4ad57f7 (diff)
downloadopenssl-0a56b3c2e58930e6c6e958bf59a80ef026f6f1b2.zip
openssl-0a56b3c2e58930e6c6e958bf59a80ef026f6f1b2.tar.gz
openssl-0a56b3c2e58930e6c6e958bf59a80ef026f6f1b2.tar.bz2
prov: update gmac to have additional init arguments
Reviewed-by: Shane Lontis <shane.lontis@oracle.com> (Merged from https://github.com/openssl/openssl/pull/14310)
Diffstat (limited to 'providers/implementations/macs')
-rw-r--r--providers/implementations/macs/gmac_prov.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/providers/implementations/macs/gmac_prov.c b/providers/implementations/macs/gmac_prov.c
index 3a4600b..14ca948 100644
--- a/providers/implementations/macs/gmac_prov.c
+++ b/providers/implementations/macs/gmac_prov.c
@@ -98,9 +98,30 @@ static size_t gmac_size(void)
return EVP_GCM_TLS_TAG_LEN;
}
-static int gmac_init(void *vmacctx)
+static int gmac_setkey(struct gmac_data_st *macctx,
+ const unsigned char *key, size_t keylen)
{
- return ossl_prov_is_running();
+ EVP_CIPHER_CTX *ctx = macctx->ctx;
+
+ if (keylen != (size_t)EVP_CIPHER_CTX_key_length(ctx)) {
+ ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);
+ return 0;
+ }
+ if (!EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL))
+ return 0;
+ return 1;
+}
+
+static int gmac_init(void *vmacctx, const unsigned char *key,
+ size_t keylen, const OSSL_PARAM params[])
+{
+ struct gmac_data_st *macctx = vmacctx;
+
+ if (!ossl_prov_is_running() || !gmac_set_ctx_params(macctx, params))
+ return 0;
+ if (key != NULL)
+ return gmac_setkey(macctx, key, keylen);
+ return 1;
}
static int gmac_update(void *vmacctx, const unsigned char *data,
@@ -186,7 +207,9 @@ static int gmac_set_ctx_params(void *vmacctx, const OSSL_PARAM params[])
OSSL_LIB_CTX *provctx = PROV_LIBCTX_OF(macctx->provctx);
const OSSL_PARAM *p;
- if (ctx == NULL
+ if (params == NULL)
+ return 1;
+ if (ctx == NULL
|| !ossl_prov_cipher_load_from_params(&macctx->cipher, params, provctx))
return 0;
@@ -200,17 +223,11 @@ static int gmac_set_ctx_params(void *vmacctx, const OSSL_PARAM params[])
NULL))
return 0;
- if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_KEY)) != NULL) {
- if (p->data_type != OSSL_PARAM_OCTET_STRING)
+ if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_KEY)) != NULL)
+ if (p->data_type != OSSL_PARAM_OCTET_STRING
+ || !gmac_setkey(macctx, p->data, p->data_size))
return 0;
- if (p->data_size != (size_t)EVP_CIPHER_CTX_key_length(ctx)) {
- ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);
- return 0;
- }
- if (!EVP_EncryptInit_ex(ctx, NULL, NULL, p->data, NULL))
- return 0;
- }
if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_IV)) != NULL) {
if (p->data_type != OSSL_PARAM_OCTET_STRING)
return 0;