diff options
author | Dr. Stephen Henson <steve@openssl.org> | 2015-10-27 19:34:17 +0000 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 2015-12-09 22:09:19 +0000 |
commit | cf517a6d3d2548b1a79155df5c384f4a4b3924d6 (patch) | |
tree | b766f06cc865aaa6f7aa9f06898eddcc76f1b41a | |
parent | c535979126bb344420e6ce6654e050f6af6ae599 (diff) | |
download | openssl-new-cf517a6d3d2548b1a79155df5c384f4a4b3924d6.tar.gz |
add ECDSA_size to ec_asn1.c
Reviewed-by: Richard Levitte <levitte@openssl.org>
-rw-r--r-- | crypto/ec/ec_asn1.c | 34 | ||||
-rw-r--r-- | include/openssl/ec.h | 6 |
2 files changed, 40 insertions, 0 deletions
diff --git a/crypto/ec/ec_asn1.c b/crypto/ec/ec_asn1.c index 8bd2de4e14..99d081440c 100644 --- a/crypto/ec/ec_asn1.c +++ b/crypto/ec/ec_asn1.c @@ -1319,3 +1319,37 @@ void ECDSA_SIG_get0(BIGNUM **pr, BIGNUM **ps, ECDSA_SIG *sig) if (ps) *ps = sig->s; } + +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); +} diff --git a/include/openssl/ec.h b/include/openssl/ec.h index ed1fea9575..f0f2ba60df 100644 --- a/include/openssl/ec.h +++ b/include/openssl/ec.h @@ -1089,6 +1089,12 @@ int ECDSA_sign_ex(int type, const unsigned char *dgst, int dgstlen, int ECDSA_verify(int type, const unsigned char *dgst, int dgstlen, const unsigned char *sig, int siglen, EC_KEY *eckey); +/** Returns the maximum length of the DER encoded signature + * \param eckey EC_KEY object + * \return numbers of bytes required for the DER encoded signature + */ +int ECDSA_size(const EC_KEY *eckey); + # define ECParameters_dup(x) ASN1_dup_of(EC_KEY,i2d_ECParameters,d2i_ECParameters,x) # ifndef __cplusplus |