Skip to content

Commit

Permalink
added engine testing
Browse files Browse the repository at this point in the history
  • Loading branch information
smittals2 committed Sep 6, 2024
1 parent dd6cc75 commit 685de40
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
26 changes: 26 additions & 0 deletions crypto/fipsmodule/ec/ec_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2525,3 +2525,29 @@ TEST(ECTest, ECKEYMETHOD) {
EC_KEY_METHOD_set_flags(ec_method, ECDSA_FLAG_OPAQUE);
ASSERT_TRUE(EC_KEY_is_opaque(ec));
}

TEST(ECTest, ECEngine) {
ENGINE *engine = ENGINE_new();
ASSERT_TRUE(engine);
ASSERT_FALSE(ENGINE_get_EC(engine));

EC_KEY_METHOD *eng_funcs = EC_KEY_METHOD_new(NULL);
ASSERT_TRUE(eng_funcs);
EC_KEY_METHOD_set_sign(eng_funcs, NULL, NULL, ecdsa_sign_sig);

ASSERT_TRUE(ENGINE_set_EC(engine, eng_funcs));
ASSERT_TRUE(ENGINE_get_EC(engine));

EC_KEY *key = EC_KEY_new_method(engine);
ASSERT_TRUE(key);

// Call custom Engine implementation
ECDSA_do_sign(NULL, 0, key);
ASSERT_STREQ(static_cast<const char*>(EC_KEY_get_ex_data(key, 1))
, "ecdsa_sign_sig");

EC_KEY_free(key);
ENGINE_free(engine);
EC_KEY_METHOD_free(eng_funcs);
}

28 changes: 28 additions & 0 deletions crypto/rsa_extra/rsa_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,34 @@ TEST(RSATest, RSAMETHOD) {
, "rsa_priv_enc");
}

TEST(RSATest, RSAEngine) {
ENGINE *engine = ENGINE_new();
ASSERT_TRUE(engine);
ASSERT_FALSE(ENGINE_get_RSA(engine));

RSA_METHOD *eng_funcs = RSA_meth_new(NULL, 0);
ASSERT_TRUE(eng_funcs);
ASSERT_TRUE(RSA_meth_set_priv_dec(eng_funcs, rsa_priv_dec));

ASSERT_TRUE(ENGINE_set_RSA(engine, eng_funcs));
ASSERT_TRUE(ENGINE_get_RSA(engine));

RSA *key = RSA_new_method(engine);
ASSERT_TRUE(key);

size_t out_len = 16;
uint8_t in, out;
// Call custom Engine implementation
ASSERT_TRUE(RSA_decrypt(key, &out_len, &out, out_len, &in, 0, 0));
ASSERT_EQ(out_len, (size_t)0);
ASSERT_STREQ(static_cast<const char*>(RSA_get_ex_data(key, 0))
, "rsa_priv_dec");

RSA_free(key);
ENGINE_free(engine);
RSA_meth_free(eng_funcs);
}

#if !defined(AWSLC_FIPS)

TEST(RSATest, KeygenFail) {
Expand Down

0 comments on commit 685de40

Please sign in to comment.