diff options
author | Yi Chou <yich@google.com> | 2023-05-05 10:18:41 +0800 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-05-16 12:34:56 +0000 |
commit | d20b09e533f7190284df1f60c60b9430f7ba0dd5 (patch) | |
tree | 7a3d34beefea818b97de3a38741ff7c4e1e31c8e /test/boringssl_crypto.cc | |
parent | 28939ffb30bdb1d9e6386cf390c982922ea9253d (diff) | |
download | chrome-ec-d20b09e533f7190284df1f60c60b9430f7ba0dd5.tar.gz |
boringssl: Add elliptic curve key helpers
BUG=b:248508087
TEST=make V=1 BOARD=bloonchipper -j
TEST=./test/run_device_tests.py --board bloonchipper -t boringssl_crypto
=> PASS
TEST=./test/run_device_tests.py --board dartmonkey -t boringssl_crypto
=> PASS
Change-Id: Ifdca7743c09910d413407be986e9d959e5b90479
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4505560
Tested-by: Yi Chou <yich@google.com>
Commit-Queue: Yi Chou <yich@google.com>
Reviewed-by: Tom Hughes <tomhughes@chromium.org>
Diffstat (limited to 'test/boringssl_crypto.cc')
-rw-r--r-- | test/boringssl_crypto.cc | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/boringssl_crypto.cc b/test/boringssl_crypto.cc index bc7bd5dffe..c04b391854 100644 --- a/test/boringssl_crypto.cc +++ b/test/boringssl_crypto.cc @@ -4,6 +4,7 @@ */ #include "common.h" +#include "crypto/elliptic_curve_key.h" #include "openssl/bn.h" #include "openssl/ec.h" #include "openssl/mem.h" @@ -28,8 +29,38 @@ test_static enum ec_error_list test_rand(void) return EC_SUCCESS; } +test_static enum ec_error_list test_ecc_keygen(void) +{ + bssl::UniquePtr<EC_KEY> key1 = generate_elliptic_curve_key(); + + TEST_NE(key1.get(), nullptr, "%p"); + + /* The generated key should be valid.*/ + TEST_EQ(EC_KEY_check_key(key1.get()), 1, "%d"); + + bssl::UniquePtr<EC_KEY> key2 = generate_elliptic_curve_key(); + + TEST_NE(key2.get(), nullptr, "%p"); + + /* The generated key should be valid. */ + TEST_EQ(EC_KEY_check_key(key2.get()), 1, "%d"); + + const BIGNUM *priv1 = EC_KEY_get0_private_key(key1.get()); + const BIGNUM *priv2 = EC_KEY_get0_private_key(key2.get()); + + /* The generated keys should not be the same. */ + TEST_NE(BN_cmp(priv1, priv2), 0, "%d"); + + /* The generated keys should not be zero. */ + TEST_EQ(BN_is_zero(priv1), 0, "%d"); + TEST_EQ(BN_is_zero(priv2), 0, "%d"); + + return EC_SUCCESS; +} + extern "C" void run_test(int argc, const char **argv) { RUN_TEST(test_rand); + RUN_TEST(test_ecc_keygen); test_print_result(); } |