summaryrefslogtreecommitdiffstats
path: root/providers/fips/self_test_data.inc
diff options
context:
space:
mode:
authorShane Lontis <shane.lontis@oracle.com>2020-09-16 14:10:23 +1000
committerShane Lontis <shane.lontis@oracle.com>2020-09-16 14:10:23 +1000
commit4343a4187d28d719006642a610afea6e186832bf (patch)
tree1dfeffe1ad5f1b6e823163d7e1c21657c3307eb8 /providers/fips/self_test_data.inc
parenta268ed3acf16948c0e19ba67b2b3f89b3312a416 (diff)
Add self tests for rsa encryption
SP800-56br2 requires seperate KAT's (fips self tests) to be tested for both encryption and decryption using the RSA primitive (i.e. no padding). This is specified in FIPS140-2 IG D.9 A copy of the methods EVP_PKEY_encrypt_init(), EVP_PKEY_encrypt(), EVP_PKEY_decrypt_init(), EVP_PKEY_decrypt() are now in the fips module. Removed the #ifdef FIPS_MODULE in evp_pkey_ctx_free_old_ops(). Added corruption test Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org> (Merged from https://github.com/openssl/openssl/pull/12835)
Diffstat (limited to 'providers/fips/self_test_data.inc')
-rw-r--r--providers/fips/self_test_data.inc106
1 files changed, 104 insertions, 2 deletions
diff --git a/providers/fips/self_test_data.inc b/providers/fips/self_test_data.inc
index 17bfc950db..8a4b6fcee0 100644
--- a/providers/fips/self_test_data.inc
+++ b/providers/fips/self_test_data.inc
@@ -101,6 +101,18 @@ typedef struct st_kat_sign_st {
size_t sig_expected_len;
} ST_KAT_SIGN;
+typedef struct st_kat_asym_cipher_st {
+ const char *desc;
+ const char *algorithm;
+ int encrypt;
+ const ST_KAT_PARAM *key;
+ const ST_KAT_PARAM *postinit;
+ const unsigned char *in;
+ size_t in_len;
+ const unsigned char *expected;
+ size_t expected_len;
+} ST_KAT_ASYM_CIPHER;
+
/*- DIGEST TEST DATA */
static const unsigned char sha1_pt[] = "abc";
static const unsigned char sha1_digest[] = {
@@ -943,7 +955,7 @@ static const unsigned char rsa_qInv[] = {
0xF8, 0xF3, 0x95, 0xFE, 0x31, 0x25, 0x50, 0x12
};
-static const ST_KAT_PARAM rsa_key[] = {
+static const ST_KAT_PARAM rsa_crt_key[] = {
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_RSA_N, rsa_n),
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_RSA_E, rsa_e),
ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_RSA_D, rsa_d),
@@ -955,6 +967,25 @@ static const ST_KAT_PARAM rsa_key[] = {
ST_KAT_PARAM_END()
};
+static const ST_KAT_PARAM rsa_pub_key[] = {
+ ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_RSA_N, rsa_n),
+ ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_RSA_E, rsa_e),
+ ST_KAT_PARAM_END()
+};
+
+static const ST_KAT_PARAM rsa_priv_key[] = {
+ ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_RSA_N, rsa_n),
+ ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_RSA_E, rsa_e),
+ ST_KAT_PARAM_BIGNUM(OSSL_PKEY_PARAM_RSA_D, rsa_d),
+ ST_KAT_PARAM_END()
+};
+
+static const ST_KAT_PARAM rsa_enc_params[] = {
+ ST_KAT_PARAM_UTF8STRING(OSSL_ASYM_CIPHER_PARAM_PAD_MODE,
+ OSSL_PKEY_RSA_PAD_MODE_NONE),
+ ST_KAT_PARAM_END()
+};
+
static const unsigned char rsa_expected_sig[256] = {
0xad, 0xbe, 0x2a, 0xaf, 0x16, 0x85, 0xc5, 0x00,
0x91, 0x3e, 0xd0, 0x49, 0xfb, 0x3a, 0x81, 0xb9,
@@ -990,6 +1021,45 @@ static const unsigned char rsa_expected_sig[256] = {
0x2c, 0x68, 0xf0, 0x37, 0xa9, 0xd2, 0x56, 0xd6
};
+static const unsigned char rsa_asym_plaintext_encrypt[256] = {
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+ 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x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, 0x04, 0xad, 0xaa,
+ 0x11, 0x6c, 0x8f, 0xce, 0x83, 0x29, 0x56, 0x69,
+ 0xbb, 0x00, 0x3b, 0xef, 0xca, 0x2d, 0xcd, 0x52,
+ 0xc8, 0xf1, 0xb3, 0x9b, 0xb4, 0x4f, 0x6d, 0x9c,
+ 0x3d, 0x69, 0xcc, 0x6d, 0x1f, 0x38, 0x4d, 0xe6,
+ 0xbb, 0x0c, 0x87, 0xdc, 0x5f, 0xa9, 0x24, 0x93,
+ 0x03, 0x46, 0xa2, 0x33, 0x6c, 0xf4, 0xd8, 0x5d,
+ 0x68, 0xf3, 0xd3, 0xe0, 0xf2, 0x30, 0xdb, 0xf5,
+ 0x4f, 0x0f, 0xad, 0xc7, 0xd0, 0xaa, 0x47, 0xd9,
+ 0x9f, 0x85, 0x1b, 0x2e, 0x6c, 0x3c, 0x57, 0x04,
+ 0x29, 0xf4, 0xf5, 0x66, 0x7d, 0x93, 0x4a, 0xaa,
+ 0x05, 0x52, 0x55, 0xc1, 0xc6, 0x06, 0x90, 0xab,
+};
+
#endif /* OPENSSL_NO_RSA */
#ifndef OPENSSL_NO_EC
@@ -1153,7 +1223,7 @@ static const ST_KAT_SIGN st_kat_sign_tests[] = {
OSSL_SELF_TEST_DESC_SIGN_RSA,
"RSA",
"SHA-256",
- rsa_key,
+ rsa_crt_key,
ITM(rsa_expected_sig)
},
#endif /* OPENSSL_NO_RSA */
@@ -1182,3 +1252,35 @@ static const ST_KAT_SIGN st_kat_sign_tests[] = {
},
#endif /* OPENSSL_NO_DSA */
};
+
+static const ST_KAT_ASYM_CIPHER st_kat_asym_cipher_tests[] = {
+#ifndef OPENSSL_NO_RSA
+ {
+ OSSL_SELF_TEST_DESC_ASYM_RSA_ENC,
+ "RSA",
+ 1,
+ rsa_pub_key,
+ rsa_enc_params,
+ ITM(rsa_asym_plaintext_encrypt),
+ ITM(rsa_asym_expected_encrypt),
+ },
+ {
+ OSSL_SELF_TEST_DESC_ASYM_RSA_DEC,
+ "RSA",
+ 0,
+ rsa_priv_key,
+ rsa_enc_params,
+ ITM(rsa_asym_expected_encrypt),
+ ITM(rsa_asym_plaintext_encrypt),
+ },
+ {
+ OSSL_SELF_TEST_DESC_ASYM_RSA_DEC,
+ "RSA",
+ 0,
+ rsa_crt_key,
+ rsa_enc_params,
+ ITM(rsa_asym_expected_encrypt),
+ ITM(rsa_asym_plaintext_encrypt),
+ },
+#endif /* OPENSSL_NO_RSA */
+};