static OSSL_FUNC_keymgmt_gen_init_fn mac_gen_init;
static OSSL_FUNC_keymgmt_gen_fn mac_gen;
static OSSL_FUNC_keymgmt_gen_cleanup_fn mac_gen_cleanup;
+static OSSL_FUNC_keymgmt_gen_set_params_fn mac_gen_set_params;
+static OSSL_FUNC_keymgmt_gen_settable_params_fn mac_gen_settable_params;
static OSSL_FUNC_keymgmt_get_params_fn mac_get_params;
static OSSL_FUNC_keymgmt_gettable_params_fn mac_gettable_params;
static OSSL_FUNC_keymgmt_set_params_fn mac_set_params;
static OSSL_FUNC_keymgmt_export_fn mac_export;
static OSSL_FUNC_keymgmt_export_types_fn mac_imexport_types;
+static OSSL_FUNC_keymgmt_new_fn mac_new_cmac;
+static OSSL_FUNC_keymgmt_gettable_params_fn cmac_gettable_params;
+static OSSL_FUNC_keymgmt_import_types_fn cmac_imexport_types;
+static OSSL_FUNC_keymgmt_export_types_fn cmac_imexport_types;
+static OSSL_FUNC_keymgmt_gen_set_params_fn cmac_gen_set_params;
+static OSSL_FUNC_keymgmt_gen_settable_params_fn cmac_gen_settable_params;
+
struct mac_gen_ctx {
- OPENSSL_CTX *libctx;
+ OSSL_LIB_CTX *libctx;
int selection;
unsigned char *priv_key;
size_t priv_key_len;
PROV_CIPHER cipher;
};
-MAC_KEY *mac_key_new(OPENSSL_CTX *libctx, int cmac)
+MAC_KEY *ossl_mac_key_new(OSSL_LIB_CTX *libctx, int cmac)
{
- MAC_KEY *mackey = OPENSSL_zalloc(sizeof(*mackey));
+ MAC_KEY *mackey;
+
+ if (!ossl_prov_is_running())
+ return NULL;
+ mackey = OPENSSL_zalloc(sizeof(*mackey));
if (mackey == NULL)
return NULL;
return mackey;
}
-void mac_key_free(MAC_KEY *mackey)
+void ossl_mac_key_free(MAC_KEY *mackey)
{
int ref = 0;
OPENSSL_free(mackey);
}
-int mac_key_up_ref(MAC_KEY *mackey)
+int ossl_mac_key_up_ref(MAC_KEY *mackey)
{
int ref = 0;
+ /* This is effectively doing a new operation on the MAC_KEY and should be
+ * adequately guarded again modules' error states. However, both current
+ * calls here are guarded propery in signature/mac_legacy.c. Thus, it
+ * could be removed here. The concern is that something in the future
+ * might call this function without adequate guards. It's a cheap call,
+ * it seems best to leave it even though it is currently redundant.
+ */
+ if (!ossl_prov_is_running())
+ return 0;
+
CRYPTO_UP_REF(&mackey->refcnt, &ref, mackey->lock);
return 1;
}
static void *mac_new(void *provctx)
{
- return mac_key_new(PROV_LIBRARY_CONTEXT_OF(provctx), 0);
+ return ossl_mac_key_new(PROV_LIBCTX_OF(provctx), 0);
}
static void *mac_new_cmac(void *provctx)
{
- return mac_key_new(PROV_LIBRARY_CONTEXT_OF(provctx), 1);
+ return ossl_mac_key_new(PROV_LIBCTX_OF(provctx), 1);
}
static void mac_free(void *mackey)
{
- mac_key_free(mackey);
+ ossl_mac_key_free(mackey);
}
-static int mac_has(void *keydata, int selection)
+static int mac_has(const void *keydata, int selection)
{
- MAC_KEY *key = keydata;
+ const MAC_KEY *key = keydata;
int ok = 0;
- if (key != NULL) {
+ if (ossl_prov_is_running() && key != NULL) {
/*
* MAC keys always have all the parameters they need (i.e. none).
* Therefore we always return with 1, if asked about parameters.
const MAC_KEY *key2 = keydata2;
int ok = 1;
+ if (!ossl_prov_is_running())
+ return 0;
+
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) {
if ((key1->priv_key == NULL && key2->priv_key != NULL)
|| (key1->priv_key != NULL && key2->priv_key == NULL)
{
MAC_KEY *key = keydata;
- if (key == NULL)
+ if (!ossl_prov_is_running() || key == NULL)
return 0;
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) == 0)
OSSL_PARAM *params = NULL;
int ret = 0;
- if (key == NULL)
+ if (!ossl_prov_is_running() || key == NULL)
return 0;
tmpl = OSSL_PARAM_BLD_new();
return gettable_params;
}
-
static int mac_set_params(void *keydata, const OSSL_PARAM params[])
{
MAC_KEY *key = keydata;
static void *mac_gen_init(void *provctx, int selection)
{
- OPENSSL_CTX *libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
+ OSSL_LIB_CTX *libctx = PROV_LIBCTX_OF(provctx);
struct mac_gen_ctx *gctx = NULL;
+ if (!ossl_prov_is_running())
+ return NULL;
+
if ((gctx = OPENSSL_zalloc(sizeof(*gctx))) != NULL) {
gctx->libctx = libctx;
gctx->selection = selection;
struct mac_gen_ctx *gctx = genctx;
MAC_KEY *key;
- if (gctx == NULL)
+ if (!ossl_prov_is_running() || gctx == NULL)
return NULL;
- if ((key = mac_key_new(gctx->libctx, 0)) == NULL) {
+ if ((key = ossl_mac_key_new(gctx->libctx, 0)) == NULL) {
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
return NULL;
}
if (gctx->priv_key == NULL) {
ERR_raise(ERR_LIB_PROV, EVP_R_INVALID_KEY);
- mac_key_free(key);
+ ossl_mac_key_free(key);
return NULL;
}
OPENSSL_free(gctx);
}
-const OSSL_DISPATCH mac_keymgmt_functions[] = {
+const OSSL_DISPATCH ossl_mac_legacy_keymgmt_functions[] = {
{ OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))mac_new },
{ OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))mac_free },
{ OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*) (void))mac_get_params },
{ 0, NULL }
};
-const OSSL_DISPATCH cmac_keymgmt_functions[] = {
+const OSSL_DISPATCH ossl_cossl_mac_legacy_keymgmt_functions[] = {
{ OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))mac_new_cmac },
{ OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))mac_free },
{ OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*) (void))mac_get_params },
{ OSSL_FUNC_KEYMGMT_GEN_CLEANUP, (void (*)(void))mac_gen_cleanup },
{ 0, NULL }
};
+