keygen/src/ssl.c
/**
 * gen_EC_PKEY() - Generate an Elliptic Curve key (NID_X9_62_prime256v1)
 *
 * Return: A pointer to a new EC_KEY instance or NULL on failure
 */
Generate an Elliptic Curve key (NID_X9_62_prime256v1)
Return: A pointer to a new EC_KEY instance or NULL on failure
Generate an Elliptic Curve key ( NID_X9_62_prime256v1 ) Return : A pointer to a new EC_KEY instance or NULL on failure
int gen_key(struct key *key_out)
{
    int ret = 0;
    EC_KEY * ec_key = NULL;
    ec_key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
    if (!ec_key) {
        fprintf(stderr, "%s ERR: Could not generate EC_KEY", __func__);
        ret = 0;
        goto out;
    }
    key_out->pkey = EVP_PKEY_new();
    if (!key_out->pkey) {
        fprintf(stderr, "%s ERR: Could not generate PKEY", __func__);
        ret = 0;
        goto cleanup_ec_key;
    }
    ret = EC_KEY_generate_key(ec_key);
    if (!ret) {
        fprintf(stderr, "%s ERR: Could not generate EC_KEY", __func__);
        ret = 0;
        goto cleanup_ec_key;
    }
    if (!EVP_PKEY_assign_EC_KEY(key_out->pkey, ec_key)) {
        fprintf(stderr, "%s ERR: Could not assign EC_KEY to PKEY", __func__);
        ret = 0;
        goto cleanup_ec_key;
    }
    key_out->hex_str = public_key_encode_x962(ec_key);
    if (!key_out->hex_str) {
        fprintf(stderr, "%s ERR: Could not generate x862 public key from PKEY", __func__);
        ret = 0;
        goto cleanup;
    }
    ret = 1;
    goto out;
cleanup_ec_key:
    if (ec_key)
        EC_KEY_free(ec_key);
cleanup:
    destroy_key(key_out);
out:
    return ret;
}
int gen_key ( struct key * key_out ) { int ret = 0 ; EC_KEY * ec_key = NULL ; ec_key = EC_KEY_new_by_curve_name ( NID_X9_62_prime256v1 ) ; if ( ! ec_key ) { fprintf ( stderr , " " , __func__ ) ; ret = 0 ; goto out ; } key_out -> pkey = EVP_PKEY_new ( ) ; if ( ! key_out -> pkey ) { fprintf ( stderr , " " , __func__ ) ; ret = 0 ; goto cleanup_ec_key ; } ret = EC_KEY_generate_key ( ec_key ) ; if ( ! ret ) { fprintf ( stderr , " " , __func__ ) ; ret = 0 ; goto cleanup_ec_key ; } if ( ! EVP_PKEY_assign_EC_KEY ( key_out -> pkey , ec_key ) ) { fprintf ( stderr , " " , __func__ ) ; ret = 0 ; goto cleanup_ec_key ; } key_out -> hex_str = public_key_encode_x962 ( ec_key ) ; if ( ! key_out -> hex_str ) { fprintf ( stderr , " " , __func__ ) ; ret = 0 ; goto cleanup ; } ret = 1 ; goto out ; cleanup_ec_key : if ( ec_key ) EC_KEY_free ( ec_key ) ; cleanup : destroy_key ( key_out ) ; out : return ret ; }
gen_EC_PKEY() - Generate an Elliptic Curve key (NID_X9_62_prime256v1)
 Return: A pointer to a new EC_KEY instance or NULL on failure
gen_EC_PKEY () - Generate an Elliptic Curve key ( NID_X9_62_prime256v1 ) Return : A pointer to a new EC_KEY instance or NULL on failure
/* Because EVP_PKEY_assign_EC_KEY succeeded both items will be freed when EC_KEY_free is run */ /* Success */