Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/boringssl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Langley <agl@chromium.org>2014-07-16 02:15:09 +0400
committerAdam Langley <agl@google.com>2014-07-16 02:26:08 +0400
commit449f16b947bf3df8a0151468d330918378ad8acb (patch)
treeb6d5c809fc72c652b86c2be7ec42bfa257e500be /crypto/ecdsa
parent22f9bccde5ebd742c36f02fe05e45880221b2239 (diff)
Change ECDSA_METHOD's size() to group_order_size()
The |size| method was documented to return the same as |ECDSA_size| - the max size of an ECDSA signature. However, this involves some ASN.1 calculations which is best done once. What custom implementations want to give is the size of the group order on which the ASN.1 computations are based. This change switches the |size| method to allow that. Change-Id: I95b6e0c2b52bfcd0d74850c2c4e9bc01269255e2 Reviewed-on: https://boringssl-review.googlesource.com/1200 Reviewed-by: David Benjamin <davidben@chromium.org> Reviewed-by: Adam Langley <agl@google.com>
Diffstat (limited to 'crypto/ecdsa')
-rw-r--r--crypto/ecdsa/ecdsa_asn1.c44
1 files changed, 24 insertions, 20 deletions
diff --git a/crypto/ecdsa/ecdsa_asn1.c b/crypto/ecdsa/ecdsa_asn1.c
index 9d683617..e54dcca0 100644
--- a/crypto/ecdsa/ecdsa_asn1.c
+++ b/crypto/ecdsa/ecdsa_asn1.c
@@ -69,35 +69,39 @@ DECLARE_ASN1_ENCODE_FUNCTIONS_const(ECDSA_SIG, ECDSA_SIG);
IMPLEMENT_ASN1_FUNCTIONS_const(ECDSA_SIG);
size_t ECDSA_size(const EC_KEY *key) {
- size_t ret, i;
+ size_t ret, i, group_order_size;
ASN1_INTEGER bs;
BIGNUM *order = NULL;
unsigned char buf[4];
const EC_GROUP *group;
- if (key->ecdsa_meth && key->ecdsa_meth->size) {
- return key->ecdsa_meth->size(key);
- }
+ if (key->ecdsa_meth && key->ecdsa_meth->group_order_size) {
+ group_order_size = key->ecdsa_meth->group_order_size(key);
+ } else {
+ size_t num_bits;
- if (key == NULL) {
- return 0;
- }
- group = EC_KEY_get0_group(key);
- if (group == NULL) {
- return 0;
- }
+ if (key == NULL) {
+ return 0;
+ }
+ group = EC_KEY_get0_group(key);
+ if (group == NULL) {
+ return 0;
+ }
- order = BN_new();
- if (order == NULL) {
- return 0;
- }
- if (!EC_GROUP_get_order(group, order, NULL)) {
- BN_clear_free(order);
- return 0;
+ order = BN_new();
+ if (order == NULL) {
+ return 0;
+ }
+ if (!EC_GROUP_get_order(group, order, NULL)) {
+ BN_clear_free(order);
+ return 0;
+ }
+
+ num_bits = BN_num_bits(order);
+ group_order_size = (num_bits + 7) / 8;
}
- i = BN_num_bits(order);
- bs.length = (i + 7) / 8;
+ bs.length = group_order_size;
bs.data = buf;
bs.type = V_ASN1_INTEGER;
/* If the top bit is set the ASN.1 encoding is 1 larger. */