Skip to content

Commit ed46cde

Browse files
committed
updated rsa_method test with checks for out_len
1 parent d21e674 commit ed46cde

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

crypto/rsa_extra/rsa_test.cc

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -992,25 +992,25 @@ TEST(RSATest, CheckKey) {
992992
static int rsa_priv_enc(int max_out, const uint8_t *from, uint8_t *to, RSA *rsa,
993993
int padding) {
994994
RSA_set_ex_data(rsa, 0, (void*)"rsa_priv_enc");
995-
return 1;
995+
return 0;
996996
}
997997

998998
static int rsa_priv_dec(int max_out, const uint8_t *from, uint8_t *to, RSA *rsa,
999999
int padding) {
10001000
RSA_set_ex_data(rsa, 0, (void*)"rsa_priv_dec");
1001-
return 1;
1001+
return 0;
10021002
}
10031003

10041004
static int rsa_pub_enc(int max_out, const uint8_t *from, uint8_t *to, RSA *rsa,
10051005
int padding) {
10061006
RSA_set_ex_data(rsa, 0, (void*)"rsa_pub_enc");
1007-
return 1;
1007+
return 0;
10081008
}
10091009

10101010
static int rsa_pub_dec(int max_out, const uint8_t *from, uint8_t *to, RSA *rsa,
10111011
int padding) {
10121012
RSA_set_ex_data(rsa, 0, (void*)"rsa_pub_dec");
1013-
return 1;
1013+
return 0;
10141014
}
10151015

10161016
static int extkey_rsa_finish (RSA *rsa) {
@@ -1038,9 +1038,9 @@ TEST(RSATest, RSAMETHOD) {
10381038
ASSERT_TRUE(RSA_meth_set_pub_dec(rsa_meth, rsa_pub_dec));
10391039
ASSERT_TRUE(RSA_meth_set_priv_enc(rsa_meth, rsa_priv_enc));
10401040
ASSERT_TRUE(RSA_meth_set_priv_dec(rsa_meth, rsa_priv_dec));
1041-
ASSERT_TRUE(RSA_meth_set_init(rsa_meth, NULL));
1041+
ASSERT_TRUE(RSA_meth_set_init(rsa_meth, nullptr));
10421042
ASSERT_TRUE(RSA_meth_set_finish(rsa_meth, extkey_rsa_finish));
1043-
ASSERT_TRUE(RSA_meth_set0_app_data(rsa_meth, NULL));
1043+
ASSERT_TRUE(RSA_meth_set0_app_data(rsa_meth, nullptr));
10441044

10451045
ASSERT_TRUE(rsa_meth->decrypt && rsa_meth->encrypt && rsa_meth->sign_raw &&
10461046
rsa_meth->verify_raw);
@@ -1062,20 +1062,36 @@ TEST(RSATest, RSAMETHOD) {
10621062
uint8_t in, out;
10631063
ASSERT_TRUE(EVP_PKEY_encrypt_init(rsa_key_ctx.get()));
10641064
ASSERT_TRUE(EVP_PKEY_encrypt(rsa_key_ctx.get(), &out, &out_len, &in, 0));
1065+
// Custom func return 0 since they don't write any data to out
1066+
ASSERT_EQ(out_len, (size_t)0);
10651067
ASSERT_STREQ(static_cast<const char*>(RSA_get_ex_data(key, 0))
10661068
, "rsa_pub_enc");
1069+
1070+
// Update before passing into next operation
1071+
out_len = EVP_PKEY_size(rsa_key.get());
10671072
ASSERT_TRUE(EVP_PKEY_decrypt_init(rsa_key_ctx.get()));
10681073
ASSERT_TRUE(EVP_PKEY_decrypt(rsa_key_ctx.get(), &out, &out_len, &in, 0));
1074+
// Custom func return 0 since they don't write any data to out
1075+
ASSERT_EQ(out_len, (size_t)0);
10691076
ASSERT_STREQ(static_cast<const char*>(RSA_get_ex_data(key, 0))
10701077
, "rsa_priv_dec");
10711078

1079+
// Update before passing into next operation
1080+
out_len = EVP_PKEY_size(rsa_key.get());
10721081
ASSERT_TRUE(EVP_PKEY_verify_recover_init(rsa_key_ctx.get()));
1073-
ASSERT_TRUE(EVP_PKEY_verify_recover(rsa_key_ctx.get(), &out, &out_len, NULL, 0));
1082+
ASSERT_TRUE(EVP_PKEY_verify_recover(rsa_key_ctx.get(), &out, &out_len,
1083+
nullptr, 0));
1084+
// Custom func return 0 since they don't write any data to out
1085+
ASSERT_EQ(out_len, (size_t)0);
10741086
ASSERT_STREQ(static_cast<const char*>(RSA_get_ex_data(key, 0))
10751087
, "rsa_pub_dec");
10761088

1089+
// Update before passing into next operation
1090+
out_len = EVP_PKEY_size(rsa_key.get());
10771091
// This operation is not plumbed through EVP_PKEY API in OpenSSL or AWS-LC
1078-
ASSERT_TRUE(RSA_sign_raw(key, &out_len, &out, 0, NULL, 0, 0));
1092+
ASSERT_TRUE(RSA_sign_raw(key, &out_len, &out, 0, nullptr, 0, 0));
1093+
// Custom func return 0 since they don't write any data to out
1094+
ASSERT_EQ(out_len, (size_t)0);
10791095
ASSERT_STREQ(static_cast<const char*>(RSA_get_ex_data(key, 0))
10801096
, "rsa_priv_enc");
10811097
}

0 commit comments

Comments
 (0)