return EVP_CIPHER_CTX_block_size(CMAC_CTX_get0_cipher_ctx(macctx->ctx));
}
-static int cmac_init(void *vmacctx)
+static int cmac_setkey(struct cmac_data_st *macctx,
+ const unsigned char *key, size_t keylen)
+{
+ int rv = CMAC_Init(macctx->ctx, key, keylen,
+ ossl_prov_cipher_cipher(&macctx->cipher),
+ ossl_prov_cipher_engine(&macctx->cipher));
+ ossl_prov_cipher_reset(&macctx->cipher);
+ return rv;
+}
+
+static int cmac_init(void *vmacctx, const unsigned char *key,
+ size_t keylen, const OSSL_PARAM params[])
{
struct cmac_data_st *macctx = vmacctx;
- int rv;
- if (!ossl_prov_is_running())
+ if (!ossl_prov_is_running() || !cmac_set_ctx_params(macctx, params))
return 0;
-
- rv = CMAC_Init(macctx->ctx, NULL, 0,
- ossl_prov_cipher_cipher(&macctx->cipher),
- ossl_prov_cipher_engine(&macctx->cipher));
-
- ossl_prov_cipher_reset(&macctx->cipher);
- return rv;
+ if (key != NULL)
+ return cmac_setkey(macctx, key, keylen);
+ return 1;
}
static int cmac_update(void *vmacctx, const unsigned char *data,
if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_KEY)) != NULL) {
if (p->data_type != OSSL_PARAM_OCTET_STRING)
return 0;
-
- if (!CMAC_Init(macctx->ctx, p->data, p->data_size,
- ossl_prov_cipher_cipher(&macctx->cipher),
- ossl_prov_cipher_engine(&macctx->cipher)))
- return 0;
-
- ossl_prov_cipher_reset(&macctx->cipher);
+ return cmac_setkey(macctx, p->data, p->data_size);
}
return 1;
}