我有一个EC证书(签名算法是ECDSA),我想知道使用openssl的EC密钥的长度。现在,我可以从证书中获得EC_KEY结构,但我不知道EC_KEY中的哪个元素是密钥的长度,以及如何获得它。
以下是EC_KEY的结构:
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 */;请帮帮我!
发布于 2016-04-18 11:51:53
ECC密钥大小由EC_GROUP参数p的大小定义。如果您的EC_KEY *在变量ec中,则可以使用
int bits = BN_num_bits(ec->group->p);或者更好地使用函数的EVP_KEY结构
int bits = EVP_PKEY_bits(EVP_PKEY *pkey);编辑2018年:使用OpenSSL 1.1.0+不透明结构,我们不能再直接访问结构元素了,但是我们需要使用特定的函数(在旧的OpenSSL 1.0.x版本中不可用):
EC_GROUP *g = EC_KEY_get0_group(ec);
int bits = EC_GROUP_order_bits(g);但是,最可移植的方法是使用EC_GROUP_get_degree(),它在所有OpenSSL版本中都可用(目前为1.0.2至1.1.1 ):
EC_GROUP *g = EC_KEY_get0_group(ec);
int bits = EC_GROUP_get_degree(g);https://stackoverflow.com/questions/36169789
复制相似问题