aboutsummaryrefslogtreecommitdiff
path: root/crypto/ecdh_extra
diff options
context:
space:
mode:
authorDavid Benjamin <davidben@google.com>2023-02-13 19:05:19 -0500
committerBoringssl LUCI CQ <boringssl-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-07-11 20:07:57 +0000
commit70be01270bd98169afaeee62f5f73243cb8764cf (patch)
treef01c3940886c53e479780451effeed9a067177be /crypto/ecdh_extra
parentac6793a4251a65a7c0fedcf847a7e081dfdca6ac (diff)
downloadboringssl-70be01270bd98169afaeee62f5f73243cb8764cf.zip
boringssl-70be01270bd98169afaeee62f5f73243cb8764cf.tar.gz
boringssl-70be01270bd98169afaeee62f5f73243cb8764cf.tar.bz2
Use constant curve-specific groups whenever possible
Also remove unnecessary EC_GROUP_free calls. EC_GROUP_free is only necessary in codepaths where arbitrary groups are possible. Bug: 20 Change-Id: I3dfb7f07b890ab002ba8a302724d8bc671590cfe Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/60932 Reviewed-by: Bob Beck <bbe@google.com> Commit-Queue: David Benjamin <davidben@google.com>
Diffstat (limited to 'crypto/ecdh_extra')
-rw-r--r--crypto/ecdh_extra/ecdh_test.cc29
1 files changed, 14 insertions, 15 deletions
diff --git a/crypto/ecdh_extra/ecdh_test.cc b/crypto/ecdh_extra/ecdh_test.cc
index 3948525..ca44375 100644
--- a/crypto/ecdh_extra/ecdh_test.cc
+++ b/crypto/ecdh_extra/ecdh_test.cc
@@ -35,24 +35,23 @@
#include "../test/wycheproof_util.h"
-static bssl::UniquePtr<EC_GROUP> GetCurve(FileTest *t, const char *key) {
+static const EC_GROUP *GetCurve(FileTest *t, const char *key) {
std::string curve_name;
if (!t->GetAttribute(&curve_name, key)) {
return nullptr;
}
if (curve_name == "P-224") {
- return bssl::UniquePtr<EC_GROUP>(EC_GROUP_new_by_curve_name(NID_secp224r1));
+ return EC_group_p224();
}
if (curve_name == "P-256") {
- return bssl::UniquePtr<EC_GROUP>(EC_GROUP_new_by_curve_name(
- NID_X9_62_prime256v1));
+ return EC_group_p256();
}
if (curve_name == "P-384") {
- return bssl::UniquePtr<EC_GROUP>(EC_GROUP_new_by_curve_name(NID_secp384r1));
+ return EC_group_p384();
}
if (curve_name == "P-521") {
- return bssl::UniquePtr<EC_GROUP>(EC_GROUP_new_by_curve_name(NID_secp521r1));
+ return EC_group_p521();
}
t->PrintLine("Unknown curve '%s'", curve_name.c_str());
@@ -70,7 +69,7 @@ static bssl::UniquePtr<BIGNUM> GetBIGNUM(FileTest *t, const char *key) {
TEST(ECDHTest, TestVectors) {
FileTestGTest("crypto/ecdh_extra/ecdh_tests.txt", [](FileTest *t) {
- bssl::UniquePtr<EC_GROUP> group = GetCurve(t, "Curve");
+ const EC_GROUP *group = GetCurve(t, "Curve");
ASSERT_TRUE(group);
bssl::UniquePtr<BIGNUM> priv_key = GetBIGNUM(t, "Private");
ASSERT_TRUE(priv_key);
@@ -87,16 +86,16 @@ TEST(ECDHTest, TestVectors) {
bssl::UniquePtr<EC_KEY> key(EC_KEY_new());
ASSERT_TRUE(key);
- bssl::UniquePtr<EC_POINT> pub_key(EC_POINT_new(group.get()));
+ bssl::UniquePtr<EC_POINT> pub_key(EC_POINT_new(group));
ASSERT_TRUE(pub_key);
- bssl::UniquePtr<EC_POINT> peer_pub_key(EC_POINT_new(group.get()));
+ bssl::UniquePtr<EC_POINT> peer_pub_key(EC_POINT_new(group));
ASSERT_TRUE(peer_pub_key);
- ASSERT_TRUE(EC_KEY_set_group(key.get(), group.get()));
+ ASSERT_TRUE(EC_KEY_set_group(key.get(), group));
ASSERT_TRUE(EC_KEY_set_private_key(key.get(), priv_key.get()));
- ASSERT_TRUE(EC_POINT_set_affine_coordinates_GFp(group.get(), pub_key.get(),
+ ASSERT_TRUE(EC_POINT_set_affine_coordinates_GFp(group, pub_key.get(),
x.get(), y.get(), nullptr));
ASSERT_TRUE(EC_POINT_set_affine_coordinates_GFp(
- group.get(), peer_pub_key.get(), peer_x.get(), peer_y.get(), nullptr));
+ group, peer_pub_key.get(), peer_x.get(), peer_y.get(), nullptr));
ASSERT_TRUE(EC_KEY_set_public_key(key.get(), pub_key.get()));
ASSERT_TRUE(EC_KEY_check_key(key.get()));
@@ -130,7 +129,7 @@ TEST(ECDHTest, TestVectors) {
static void RunWycheproofTest(FileTest *t) {
t->IgnoreInstruction("encoding");
- bssl::UniquePtr<EC_GROUP> group = GetWycheproofCurve(t, "curve", true);
+ const EC_GROUP *group = GetWycheproofCurve(t, "curve", true);
ASSERT_TRUE(group);
bssl::UniquePtr<BIGNUM> priv_key = GetWycheproofBIGNUM(t, "private", false);
ASSERT_TRUE(priv_key);
@@ -157,10 +156,10 @@ static void RunWycheproofTest(FileTest *t) {
bssl::UniquePtr<EC_KEY> key(EC_KEY_new());
ASSERT_TRUE(key);
- ASSERT_TRUE(EC_KEY_set_group(key.get(), group.get()));
+ ASSERT_TRUE(EC_KEY_set_group(key.get(), group));
ASSERT_TRUE(EC_KEY_set_private_key(key.get(), priv_key.get()));
- std::vector<uint8_t> actual((EC_GROUP_get_degree(group.get()) + 7) / 8);
+ std::vector<uint8_t> actual((EC_GROUP_get_degree(group) + 7) / 8);
int ret =
ECDH_compute_key(actual.data(), actual.size(),
EC_KEY_get0_public_key(peer_ec), key.get(), nullptr);