1 #include <openssl/evp.h>
2 #include <openssl/err.h>
3 #include <openssl/core.h>
4 #include <openssl/core_numbers.h>
5 #include "internal/evp_int.h"
6 #include "internal/provider.h"
9 static int evp_mac_up_ref(void *vmac
)
14 CRYPTO_UP_REF(&mac
->refcnt
, &ref
, mac
->lock
);
18 static void evp_mac_free(void *vmac
)
26 CRYPTO_DOWN_REF(&mac
->refcnt
, &ref
, mac
->lock
);
29 ossl_provider_free(mac
->prov
);
30 OPENSSL_free(mac
->name
);
31 CRYPTO_THREAD_lock_free(mac
->lock
);
35 static void *evp_mac_new(void)
39 if ((mac
= OPENSSL_zalloc(sizeof(*mac
))) == NULL
40 || (mac
->lock
= CRYPTO_THREAD_lock_new()) == NULL
) {
50 static void *evp_mac_from_dispatch(const char *name
, const OSSL_DISPATCH
*fns
,
54 int fnmaccnt
= 0, fnctxcnt
= 0;
56 if ((mac
= evp_mac_new()) == NULL
57 || (mac
->name
= OPENSSL_strdup(name
)) == NULL
) {
59 EVPerr(0, ERR_R_MALLOC_FAILURE
);
63 for (; fns
->function_id
!= 0; fns
++) {
64 switch (fns
->function_id
) {
65 case OSSL_FUNC_MAC_NEWCTX
:
66 if (mac
->newctx
!= NULL
)
68 mac
->newctx
= OSSL_get_OP_mac_newctx(fns
);
71 case OSSL_FUNC_MAC_DUPCTX
:
72 if (mac
->dupctx
!= NULL
)
74 mac
->dupctx
= OSSL_get_OP_mac_dupctx(fns
);
76 case OSSL_FUNC_MAC_FREECTX
:
77 if (mac
->freectx
!= NULL
)
79 mac
->freectx
= OSSL_get_OP_mac_freectx(fns
);
82 case OSSL_FUNC_MAC_INIT
:
83 if (mac
->init
!= NULL
)
85 mac
->init
= OSSL_get_OP_mac_init(fns
);
88 case OSSL_FUNC_MAC_UPDATE
:
89 if (mac
->update
!= NULL
)
91 mac
->update
= OSSL_get_OP_mac_update(fns
);
94 case OSSL_FUNC_MAC_FINAL
:
95 if (mac
->final
!= NULL
)
97 mac
->final
= OSSL_get_OP_mac_final(fns
);
100 case OSSL_FUNC_MAC_GETTABLE_PARAMS
:
101 if (mac
->gettable_params
!= NULL
)
103 mac
->gettable_params
=
104 OSSL_get_OP_mac_gettable_params(fns
);
106 case OSSL_FUNC_MAC_GETTABLE_CTX_PARAMS
:
107 if (mac
->gettable_ctx_params
!= NULL
)
109 mac
->gettable_ctx_params
=
110 OSSL_get_OP_mac_gettable_ctx_params(fns
);
112 case OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS
:
113 if (mac
->settable_ctx_params
!= NULL
)
115 mac
->settable_ctx_params
=
116 OSSL_get_OP_mac_settable_ctx_params(fns
);
118 case OSSL_FUNC_MAC_GET_PARAMS
:
119 if (mac
->get_params
!= NULL
)
121 mac
->get_params
= OSSL_get_OP_mac_get_params(fns
);
123 case OSSL_FUNC_MAC_CTX_GET_PARAMS
:
124 if (mac
->ctx_get_params
!= NULL
)
126 mac
->ctx_get_params
= OSSL_get_OP_mac_ctx_get_params(fns
);
128 case OSSL_FUNC_MAC_CTX_SET_PARAMS
:
129 if (mac
->ctx_set_params
!= NULL
)
131 mac
->ctx_set_params
= OSSL_get_OP_mac_ctx_set_params(fns
);
138 * In order to be a consistent set of functions we must have at least
139 * a complete set of "mac" functions, and a complete set of context
140 * management functions, as well as the size function.
143 ERR_raise(ERR_LIB_EVP
, EVP_R_INVALID_PROVIDER_FUNCTIONS
);
148 ossl_provider_up_ref(prov
);
153 EVP_MAC
*EVP_MAC_fetch(OPENSSL_CTX
*libctx
, const char *algorithm
,
154 const char *properties
)
156 return evp_generic_fetch(libctx
, OSSL_OP_MAC
, algorithm
, properties
,
157 evp_mac_from_dispatch
, evp_mac_up_ref
,
161 int EVP_MAC_up_ref(EVP_MAC
*mac
)
163 return evp_mac_up_ref(mac
);
166 void EVP_MAC_free(EVP_MAC
*mac
)
171 const char *EVP_MAC_name(const EVP_MAC
*mac
)
176 const OSSL_PROVIDER
*EVP_MAC_provider(const EVP_MAC
*mac
)
181 const OSSL_PARAM
*EVP_MAC_gettable_params(const EVP_MAC
*mac
)
183 if (mac
->gettable_params
== NULL
)
185 return mac
->gettable_params();
188 const OSSL_PARAM
*EVP_MAC_CTX_gettable_params(const EVP_MAC
*mac
)
190 if (mac
->gettable_ctx_params
== NULL
)
192 return mac
->gettable_ctx_params();
195 const OSSL_PARAM
*EVP_MAC_CTX_settable_params(const EVP_MAC
*mac
)
197 if (mac
->settable_ctx_params
== NULL
)
199 return mac
->settable_ctx_params();