关于椭圆曲线:ECDSA签名长度

ECDSA signature length

ECDSA 算法中 256 位 EC 密钥的签名长度是多少?
我想验证相同的签名长度。如果有人可以帮助我使用一套 EC 密钥,那就太好了。


这取决于您如何对签名进行编码。这是来自 OpenSSL 的代码段,用于测量 DER 格式的 ECDSA 签名的长度。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/** ECDSA_size
 * returns the maximum length of the DER encoded signature
 * \\param  eckey pointer to a EC_KEY object
 * \
eturn numbers of bytes required for the DER encoded signature
 */

int ECDSA_size(const EC_KEY *r)
{
    int ret,i;
    ASN1_INTEGER bs;
    BIGNUM  *order=NULL;
    unsigned char buf[4];
    const EC_GROUP *group;

    if (r == NULL)
        return 0;
    group = EC_KEY_get0_group(r);
    if (group == NULL)
        return 0;

    if ((order = BN_new()) == NULL) return 0;
    if (!EC_GROUP_get_order(group,order,NULL))
    {
        BN_clear_free(order);
        return 0;
    }
    i=BN_num_bits(order);
    bs.length=(i+7)/8;
    bs.data=buf;
    bs.type=V_ASN1_INTEGER;
    /* If the top bit is set the asn1 encoding is 1 larger. */
    buf[0]=0xff;    

    i=i2d_ASN1_INTEGER(&bs,NULL);
    i+=i; /* r and s */
    ret=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
    BN_clear_free(order);
    return(ret);
}

以prime256曲线上的EC_KEY作为参数的上述函数的结果是

1
sig_len = ECDSA_size(eckey);

其中 sig_len 是 72.

对于使用 256 位 EC 密钥的 DER 编码 ECDSA 签名,您需要 72 个字节。