X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=crypto%2Fec%2Fec_key.c;h=439cfa27cc56663328619dee71d1a40202a5373c;hp=19628b143539167f633dfa712d09c3d026cd49d3;hb=acae59bb29ddc769743ab4a8ae373b5ff2f42b57;hpb=907e95006820c84d2efe1adb2c8af8340f3ba6cc diff --git a/crypto/ec/ec_key.c b/crypto/ec/ec_key.c index 19628b1435..439cfa27cc 100644 --- a/crypto/ec/ec_key.c +++ b/crypto/ec/ec_key.c @@ -99,24 +99,16 @@ void EC_KEY_free(EC_KEY *r) return; i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_EC); -#ifdef REF_PRINT - REF_PRINT("EC_KEY", r); -#endif + REF_PRINT_COUNT("EC_KEY", r); if (i > 0) return; -#ifdef REF_CHECK - if (i < 0) { - fprintf(stderr, "EC_KEY_free, bad reference count\n"); - abort(); - } -#endif + REF_ASSERT_ISNT(i < 0); if (r->meth->finish != NULL) r->meth->finish(r); #ifndef OPENSSL_NO_ENGINE - if (r->engine != NULL) - ENGINE_finish(r->engine); + ENGINE_finish(r->engine); #endif CRYPTO_free_ex_data(CRYPTO_EX_INDEX_EC_KEY, r, &r->ex_data); @@ -137,7 +129,7 @@ EC_KEY *EC_KEY_copy(EC_KEY *dest, EC_KEY *src) if (dest->meth->finish != NULL) dest->meth->finish(dest); #ifndef OPENSSL_NO_ENGINE - if (dest->engine != NULL && ENGINE_finish(dest->engine) == 0) + if (ENGINE_finish(dest->engine) == 0) return 0; dest->engine = NULL; #endif @@ -213,15 +205,9 @@ EC_KEY *EC_KEY_dup(EC_KEY *ec_key) int EC_KEY_up_ref(EC_KEY *r) { int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_EC); -#ifdef REF_PRINT - REF_PRINT("EC_KEY", r); -#endif -#ifdef REF_CHECK - if (i < 2) { - fprintf(stderr, "EC_KEY_up, bad reference count\n"); - abort(); - } -#endif + + REF_PRINT_COUNT("EC_KEY", r); + REF_ASSERT_ISNT(i < 2); return ((i > 1) ? 1 : 0); } @@ -591,3 +577,22 @@ int EC_KEY_oct2priv(EC_KEY *eckey, unsigned char *buf, size_t len) } return 1; } + +size_t EC_KEY_priv2buf(const EC_KEY *eckey, unsigned char **pbuf) +{ + size_t len; + unsigned char *buf; + len = EC_KEY_priv2oct(eckey, NULL, 0); + if (len == 0 || pbuf == NULL) + return len; + buf = OPENSSL_malloc(len); + if (buf == NULL) + return 0; + len = EC_KEY_priv2oct(eckey, buf, len); + if (len == 0) { + OPENSSL_free(buf); + return 0; + } + *pbuf = buf; + return len; +}