PROV_ECDSA_CTX *srcctx = (PROV_ECDSA_CTX *)vctx;
PROV_ECDSA_CTX *dstctx;
- if (!ossl_prov_is_running())
- return NULL;
-
- dstctx = OPENSSL_zalloc(sizeof(*srcctx));
- if (dstctx == NULL)
+ /* Test KATS should not need to be supported */
+ if (!ossl_prov_is_running()
+ || srcctx->kinv != NULL
+ || srcctx->r != NULL
+ || (dstctx = OPENSSL_memdup(srcctx, sizeof(*srcctx))) == NULL)
return NULL;
- *dstctx = *srcctx;
dstctx->ec = NULL;
dstctx->propq = NULL;
+ dstctx->md = NULL;
+ dstctx->mdctx = NULL;
+ dstctx->sig = NULL;
if (srcctx->ec != NULL && !EC_KEY_up_ref(srcctx->ec))
goto err;
- /* Test KATS should not need to be supported */
- if (srcctx->kinv != NULL || srcctx->r != NULL)
- goto err;
dstctx->ec = srcctx->ec;
if (srcctx->md != NULL && !EVP_MD_up_ref(srcctx->md))
goto err;
dstctx->md = srcctx->md;
- if (srcctx->mdctx != NULL) {
- dstctx->mdctx = EVP_MD_CTX_new();
- if (dstctx->mdctx == NULL
- || !EVP_MD_CTX_copy_ex(dstctx->mdctx, srcctx->mdctx))
- goto err;
- }
-
- if (srcctx->propq != NULL) {
- dstctx->propq = OPENSSL_strdup(srcctx->propq);
- if (dstctx->propq == NULL)
- goto err;
- }
+ if (srcctx->mdctx != NULL
+ && ((dstctx->mdctx = EVP_MD_CTX_new()) == NULL
+ || !EVP_MD_CTX_copy_ex(dstctx->mdctx, srcctx->mdctx)))
+ goto err;
+ if (srcctx->propq != NULL
+ && (dstctx->propq = OPENSSL_strdup(srcctx->propq)) == NULL)
+ goto err;
+ if (srcctx->sig != NULL
+ && (dstctx->sig = OPENSSL_memdup(srcctx->sig, srcctx->siglen)) == NULL)
+ goto err;
return dstctx;
err:
if (!OSSL_PARAM_get_octet_string(p.sig, (void **)&ctx->sig,
0, &ctx->siglen))
return 0;
+ /* The signature must not be empty */
+ if (ctx->siglen == 0) {
+ OPENSSL_free(ctx->sig);
+ ctx->sig = NULL;
+ return 0;
+ }
}
}
return 1;