test_suite_rsa.function: add tests
Signed-off-by: Yanray Wang <yanray.wang@arm.com>
diff --git a/tests/suites/test_suite_rsa.data b/tests/suites/test_suite_rsa.data
index 2be9399..ef2a60b 100644
--- a/tests/suites/test_suite_rsa.data
+++ b/tests/suites/test_suite_rsa.data
@@ -7,6 +7,46 @@
RSA init-free-init-free
rsa_init_free:1
+RSA retrieves context with PKCS#1 v1.5 and None MD
+depends_on:MBEDTLS_PKCS1_V15
+# MBEDTLS_RSA_PKCS_V15:MBEDTLS_MD_NONE
+rsa_ctx_param_validation:0:0
+
+RSA retrieves context with PKCS#1 v1.5 and MD5
+depends_on:MBEDTLS_PKCS1_V15:MBEDTLS_HAS_ALG_MD5_VIA_LOWLEVEL_OR_PSA
+# MBEDTLS_RSA_PKCS_V15:MBEDTLS_MD_MD5
+rsa_ctx_param_validation:0:1
+
+RSA retrieves context with PKCS#1 v1.5 and SHA-256
+depends_on:MBEDTLS_PKCS1_V15:MBEDTLS_HAS_ALG_SHA_256_VIA_LOWLEVEL_OR_PSA
+# MBEDTLS_RSA_PKCS_V15:MBEDTLS_MD_SHA256
+rsa_ctx_param_validation:0:4
+
+RSA retrieves context with PKCS#1 v1.5 and RIPEMD-160
+depends_on:MBEDTLS_PKCS1_V15:MBEDTLS_HAS_ALG_RIPEMD160_VIA_LOWLEVEL_OR_PSA
+# MBEDTLS_RSA_PKCS_V15:MBEDTLS_MD_RIPEMD160
+rsa_ctx_param_validation:0:7
+
+RSA retrieves context with PKCS#1 v2.1 and SHA1
+depends_on:MBEDTLS_PKCS1_V21:MBEDTLS_HAS_ALG_SHA_1_VIA_LOWLEVEL_OR_PSA
+# MBEDTLS_RSA_PKCS_V21:MBEDTLS_MD_SHA1
+rsa_ctx_param_validation:1:2
+
+RSA retrieves context with PKCS#1 v2.1 and SHA224
+depends_on:MBEDTLS_PKCS1_V21:MBEDTLS_HAS_ALG_SHA_224_VIA_LOWLEVEL_OR_PSA
+# MBEDTLS_RSA_PKCS_V21:MBEDTLS_MD_SHA224
+rsa_ctx_param_validation:1:3
+
+RSA retrieves context with PKCS#1 v2.1 and SHA384
+depends_on:MBEDTLS_PKCS1_V21:MBEDTLS_HAS_ALG_SHA_384_VIA_LOWLEVEL_OR_PSA
+# MBEDTLS_RSA_PKCS_V21:MBEDTLS_MD_SHA384
+rsa_ctx_param_validation:1:5
+
+RSA retrieves context with PKCS#1 v2.1 and SHA512
+depends_on:MBEDTLS_PKCS1_V21:MBEDTLS_HAS_ALG_SHA_512_VIA_LOWLEVEL_OR_PSA
+# MBEDTLS_RSA_PKCS_V21:MBEDTLS_MD_SHA512
+rsa_ctx_param_validation:1:6
+
RSA PKCS1 Verify v1.5 CAVS #1
depends_on:MBEDTLS_HAS_ALG_SHA_1_VIA_LOWLEVEL_OR_PSA:MBEDTLS_PKCS1_V15
# Good padding but wrong hash
diff --git a/tests/suites/test_suite_rsa.function b/tests/suites/test_suite_rsa.function
index a2fe6c8..deb156e 100644
--- a/tests/suites/test_suite_rsa.function
+++ b/tests/suites/test_suite_rsa.function
@@ -26,11 +26,17 @@
MBEDTLS_MD_NONE),
MBEDTLS_ERR_RSA_INVALID_PADDING);
+ TEST_EQUAL(mbedtls_rsa_get_padding_mode(&ctx), MBEDTLS_RSA_PKCS_V15);
+ TEST_EQUAL(mbedtls_rsa_get_hash_id(&ctx), MBEDTLS_MD_NONE);
+
TEST_EQUAL(mbedtls_rsa_set_padding(&ctx,
MBEDTLS_RSA_PKCS_V21,
invalid_hash_id),
MBEDTLS_ERR_RSA_INVALID_PADDING);
+ TEST_EQUAL(mbedtls_rsa_get_padding_mode(&ctx), MBEDTLS_RSA_PKCS_V15);
+ TEST_EQUAL(mbedtls_rsa_get_hash_id(&ctx), MBEDTLS_MD_NONE);
+
TEST_EQUAL(mbedtls_rsa_pkcs1_sign(&ctx, NULL,
NULL, MBEDTLS_MD_NONE,
buf_len,
@@ -58,6 +64,9 @@
MBEDTLS_RSA_PKCS_V15,
MBEDTLS_MD_NONE),
MBEDTLS_ERR_RSA_INVALID_PADDING);
+
+ TEST_EQUAL(mbedtls_rsa_get_padding_mode(&ctx), MBEDTLS_RSA_PKCS_V15);
+ TEST_EQUAL(mbedtls_rsa_get_hash_id(&ctx), MBEDTLS_MD_NONE);
#endif
#if defined(MBEDTLS_PKCS1_V15)
@@ -91,6 +100,9 @@
MBEDTLS_RSA_PKCS_V21,
MBEDTLS_MD_NONE),
MBEDTLS_ERR_RSA_INVALID_PADDING);
+
+ TEST_EQUAL(mbedtls_rsa_get_padding_mode(&ctx), MBEDTLS_RSA_PKCS_V15);
+ TEST_EQUAL(mbedtls_rsa_get_hash_id(&ctx), MBEDTLS_MD_NONE);
#endif
#if defined(MBEDTLS_PKCS1_V21)
@@ -159,6 +171,25 @@
/* END_CASE */
/* BEGIN_CASE */
+void rsa_ctx_param_validation(int padding_mode, int hash_id)
+{
+ mbedtls_rsa_context ctx;
+
+ mbedtls_rsa_init(&ctx);
+
+ TEST_ASSERT(mbedtls_rsa_set_padding(&ctx,
+ padding_mode,
+ hash_id) == 0);
+
+ TEST_ASSERT(mbedtls_rsa_get_padding_mode(&ctx) == padding_mode);
+ TEST_ASSERT(mbedtls_rsa_get_hash_id(&ctx) == hash_id);
+
+exit:
+ mbedtls_rsa_free(&ctx);
+}
+/* END_CASE */
+
+/* BEGIN_CASE */
void mbedtls_rsa_pkcs1_sign(data_t *message_str, int padding_mode,
int digest, int mod, char *input_P,
char *input_Q, char *input_N, char *input_E,