Change EVP_MAC method from copy to dup
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org> GH: #7651
This commit is contained in:
parent
be5fc053ed
commit
7ed66e2634
10 changed files with 97 additions and 32 deletions
|
@ -39,10 +39,16 @@ static void blake2b_mac_free(EVP_MAC_IMPL *macctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int blake2b_mac_copy(EVP_MAC_IMPL *dst, EVP_MAC_IMPL *src)
|
static EVP_MAC_IMPL *blake2b_mac_dup(const EVP_MAC_IMPL *src)
|
||||||
{
|
{
|
||||||
|
EVP_MAC_IMPL *dst;
|
||||||
|
|
||||||
|
dst = OPENSSL_zalloc(sizeof(*dst));
|
||||||
|
if (dst == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
*dst = *src;
|
*dst = *src;
|
||||||
return 1;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int blake2b_mac_init(EVP_MAC_IMPL *macctx)
|
static int blake2b_mac_init(EVP_MAC_IMPL *macctx)
|
||||||
|
@ -177,7 +183,7 @@ static size_t blake2b_mac_size(EVP_MAC_IMPL *macctx)
|
||||||
const EVP_MAC blake2b_mac_meth = {
|
const EVP_MAC blake2b_mac_meth = {
|
||||||
EVP_MAC_BLAKE2B,
|
EVP_MAC_BLAKE2B,
|
||||||
blake2b_mac_new,
|
blake2b_mac_new,
|
||||||
blake2b_mac_copy,
|
blake2b_mac_dup,
|
||||||
blake2b_mac_free,
|
blake2b_mac_free,
|
||||||
blake2b_mac_size,
|
blake2b_mac_size,
|
||||||
blake2b_mac_init,
|
blake2b_mac_init,
|
||||||
|
|
|
@ -39,10 +39,16 @@ static void blake2s_mac_free(EVP_MAC_IMPL *macctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int blake2s_mac_copy(EVP_MAC_IMPL *dst, EVP_MAC_IMPL *src)
|
static EVP_MAC_IMPL *blake2s_mac_dup(const EVP_MAC_IMPL *src)
|
||||||
{
|
{
|
||||||
|
EVP_MAC_IMPL *dst;
|
||||||
|
|
||||||
|
dst = OPENSSL_malloc(sizeof(*dst));
|
||||||
|
if (dst == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
*dst = *src;
|
*dst = *src;
|
||||||
return 1;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int blake2s_mac_init(EVP_MAC_IMPL *macctx)
|
static int blake2s_mac_init(EVP_MAC_IMPL *macctx)
|
||||||
|
@ -177,7 +183,7 @@ static size_t blake2s_mac_size(EVP_MAC_IMPL *macctx)
|
||||||
const EVP_MAC blake2s_mac_meth = {
|
const EVP_MAC blake2s_mac_meth = {
|
||||||
EVP_MAC_BLAKE2S,
|
EVP_MAC_BLAKE2S,
|
||||||
blake2s_mac_new,
|
blake2s_mac_new,
|
||||||
blake2s_mac_copy,
|
blake2s_mac_dup,
|
||||||
blake2s_mac_free,
|
blake2s_mac_free,
|
||||||
blake2s_mac_size,
|
blake2s_mac_size,
|
||||||
blake2s_mac_init,
|
blake2s_mac_init,
|
||||||
|
|
|
@ -46,14 +46,22 @@ static void cmac_free(EVP_MAC_IMPL *cctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cmac_copy(EVP_MAC_IMPL *cdst, EVP_MAC_IMPL *csrc)
|
static EVP_MAC_IMPL *cmac_dup(const EVP_MAC_IMPL *csrc)
|
||||||
{
|
{
|
||||||
if (!CMAC_CTX_copy(cdst->ctx, csrc->ctx))
|
EVP_MAC_IMPL *cdst = cmac_new();
|
||||||
return 0;
|
|
||||||
|
if (cdst == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (!CMAC_CTX_copy(cdst->ctx, csrc->ctx)) {
|
||||||
|
cmac_free(cdst);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
cdst->tmpengine = csrc->tmpengine;
|
cdst->tmpengine = csrc->tmpengine;
|
||||||
cdst->tmpcipher = csrc->tmpcipher;
|
cdst->tmpcipher = csrc->tmpcipher;
|
||||||
return 1;
|
|
||||||
|
return cdst;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t cmac_size(EVP_MAC_IMPL *cctx)
|
static size_t cmac_size(EVP_MAC_IMPL *cctx)
|
||||||
|
@ -153,7 +161,7 @@ static int cmac_ctrl_str(EVP_MAC_IMPL *cctx, const char *type,
|
||||||
const EVP_MAC cmac_meth = {
|
const EVP_MAC cmac_meth = {
|
||||||
EVP_MAC_CMAC,
|
EVP_MAC_CMAC,
|
||||||
cmac_new,
|
cmac_new,
|
||||||
cmac_copy,
|
cmac_dup,
|
||||||
cmac_free,
|
cmac_free,
|
||||||
cmac_size,
|
cmac_size,
|
||||||
cmac_init,
|
cmac_init,
|
||||||
|
|
|
@ -50,9 +50,9 @@ void EVP_MAC_CTX_free(EVP_MAC_CTX *ctx)
|
||||||
|
|
||||||
EVP_MAC_CTX *EVP_MAC_CTX_dup(const EVP_MAC_CTX *src)
|
EVP_MAC_CTX *EVP_MAC_CTX_dup(const EVP_MAC_CTX *src)
|
||||||
{
|
{
|
||||||
EVP_MAC_CTX *dst = EVP_MAC_CTX_new(src->meth);
|
EVP_MAC_CTX *dst;
|
||||||
|
|
||||||
if (dst == NULL)
|
if (src->data == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
dst = OPENSSL_malloc(sizeof(*dst));
|
dst = OPENSSL_malloc(sizeof(*dst));
|
||||||
|
|
|
@ -39,11 +39,23 @@ static EVP_MAC_IMPL *gmac_new(void)
|
||||||
return gctx;
|
return gctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int gmac_copy(EVP_MAC_IMPL *gdst, EVP_MAC_IMPL *gsrc)
|
static EVP_MAC_IMPL *gmac_dup(const EVP_MAC_IMPL *gsrc)
|
||||||
{
|
{
|
||||||
|
EVP_MAC_IMPL *gdst;
|
||||||
|
|
||||||
|
gdst = gmac_new();
|
||||||
|
if (gdst == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (!EVP_CIPHER_CTX_copy(gdst->ctx, gsrc->ctx)) {
|
||||||
|
gmac_free(gdst);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
gdst->cipher = gsrc->cipher;
|
gdst->cipher = gsrc->cipher;
|
||||||
gdst->engine = gsrc->engine;
|
gdst->engine = gsrc->engine;
|
||||||
return EVP_CIPHER_CTX_copy(gdst->ctx, gsrc->ctx);
|
|
||||||
|
return gdst;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t gmac_size(EVP_MAC_IMPL *gctx)
|
static size_t gmac_size(EVP_MAC_IMPL *gctx)
|
||||||
|
@ -172,7 +184,7 @@ static int gmac_ctrl_str(EVP_MAC_IMPL *gctx, const char *type,
|
||||||
const EVP_MAC gmac_meth = {
|
const EVP_MAC gmac_meth = {
|
||||||
EVP_MAC_GMAC,
|
EVP_MAC_GMAC,
|
||||||
gmac_new,
|
gmac_new,
|
||||||
gmac_copy,
|
gmac_dup,
|
||||||
gmac_free,
|
gmac_free,
|
||||||
gmac_size,
|
gmac_size,
|
||||||
gmac_init,
|
gmac_init,
|
||||||
|
|
|
@ -45,14 +45,23 @@ static void hmac_free(EVP_MAC_IMPL *hctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int hmac_copy(EVP_MAC_IMPL *hdst, EVP_MAC_IMPL *hsrc)
|
static EVP_MAC_IMPL *hmac_dup(const EVP_MAC_IMPL *hsrc)
|
||||||
{
|
{
|
||||||
if (!HMAC_CTX_copy(hdst->ctx, hsrc->ctx))
|
EVP_MAC_IMPL *hdst;
|
||||||
return 0;
|
|
||||||
|
hdst = hmac_new();
|
||||||
|
if (hdst == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (!HMAC_CTX_copy(hdst->ctx, hsrc->ctx)) {
|
||||||
|
hmac_free(hdst);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
hdst->tmpengine = hsrc->tmpengine;
|
hdst->tmpengine = hsrc->tmpengine;
|
||||||
hdst->tmpmd = hsrc->tmpmd;
|
hdst->tmpmd = hsrc->tmpmd;
|
||||||
return 1;
|
|
||||||
|
return hdst;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t hmac_size(EVP_MAC_IMPL *hctx)
|
static size_t hmac_size(EVP_MAC_IMPL *hctx)
|
||||||
|
@ -162,7 +171,7 @@ static int hmac_ctrl_str(EVP_MAC_IMPL *hctx, const char *type,
|
||||||
const EVP_MAC hmac_meth = {
|
const EVP_MAC hmac_meth = {
|
||||||
EVP_MAC_HMAC,
|
EVP_MAC_HMAC,
|
||||||
hmac_new,
|
hmac_new,
|
||||||
hmac_copy,
|
hmac_dup,
|
||||||
hmac_free,
|
hmac_free,
|
||||||
hmac_size,
|
hmac_size,
|
||||||
hmac_init,
|
hmac_init,
|
||||||
|
|
|
@ -118,7 +118,7 @@ typedef struct evp_mac_impl_st EVP_MAC_IMPL;
|
||||||
struct evp_mac_st {
|
struct evp_mac_st {
|
||||||
int type;
|
int type;
|
||||||
EVP_MAC_IMPL *(*new) (void);
|
EVP_MAC_IMPL *(*new) (void);
|
||||||
int (*copy) (EVP_MAC_IMPL *macdst, EVP_MAC_IMPL *macsrc);
|
EVP_MAC_IMPL *(*dup) (const EVP_MAC_IMPL *macsrc);
|
||||||
void (*free) (EVP_MAC_IMPL *macctx);
|
void (*free) (EVP_MAC_IMPL *macctx);
|
||||||
size_t (*size) (EVP_MAC_IMPL *macctx);
|
size_t (*size) (EVP_MAC_IMPL *macctx);
|
||||||
int (*init) (EVP_MAC_IMPL *macctx);
|
int (*init) (EVP_MAC_IMPL *macctx);
|
||||||
|
|
|
@ -147,8 +147,19 @@ static EVP_MAC_IMPL *kmac256_new(void)
|
||||||
return kmac_new(evp_keccak_kmac256());
|
return kmac_new(evp_keccak_kmac256());
|
||||||
}
|
}
|
||||||
|
|
||||||
static int kmac_copy(EVP_MAC_IMPL *gdst, EVP_MAC_IMPL *gsrc)
|
static EVP_MAC_IMPL *kmac_dup(const EVP_MAC_IMPL *gsrc)
|
||||||
{
|
{
|
||||||
|
EVP_MAC_IMPL *gdst;
|
||||||
|
|
||||||
|
gdst = kmac_new(gsrc->md);
|
||||||
|
if (gdst == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (!EVP_MD_CTX_copy(gdst->ctx, gsrc->ctx)) {
|
||||||
|
kmac_free(gdst);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
gdst->md = gsrc->md;
|
gdst->md = gsrc->md;
|
||||||
gdst->out_len = gsrc->out_len;
|
gdst->out_len = gsrc->out_len;
|
||||||
gdst->key_len = gsrc->key_len;
|
gdst->key_len = gsrc->key_len;
|
||||||
|
@ -157,7 +168,7 @@ static int kmac_copy(EVP_MAC_IMPL *gdst, EVP_MAC_IMPL *gsrc)
|
||||||
memcpy(gdst->key, gsrc->key, gsrc->key_len);
|
memcpy(gdst->key, gsrc->key, gsrc->key_len);
|
||||||
memcpy(gdst->custom, gsrc->custom, gdst->custom_len);
|
memcpy(gdst->custom, gsrc->custom, gdst->custom_len);
|
||||||
|
|
||||||
return EVP_MD_CTX_copy(gdst->ctx, gsrc->ctx);
|
return gdst;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -444,7 +455,7 @@ static int kmac_bytepad_encode_key(unsigned char *out, int *out_len,
|
||||||
const EVP_MAC kmac128_meth = {
|
const EVP_MAC kmac128_meth = {
|
||||||
EVP_MAC_KMAC128,
|
EVP_MAC_KMAC128,
|
||||||
kmac128_new,
|
kmac128_new,
|
||||||
kmac_copy,
|
kmac_dup,
|
||||||
kmac_free,
|
kmac_free,
|
||||||
kmac_size,
|
kmac_size,
|
||||||
kmac_init,
|
kmac_init,
|
||||||
|
@ -457,7 +468,7 @@ const EVP_MAC kmac128_meth = {
|
||||||
const EVP_MAC kmac256_meth = {
|
const EVP_MAC kmac256_meth = {
|
||||||
EVP_MAC_KMAC256,
|
EVP_MAC_KMAC256,
|
||||||
kmac256_new,
|
kmac256_new,
|
||||||
kmac_copy,
|
kmac_dup,
|
||||||
kmac_free,
|
kmac_free,
|
||||||
kmac_size,
|
kmac_size,
|
||||||
kmac_init,
|
kmac_init,
|
||||||
|
|
|
@ -37,11 +37,17 @@ static void poly1305_free(EVP_MAC_IMPL *ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int poly1305_copy(EVP_MAC_IMPL *dst, EVP_MAC_IMPL *src)
|
static EVP_MAC_IMPL *poly1305_dup(const EVP_MAC_IMPL *src)
|
||||||
{
|
{
|
||||||
|
EVP_MAC_IMPL *dst;
|
||||||
|
|
||||||
|
dst = poly1305_new();
|
||||||
|
if (dst == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
*dst->ctx = *src->ctx;
|
*dst->ctx = *src->ctx;
|
||||||
|
|
||||||
return 1;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t poly1305_size(EVP_MAC_IMPL *ctx)
|
static size_t poly1305_size(EVP_MAC_IMPL *ctx)
|
||||||
|
@ -130,7 +136,7 @@ static int poly1305_ctrl_str(EVP_MAC_IMPL *ctx,
|
||||||
const EVP_MAC poly1305_meth = {
|
const EVP_MAC poly1305_meth = {
|
||||||
EVP_MAC_POLY1305,
|
EVP_MAC_POLY1305,
|
||||||
poly1305_new,
|
poly1305_new,
|
||||||
poly1305_copy,
|
poly1305_dup,
|
||||||
poly1305_free,
|
poly1305_free,
|
||||||
poly1305_size,
|
poly1305_size,
|
||||||
poly1305_init,
|
poly1305_init,
|
||||||
|
|
|
@ -31,10 +31,17 @@ static void siphash_free(EVP_MAC_IMPL *sctx)
|
||||||
OPENSSL_free(sctx);
|
OPENSSL_free(sctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int siphash_copy(EVP_MAC_IMPL *sdst, EVP_MAC_IMPL *ssrc)
|
static EVP_MAC_IMPL *siphash_dup(const EVP_MAC_IMPL *ssrc)
|
||||||
{
|
{
|
||||||
|
EVP_MAC_IMPL *sdst;
|
||||||
|
|
||||||
|
sdst = siphash_new();
|
||||||
|
if (sdst == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
*sdst = *ssrc;
|
*sdst = *ssrc;
|
||||||
return 1;
|
|
||||||
|
return sdst;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t siphash_size(EVP_MAC_IMPL *sctx)
|
static size_t siphash_size(EVP_MAC_IMPL *sctx)
|
||||||
|
@ -128,7 +135,7 @@ static int siphash_ctrl_str(EVP_MAC_IMPL *ctx,
|
||||||
const EVP_MAC siphash_meth = {
|
const EVP_MAC siphash_meth = {
|
||||||
EVP_MAC_SIPHASH,
|
EVP_MAC_SIPHASH,
|
||||||
siphash_new,
|
siphash_new,
|
||||||
siphash_copy,
|
siphash_dup,
|
||||||
siphash_free,
|
siphash_free,
|
||||||
siphash_size,
|
siphash_size,
|
||||||
siphash_init,
|
siphash_init,
|
||||||
|
|
Loading…
Reference in a new issue