Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 884
Jeet Avatar asked Jun 24 '13 06:06

Jeet


People also ask

How long is RSA signature?

The signature is 1024-bit integer (128 bytes, 256 hex digits). This signature size corresponds to the RSA key size.

What is R and S in ECDSA signature?

First, you need to know that the signature is 40 bytes and is represented by two values of 20 bytes each, the first one is called R and the second one is called S.. so the pair (R, S) together is your ECDSA signature.. now here's how you can create those two values in order to sign a file..

Is ECDSA faster than RSA?

The algorithm, called ECDSA (Elliptic Curve Digital Signature Algorithm), was first proposed by Scott Vanstone in 1992. Signatures based on the algorithm of ECS, the ancestor of ECDSA, have several important advantages over RSA-algorithms: they are smaller in size and are created much faster.

How long is a Bitcoin signature?

A Bitcoin signature using the ECDSA signature scheme is between 71-73 bytes long, and is represented using DER encoding. Bitcoin signatures will always start with the prefix '30'. Inside a signature, two '02' prefixes will precede the R and S values which comprise a signature. ➤ Learn more about Bitcoin transactions.


1 Answers

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
 * \return 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.

like image 68
Chiara Hsieh Avatar answered Nov 12 '22 13:11

Chiara Hsieh