Commit 5a6a1029 authored by Dr. Stephen Henson's avatar Dr. Stephen Henson
Browse files

EC_KEY_METHOD keygen support.



Add keygen to EC_KEY_METHOD. Redirect EC_KEY_generate_key through
method and set the current EC key generation function as the default.

Reviewed-by: default avatarRichard Levitte <levitte@openssl.org>
parent d2fa70d8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -300,6 +300,7 @@ static ERR_STRING_DATA EC_str_reasons[] = {
    {ERR_REASON(EC_R_NOT_INITIALIZED), "not initialized"},
    {ERR_REASON(EC_R_NO_FIELD_MOD), "no field mod"},
    {ERR_REASON(EC_R_NO_PARAMETERS_SET), "no parameters set"},
    {ERR_REASON(EC_R_OPERATION_NOT_SUPPORTED), "operation not supported"},
    {ERR_REASON(EC_R_PASSED_NULL_PARAMETER), "passed null parameter"},
    {ERR_REASON(EC_R_PEER_KEY_ERROR), "peer key error"},
    {ERR_REASON(EC_R_PKPARAMETERS2GROUP_FAILURE),
+12 −5
Original line number Diff line number Diff line
@@ -203,15 +203,22 @@ int EC_KEY_up_ref(EC_KEY *r)

int EC_KEY_generate_key(EC_KEY *eckey)
{
    int ok = 0;
    BN_CTX *ctx = NULL;
    BIGNUM *priv_key = NULL, *order = NULL;
    EC_POINT *pub_key = NULL;

    if (!eckey || !eckey->group) {
        ECerr(EC_F_EC_KEY_GENERATE_KEY, ERR_R_PASSED_NULL_PARAMETER);
        return 0;
    }
    if (eckey->meth->keygen)
        return eckey->meth->keygen(eckey);
    ECerr(EC_F_EC_KEY_GENERATE_KEY, EC_R_OPERATION_NOT_SUPPORTED);
    return 0;
}

int ossl_ec_key_gen(EC_KEY *eckey)
{
    int ok = 0;
    BN_CTX *ctx = NULL;
    BIGNUM *priv_key = NULL, *order = NULL;
    EC_POINT *pub_key = NULL;

    if ((order = BN_new()) == NULL)
        goto err;
+2 −1
Original line number Diff line number Diff line
@@ -60,7 +60,8 @@

static const EC_KEY_METHOD openssl_ec_key_method = {
    "OpenSSL EC_KEY method",
    0
    0,
    ossl_ec_key_gen
};

const EC_KEY_METHOD *default_ec_key_meth = &openssl_ec_key_method;
+3 −0
Original line number Diff line number Diff line
@@ -560,6 +560,9 @@ const EC_METHOD *EC_GFp_nistz256_method(void);
struct ec_key_method_st {
    const char *name;
    int32_t flags;
    int (*keygen)(EC_KEY *key);
} /* EC_KEY_METHOD */ ;

#define EC_KEY_METHOD_DYNAMIC   1

int ossl_ec_key_gen(EC_KEY *eckey);
+1 −0
Original line number Diff line number Diff line
@@ -1266,6 +1266,7 @@ void ERR_load_EC_strings(void);
# define EC_R_NOT_INITIALIZED                             111
# define EC_R_NO_FIELD_MOD                                133
# define EC_R_NO_PARAMETERS_SET                           139
# define EC_R_OPERATION_NOT_SUPPORTED                     152
# define EC_R_PASSED_NULL_PARAMETER                       134
# define EC_R_PEER_KEY_ERROR                              149
# define EC_R_PKPARAMETERS2GROUP_FAILURE                  127