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>
This commit is contained in:
parent
ea0392b921
commit
3475bc9675
@ -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;
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user