From 0d6ff6d3d1a19d491ec9a002b808cec23ca12107 Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Fri, 23 Oct 2015 19:10:24 +0100 Subject: EC_KEY_METHOD init and finish support Reviewed-by: Richard Levitte --- crypto/ec/ec_key.c | 3 +++ crypto/ec/ec_kmeth.c | 7 ++++++- crypto/ec/ec_lcl.h | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/crypto/ec/ec_key.c b/crypto/ec/ec_key.c index cb6bcdcbf2..e2681c9acb 100644 --- a/crypto/ec/ec_key.c +++ b/crypto/ec/ec_key.c @@ -107,6 +107,9 @@ void EC_KEY_free(EC_KEY *r) } #endif + if (r->meth->finish) + r->meth->finish(r); + #ifndef OPENSSL_NO_ENGINE if (r->engine) ENGINE_finish(r->engine); diff --git a/crypto/ec/ec_kmeth.c b/crypto/ec/ec_kmeth.c index 4904989d63..77b4443fa3 100644 --- a/crypto/ec/ec_kmeth.c +++ b/crypto/ec/ec_kmeth.c @@ -63,6 +63,7 @@ static const EC_KEY_METHOD openssl_ec_key_method = { "OpenSSL EC_KEY method", 0, + 0,0, ossl_ec_key_gen, ossl_ecdh_compute_key }; @@ -120,7 +121,11 @@ EC_KEY *EC_KEY_new_method(ENGINE *engine) ret->version = 1; ret->conv_form = POINT_CONVERSION_UNCOMPRESSED; ret->references = 1; - return (ret); + if (ret->meth->init && ret->meth->init(ret) == 0) { + EC_KEY_free(ret); + return NULL; + } + return ret; } int ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, diff --git a/crypto/ec/ec_lcl.h b/crypto/ec/ec_lcl.h index 1630b40060..3aaee31575 100644 --- a/crypto/ec/ec_lcl.h +++ b/crypto/ec/ec_lcl.h @@ -560,6 +560,8 @@ const EC_METHOD *EC_GFp_nistz256_method(void); struct ec_key_method_st { const char *name; int32_t flags; + int (*init)(EC_KEY *key); + void (*finish)(EC_KEY *key); int (*keygen)(EC_KEY *key); int (*compute_key)(void *out, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh, -- cgit v1.2.3