/*
- * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
#include <openssl/err.h>
#include <openssl/core.h>
#include <openssl/core_names.h>
-#include <openssl/ossl_typ.h>
+#include <openssl/types.h>
#include "internal/nelem.h"
-#include "internal/evp_int.h"
+#include "crypto/evp.h"
#include "internal/provider.h"
-#include "evp_locl.h"
+#include "evp_local.h"
EVP_MAC_CTX *EVP_MAC_CTX_new(EVP_MAC *mac)
{
if (ctx == NULL
|| (ctx->data = mac->newctx(ossl_provider_ctx(mac->prov))) == NULL
|| !EVP_MAC_up_ref(mac)) {
- EVPerr(EVP_F_EVP_MAC_CTX_NEW, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE);
if (ctx != NULL)
mac->freectx(ctx->data);
OPENSSL_free(ctx);
dst = OPENSSL_malloc(sizeof(*dst));
if (dst == NULL) {
- EVPerr(EVP_F_EVP_MAC_CTX_DUP, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE);
return NULL;
}
*dst = *src;
if (!EVP_MAC_up_ref(dst->meth)) {
- EVPerr(EVP_F_EVP_MAC_CTX_DUP, ERR_R_MALLOC_FAILURE);
+ ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE);
OPENSSL_free(dst);
return NULL;
}
return ctx->meth;
}
-size_t EVP_MAC_size(EVP_MAC_CTX *ctx)
+size_t EVP_MAC_CTX_get_mac_size(EVP_MAC_CTX *ctx)
{
size_t sz = 0;
if (ctx->data != NULL) {
OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
- params[0] = OSSL_PARAM_construct_size_t(OSSL_MAC_PARAM_OUTLEN, &sz);
+ params[0] = OSSL_PARAM_construct_size_t(OSSL_MAC_PARAM_SIZE, &sz);
if (ctx->meth->get_ctx_params != NULL) {
if (ctx->meth->get_ctx_params(ctx->data, params))
return sz;
int EVP_MAC_update(EVP_MAC_CTX *ctx, const unsigned char *data, size_t datalen)
{
- if (datalen == 0)
- return 1;
return ctx->meth->update(ctx->data, data, datalen);
}
int EVP_MAC_final(EVP_MAC_CTX *ctx,
unsigned char *out, size_t *outl, size_t outsize)
{
- int l = EVP_MAC_size(ctx);
+ size_t l;
+ int res = 1;
- if (l < 0)
- return 0;
+ if (out != NULL)
+ res = ctx->meth->final(ctx->data, out, &l, outsize);
+ else
+ l = EVP_MAC_CTX_get_mac_size(ctx);
if (outl != NULL)
*outl = l;
- if (out == NULL)
- return 1;
- return ctx->meth->final(ctx->data, out, outl, outsize);
+ return res;
}
/*
return ctx->meth->set_ctx_params(ctx->data, params);
return 1;
}
+
+int EVP_MAC_number(const EVP_MAC *mac)
+{
+ return mac->name_id;
+}
+
+const char *EVP_MAC_name(const EVP_MAC *mac)
+{
+ if (mac->prov != NULL)
+ return evp_first_name(mac->prov, mac->name_id);
+ return NULL;
+}
+
+int EVP_MAC_is_a(const EVP_MAC *mac, const char *name)
+{
+ return evp_is_a(mac->prov, mac->name_id, NULL, name);
+}
+
+void EVP_MAC_names_do_all(const EVP_MAC *mac,
+ void (*fn)(const char *name, void *data),
+ void *data)
+{
+ if (mac->prov != NULL)
+ evp_names_do_all(mac->prov, mac->name_id, fn, data);
+}