Certificate 如何获取EC证书中EC密钥的长度?

Certificate 如何获取EC证书中EC密钥的长度?,certificate,key,Certificate,Key,我有一个EC证书(签名算法是ECDSA),我想知道使用openssl api的EC密钥的长度。 现在,我可以从证书中获取EC_密钥结构,但我不知道EC_密钥中的哪个元素是密钥的长度,以及如何获取它 以下是EC_密钥的结构: struct ec_key_st { int version; EC_GROUP *group;// used to represent the definition of an elliptic curve EC_POINT *pub_key;//u

我有一个EC证书(签名算法是ECDSA),我想知道使用openssl api的EC密钥的长度。 现在,我可以从证书中获取EC_密钥结构,但我不知道EC_密钥中的哪个元素是密钥的长度,以及如何获取它

以下是EC_密钥的结构:

struct ec_key_st {
    int version;
    EC_GROUP *group;// used to represent the definition of an elliptic curve
    EC_POINT *pub_key;//used to store the points on the elliptic curve
    BIGNUM   *priv_key;
    unsigned int enc_flag;
    point_conversion_form_t conv_form;
    int     references;
    int flags;
    EC_EXTRA_DATA *method_data;
} /* EC_KEY */;

请帮忙

ECC密钥大小由
EC_组的大小定义
参数
p
。如果您在变量
EC
中有
EC\u键*
,您可以使用

int bits = BN_num_bits(ec->group->p);
或者更好地通过使用函数的
EVP_键
结构

int bits = EVP_PKEY_bits(EVP_PKEY *pkey);
编辑2018: 使用OpenSSL 1.1.0+不透明结构,我们无法再直接访问结构元素,但我们需要使用特定的功能(在较旧的OpenSSL 1.0.x版本中不可用):

但最可移植的方法是使用
EC_GROUP\u get_degree()
,它在所有OpenSSL版本(目前为1.0.2到1.1.1)中都可用:

EC_GROUP *g = EC_KEY_get0_group(ec);
int bits = EC_GROUP_order_bits(g);
EC_GROUP *g = EC_KEY_get0_group(ec);
int bits = EC_GROUP_get_degree(g);