#include "internal/provider_algs.h"
#include "internal/provider_ctx.h"
+#include "internal/provider_util.h"
/*
* Forward declaration of everything implemented here. This is not strictly
struct cmac_data_st {
void *provctx;
CMAC_CTX *ctx;
-
- /*
- * References to the underlying cipher implementation. tmpcipher
- * caches the cipher, always. alloc_cipher only holds a reference
- * to an explicitly fetched cipher.
- * tmpcipher is cleared after a CMAC_Init call.
- */
- const EVP_CIPHER *tmpcipher; /* cached CMAC cipher */
- EVP_CIPHER *alloc_cipher; /* fetched CMAC cipher */
-
- /*
- * Conditions for legacy EVP_CIPHER uses.
- * tmpengine is cleared after a CMAC_Init call.
- */
- ENGINE *tmpengine; /* CMAC cipher engine (legacy) */
+ PROV_CIPHER cipher;
};
static void *cmac_new(void *provctx)
if (macctx != NULL) {
CMAC_CTX_free(macctx->ctx);
- EVP_CIPHER_free(macctx->alloc_cipher);
+ ossl_prov_cipher_reset(&macctx->cipher);
OPENSSL_free(macctx);
}
}
struct cmac_data_st *src = vsrc;
struct cmac_data_st *dst = cmac_new(src->provctx);
- if (!CMAC_CTX_copy(dst->ctx, src->ctx)) {
+ if (!CMAC_CTX_copy(dst->ctx, src->ctx)
+ || !ossl_prov_cipher_copy(&dst->cipher, &src->cipher)) {
cmac_free(dst);
return NULL;
}
-
- if (src->alloc_cipher != NULL && !EVP_CIPHER_up_ref(src->alloc_cipher)) {
- cmac_free(dst);
- return NULL;
- }
-
- dst->tmpengine = src->tmpengine;
- dst->tmpcipher = src->tmpcipher;
- dst->alloc_cipher = src->alloc_cipher;
return dst;
}
static int cmac_init(void *vmacctx)
{
struct cmac_data_st *macctx = vmacctx;
- int rv = CMAC_Init(macctx->ctx, NULL, 0, macctx->tmpcipher,
- (ENGINE *)macctx->tmpengine);
-
- macctx->tmpcipher = NULL;
- macctx->tmpengine = NULL;
+ int 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;
}
static int cmac_set_ctx_params(void *vmacctx, const OSSL_PARAM params[])
{
struct cmac_data_st *macctx = vmacctx;
+ OPENSSL_CTX *ctx = PROV_LIBRARY_CONTEXT_OF(macctx->provctx);
const OSSL_PARAM *p;
- if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_CIPHER)) != NULL) {
- if (p->data_type != OSSL_PARAM_UTF8_STRING)
- return 0;
-
- {
- const char *algoname = p->data;
- const char *propquery = NULL;
-
-/* Inside the FIPS module, we don't support engines */
-#if !defined(FIPS_MODE) && !defined(OPENSSL_NO_ENGINE)
- ENGINE_finish(macctx->tmpengine);
- macctx->tmpengine = NULL;
-
- if ((p = OSSL_PARAM_locate_const(params, OSSL_MAC_PARAM_ENGINE))
- != NULL) {
- if (p->data_type != OSSL_PARAM_UTF8_STRING)
- return 0;
-
- macctx->tmpengine = ENGINE_by_id(p->data);
- if (macctx->tmpengine == NULL)
- return 0;
- }
-#endif
- if ((p = OSSL_PARAM_locate_const(params,
- OSSL_MAC_PARAM_PROPERTIES))
- != NULL) {
- if (p->data_type != OSSL_PARAM_UTF8_STRING)
- return 0;
-
- propquery = p->data;
- }
+ if (!ossl_prov_cipher_load_from_params(&macctx->cipher, params, ctx))
+ return 0;
- EVP_CIPHER_free(macctx->alloc_cipher);
-
- macctx->tmpcipher = macctx->alloc_cipher =
- EVP_CIPHER_fetch(PROV_LIBRARY_CONTEXT_OF(macctx->provctx),
- algoname, propquery);
-
-#ifndef FIPS_MODE /* Inside the FIPS module, we don't support legacy digests */
- /* TODO(3.0) BEGIN legacy stuff, to be removed */
- if (macctx->tmpcipher == NULL)
- macctx->tmpcipher = EVP_get_cipherbyname(algoname);
- /* TODO(3.0) END of legacy stuff */
-#endif
-
- if (macctx->tmpcipher == NULL)
- return 0;
- }
- }
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,
- macctx->tmpcipher, macctx->tmpengine))
+ ossl_prov_cipher_cipher(&macctx->cipher),
+ ossl_prov_cipher_engine(&macctx->cipher)))
return 0;
- macctx->tmpcipher = NULL;
- macctx->tmpengine = NULL;
+ ossl_prov_cipher_reset(&macctx->cipher);
}
return 1;
}