EC_KEY_METHOD init and finish support
authorDr. Stephen Henson <steve@openssl.org>
Fri, 23 Oct 2015 18:10:24 +0000 (19:10 +0100)
committerDr. Stephen Henson <steve@openssl.org>
Wed, 9 Dec 2015 22:09:18 +0000 (22:09 +0000)
Reviewed-by: Richard Levitte <levitte@openssl.org>
crypto/ec/ec_key.c
crypto/ec/ec_kmeth.c
crypto/ec/ec_lcl.h

index cb6bcdcbf266f2f410862eb8ab8442c06af45bbb..e2681c9acb80ad2185b69d36e9529c564797cc2c 100644 (file)
@@ -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);
index 4904989d63f784497e5b7ee53fe9e39efa160043..77b4443fa3485fd4c0e21fbbd02b85e86cedfd4b 100644 (file)
@@ -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,
index 1630b4006075d0a195f3ca4f4168663c30b8c84e..3aaee31575c949b79e4db1bf46a123d67d03f439 100644 (file)
@@ -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,