}
}
-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;
- return 1;
+ return dst;
}
static int blake2b_mac_init(EVP_MAC_IMPL *macctx)
const EVP_MAC blake2b_mac_meth = {
EVP_MAC_BLAKE2B,
blake2b_mac_new,
- blake2b_mac_copy,
+ blake2b_mac_dup,
blake2b_mac_free,
blake2b_mac_size,
blake2b_mac_init,
}
}
-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;
- return 1;
+ return dst;
}
static int blake2s_mac_init(EVP_MAC_IMPL *macctx)
const EVP_MAC blake2s_mac_meth = {
EVP_MAC_BLAKE2S,
blake2s_mac_new,
- blake2s_mac_copy,
+ blake2s_mac_dup,
blake2s_mac_free,
blake2s_mac_size,
blake2s_mac_init,
}
}
-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))
- return 0;
+ EVP_MAC_IMPL *cdst = cmac_new();
+
+ if (cdst == NULL)
+ return NULL;
+
+ if (!CMAC_CTX_copy(cdst->ctx, csrc->ctx)) {
+ cmac_free(cdst);
+ return NULL;
+ }
cdst->tmpengine = csrc->tmpengine;
cdst->tmpcipher = csrc->tmpcipher;
- return 1;
+
+ return cdst;
}
static size_t cmac_size(EVP_MAC_IMPL *cctx)
const EVP_MAC cmac_meth = {
EVP_MAC_CMAC,
cmac_new,
- cmac_copy,
+ cmac_dup,
cmac_free,
cmac_size,
cmac_init,
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;
dst = OPENSSL_malloc(sizeof(*dst));
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->engine = gsrc->engine;
- return EVP_CIPHER_CTX_copy(gdst->ctx, gsrc->ctx);
+
+ return gdst;
}
static size_t gmac_size(EVP_MAC_IMPL *gctx)
const EVP_MAC gmac_meth = {
EVP_MAC_GMAC,
gmac_new,
- gmac_copy,
+ gmac_dup,
gmac_free,
gmac_size,
gmac_init,
}
}
-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))
- return 0;
+ EVP_MAC_IMPL *hdst;
+
+ 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->tmpmd = hsrc->tmpmd;
- return 1;
+
+ return hdst;
}
static size_t hmac_size(EVP_MAC_IMPL *hctx)
const EVP_MAC hmac_meth = {
EVP_MAC_HMAC,
hmac_new,
- hmac_copy,
+ hmac_dup,
hmac_free,
hmac_size,
hmac_init,
struct evp_mac_st {
int type;
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);
size_t (*size) (EVP_MAC_IMPL *macctx);
int (*init) (EVP_MAC_IMPL *macctx);
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->out_len = gsrc->out_len;
gdst->key_len = gsrc->key_len;
memcpy(gdst->key, gsrc->key, gsrc->key_len);
memcpy(gdst->custom, gsrc->custom, gdst->custom_len);
- return EVP_MD_CTX_copy(gdst->ctx, gsrc->ctx);
+ return gdst;
}
/*
const EVP_MAC kmac128_meth = {
EVP_MAC_KMAC128,
kmac128_new,
- kmac_copy,
+ kmac_dup,
kmac_free,
kmac_size,
kmac_init,
const EVP_MAC kmac256_meth = {
EVP_MAC_KMAC256,
kmac256_new,
- kmac_copy,
+ kmac_dup,
kmac_free,
kmac_size,
kmac_init,
}
}
-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;
- return 1;
+ return dst;
}
static size_t poly1305_size(EVP_MAC_IMPL *ctx)
const EVP_MAC poly1305_meth = {
EVP_MAC_POLY1305,
poly1305_new,
- poly1305_copy,
+ poly1305_dup,
poly1305_free,
poly1305_size,
poly1305_init,
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;
- return 1;
+
+ return sdst;
}
static size_t siphash_size(EVP_MAC_IMPL *sctx)
const EVP_MAC siphash_meth = {
EVP_MAC_SIPHASH,
siphash_new,
- siphash_copy,
+ siphash_dup,
siphash_free,
siphash_size,
siphash_init,