Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

elliptic curve - ECDSA signature length

What will the signature length for 256 bit EC key in ECDSA algorithm? I wanted to validated signature length for the same. It will be great if some body can help me with one EC key set.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It depends on how you encode the signature. This is the code segment from OpenSSL that measures the length of ECDSA signature in DER format.

/** 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);
}

The result of the above function with an EC_KEY on prime256 curve as parameter is

sig_len = ECDSA_size(eckey);

where sig_len is 72.

You need 72 bytes for DER encoded ECDSA signature using a 256-bit EC key.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...