diff options
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(); } |