prov: update gmac to have additional init arguments
@@ -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,6 +207,8 @@ 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 (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;
