aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2015-10-25 13:09:50 +0000
committerDr. Stephen Henson <steve@openssl.org>2015-12-09 22:09:18 +0000
commit3475bc9675fd7b575b260c62424d2ac1547dd251 (patch)
tree95d5c70bb248a189df4be69b602e7518f38216a1
parentea0392b921598e415c754dcf4b5c61c7fa337a59 (diff)
downloadopenssl-3475bc9675fd7b575b260c62424d2ac1547dd251.tar.gz
Add set methods.
Add set_group, set_public and set_private methods. An EC_KEY_METHOD can use these to perform any appropriate operation when the key components are set, such as caching data in some more convenient ENGINE specific format or returning an error if the parameters are invalid or the operation is not supported. Reviewed-by: Richard Levitte <levitte@openssl.org>
-rw-r--r--crypto/ec/ec_key.c10
-rw-r--r--crypto/ec/ec_kmeth.c2
-rw-r--r--crypto/ec/ec_lcl.h3
3 files changed, 14 insertions, 1 deletions
diff --git a/crypto/ec/ec_key.c b/crypto/ec/ec_key.c
index 1b941b4844..53844ab9be 100644
--- a/crypto/ec/ec_key.c
+++ b/crypto/ec/ec_key.c
@@ -84,6 +84,10 @@ EC_KEY *EC_KEY_new_by_curve_name(int nid)
EC_KEY_free(ret);
return NULL;
}
+ if (ret->meth->set_group && ret->meth->set_group(ret, ret->group) == 0) {
+ EC_KEY_free(ret);
+ return NULL;
+ }
return ret;
}
@@ -449,6 +453,8 @@ const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key)
int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group)
{
+ if (key->meth->set_group && key->meth->set_group(key, group) == 0)
+ return 0;
EC_GROUP_free(key->group);
key->group = EC_GROUP_dup(group);
return (key->group == NULL) ? 0 : 1;
@@ -461,6 +467,8 @@ const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key)
int EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *priv_key)
{
+ if (key->meth->set_private && key->meth->set_private(key, priv_key) == 0)
+ return 0;
BN_clear_free(key->priv_key);
key->priv_key = BN_dup(priv_key);
return (key->priv_key == NULL) ? 0 : 1;
@@ -473,6 +481,8 @@ const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *key)
int EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub_key)
{
+ if (key->meth->set_public && key->meth->set_public(key, pub_key) == 0)
+ return 0;
EC_POINT_free(key->pub_key);
key->pub_key = EC_POINT_dup(pub_key, key->group);
return (key->pub_key == NULL) ? 0 : 1;
diff --git a/crypto/ec/ec_kmeth.c b/crypto/ec/ec_kmeth.c
index 4581880b84..767e51f73e 100644
--- a/crypto/ec/ec_kmeth.c
+++ b/crypto/ec/ec_kmeth.c
@@ -63,7 +63,7 @@
static const EC_KEY_METHOD openssl_ec_key_method = {
"OpenSSL EC_KEY method",
0,
- 0,0,0,
+ 0,0,0,0,0,0,
ossl_ec_key_gen,
ossl_ecdh_compute_key
};
diff --git a/crypto/ec/ec_lcl.h b/crypto/ec/ec_lcl.h
index 2db8779c57..57fd6ce284 100644
--- a/crypto/ec/ec_lcl.h
+++ b/crypto/ec/ec_lcl.h
@@ -563,6 +563,9 @@ struct ec_key_method_st {
int (*init)(EC_KEY *key);
void (*finish)(EC_KEY *key);
int (*copy)(EC_KEY *dest, const EC_KEY *src);
+ int (*set_group)(EC_KEY *key, const EC_GROUP *grp);
+ int (*set_private)(EC_KEY *key, const BIGNUM *priv_key);
+ int (*set_public)(EC_KEY *key, const EC_POINT *pub_key);
int (*keygen)(EC_KEY *key);
int (*compute_key)(void *out, size_t outlen, const EC_POINT *pub_key,
EC_KEY *ecdh,