{
EVP_MAC_CTX *ctx = OPENSSL_zalloc(sizeof(EVP_MAC_CTX));
- if (ctx == NULL
- || (ctx->algctx = mac->newctx(ossl_provider_ctx(mac->prov))) == NULL
- || !EVP_MAC_up_ref(mac)) {
- ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE);
- if (ctx != NULL)
- mac->freectx(ctx->algctx);
- OPENSSL_free(ctx);
- ctx = NULL;
- } else {
+ if (ctx != NULL) {
ctx->meth = mac;
+ if ((ctx->algctx = mac->newctx(ossl_provider_ctx(mac->prov))) == NULL
+ || !EVP_MAC_up_ref(mac)) {
+ mac->freectx(ctx->algctx);
+ ERR_raise(ERR_LIB_EVP, ERR_R_EVP_LIB);
+ OPENSSL_free(ctx);
+ ctx = NULL;
+ }
}
return ctx;
}
return NULL;
dst = OPENSSL_malloc(sizeof(*dst));
- if (dst == NULL) {
- ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE);
+ if (dst == NULL)
return NULL;
- }
*dst = *src;
if (!EVP_MAC_up_ref(dst->meth)) {
- ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_EVP, ERR_R_EVP_LIB);
OPENSSL_free(dst);
return NULL;
}
return dst;
}
-EVP_MAC *EVP_MAC_CTX_mac(EVP_MAC_CTX *ctx)
+EVP_MAC *EVP_MAC_CTX_get0_mac(EVP_MAC_CTX *ctx)
{
return ctx->meth;
}
size_t l;
int res;
OSSL_PARAM params[2];
+ size_t macsize;
if (ctx == NULL || ctx->meth == NULL) {
ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_NULL_ALGORITHM);
return 0;
}
+ macsize = EVP_MAC_CTX_get_mac_size(ctx);
if (out == NULL) {
if (outl == NULL) {
ERR_raise(ERR_LIB_EVP, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
- *outl = EVP_MAC_CTX_get_mac_size(ctx);
+ *outl = macsize;
return 1;
}
+ if (outsize < macsize) {
+ ERR_raise(ERR_LIB_EVP, EVP_R_BUFFER_TOO_SMALL);
+ return 0;
+ }
if (xof) {
params[0] = OSSL_PARAM_construct_int(OSSL_MAC_PARAM_XOF, &xof);
params[1] = OSSL_PARAM_construct_end();
return 1;
}
-int EVP_MAC_number(const EVP_MAC *mac)
+int evp_mac_get_number(const EVP_MAC *mac)
{
return mac->name_id;
}
-const char *EVP_MAC_name(const EVP_MAC *mac)
+const char *EVP_MAC_get0_name(const EVP_MAC *mac)
{
return mac->type_name;
}
-const char *EVP_MAC_description(const EVP_MAC *mac)
+const char *EVP_MAC_get0_description(const EVP_MAC *mac)
{
return mac->description;
}
int EVP_MAC_is_a(const EVP_MAC *mac, const char *name)
{
- return evp_is_a(mac->prov, mac->name_id, NULL, name);
+ return mac != NULL && evp_is_a(mac->prov, mac->name_id, NULL, name);
}
int EVP_MAC_names_do_all(const EVP_MAC *mac,
return 1;
}
-unsigned char *EVP_Q_mac(OSSL_LIB_CTX *libctx, const char *name, const char *propq,
+unsigned char *EVP_Q_mac(OSSL_LIB_CTX *libctx,
+ const char *name, const char *propq,
const char *subalg, const OSSL_PARAM *params,
const void *key, size_t keylen,
const unsigned char *data, size_t datalen,
- unsigned char *out, size_t outsize, unsigned int *outlen)
+ unsigned char *out, size_t outsize, size_t *outlen)
{
EVP_MAC *mac = EVP_MAC_fetch(libctx, name, propq);
OSSL_PARAM subalg_param[] = { OSSL_PARAM_END, OSSL_PARAM_END };
EVP_MAC_CTX *ctx = NULL;
- size_t len;
+ size_t len = 0;
unsigned char *res = NULL;
if (outlen != NULL)
}
res = out;
if (res != NULL && outlen != NULL)
- *outlen = (unsigned int)len;
+ *outlen = len;
}
err: