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.
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.
来源:https://stackoverflow.com/questions/17269238/ecdsa-signature-length