diff options
author | David Benjamin <davidben@google.com> | 2016-08-07 20:32:49 +0300 |
---|---|---|
committer | CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org> | 2016-08-16 21:52:42 +0300 |
commit | 161ef92c39a2c52410d3d0833f2422f6ff8b942c (patch) | |
tree | 1d801003ea63eb266d55912a2af30f9c9c1d68d2 /crypto | |
parent | 7d7afc3b89798e7df87a8044e465c83b17fd498d (diff) |
Inline ec_group_copy and simplify.
A lot of codepaths are unreachable since the EC_GROUP is known to be
blank.
Change-Id: I5829934762e503241aa73f833c982ad9680d8856
Reviewed-on: https://boringssl-review.googlesource.com/10344
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
Commit-Queue: David Benjamin <davidben@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/ec/ec.c | 75 |
1 files changed, 23 insertions, 52 deletions
diff --git a/crypto/ec/ec.c b/crypto/ec/ec.c index 75e906bd..9ddd3bd5 100644 --- a/crypto/ec/ec.c +++ b/crypto/ec/ec.c @@ -525,74 +525,45 @@ void EC_GROUP_free(EC_GROUP *group) { OPENSSL_free(group); } -int ec_group_copy(EC_GROUP *dest, const EC_GROUP *src) { - if (dest->meth->group_copy == 0) { - OPENSSL_PUT_ERROR(EC, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); - return 0; - } - if (dest->meth != src->meth) { - OPENSSL_PUT_ERROR(EC, EC_R_INCOMPATIBLE_OBJECTS); - return 0; - } - if (dest == src) { - return 1; - } - - dest->mont_data = src->mont_data; - - if (src->generator != NULL) { - if (dest->generator == NULL) { - dest->generator = EC_POINT_new(dest); - if (dest->generator == NULL) { - return 0; - } - } - if (!EC_POINT_copy(dest->generator, src->generator)) { - return 0; - } - } else { - EC_POINT_clear_free(dest->generator); - dest->generator = NULL; - } - - if (!BN_copy(&dest->order, &src->order)) { - return 0; - } - - dest->curve_name = src->curve_name; - - return dest->meth->group_copy(dest, src); -} - const BN_MONT_CTX *ec_group_get_mont_data(const EC_GROUP *group) { return group->mont_data; } EC_GROUP *EC_GROUP_dup(const EC_GROUP *a) { - EC_GROUP *t = NULL; - int ok = 0; - if (a == NULL) { return NULL; } - t = ec_group_new(a->meth); - if (t == NULL) { + if (a->meth->group_copy == NULL) { + OPENSSL_PUT_ERROR(EC, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); + return NULL; + } + + EC_GROUP *ret = ec_group_new(a->meth); + if (ret == NULL) { return NULL; } - if (!ec_group_copy(t, a)) { + + ret->mont_data = a->mont_data; + ret->curve_name = a->curve_name; + + if (a->generator != NULL) { + ret->generator = EC_POINT_dup(a->generator, ret); + if (ret->generator == NULL) { + goto err; + } + } + + if (!BN_copy(&ret->order, &a->order) || + !ret->meth->group_copy(ret, a)) { goto err; } - ok = 1; + return ret; err: - if (!ok) { - EC_GROUP_free(t); - return NULL; - } else { - return t; - } + EC_GROUP_free(ret); + return NULL; } int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ignored) { |