Re: [PATCH] crypto: testmgr - add testvector for pkcs1pad(rsa)

2017-06-19 Thread Herbert Xu
On Mon, Jun 12, 2017 at 11:27:51PM +0200, Stephan Müller wrote:
> The PKCS#1 RSA implementation is provided with a self test with RSA 2048
> and SHA-256. This self test implicitly covers other RSA keys and other
> hashes. Also, this self test implies that the pkcs1pad(rsa) is FIPS
> 140-2 compliant.
> 
> Signed-off-by: Stephan Mueller 

Patch applied.  Thanks.
-- 
Email: Herbert Xu 
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


[PATCH] crypto: testmgr - add testvector for pkcs1pad(rsa)

2017-06-12 Thread Stephan Müller
The PKCS#1 RSA implementation is provided with a self test with RSA 2048
and SHA-256. This self test implicitly covers other RSA keys and other
hashes. Also, this self test implies that the pkcs1pad(rsa) is FIPS
140-2 compliant.

Signed-off-by: Stephan Mueller 
---
 crypto/testmgr.c | 33 ---
 crypto/testmgr.h | 96 
 2 files changed, 125 insertions(+), 4 deletions(-)

diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index 5f8e683..4441273 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -,8 +,11 @@ static int test_akcipher_one(struct crypto_akcipher *tfm,
akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  tcrypt_complete, &result);
 
-   /* Run RSA encrypt - c = m^e mod n;*/
-   err = wait_async_op(&result, crypto_akcipher_encrypt(req));
+   err = wait_async_op(&result, vecs->siggen_sigver_test ?
+/* Run asymmetric signature generation */
+crypto_akcipher_sign(req) :
+/* Run asymmetric encrypt */
+crypto_akcipher_encrypt(req));
if (err) {
pr_err("alg: akcipher: encrypt test failed. err %d\n", err);
goto free_all;
@@ -2261,8 +2264,11 @@ static int test_akcipher_one(struct crypto_akcipher *tfm,
init_completion(&result.completion);
akcipher_request_set_crypt(req, &src, &dst, vecs->c_size, out_len_max);
 
-   /* Run RSA decrypt - m = c^d mod n;*/
-   err = wait_async_op(&result, crypto_akcipher_decrypt(req));
+   err = wait_async_op(&result, vecs->siggen_sigver_test ?
+/* Run asymmetric signature verification */
+crypto_akcipher_verify(req) :
+/* Run asymmetric decrypt */
+crypto_akcipher_decrypt(req));
if (err) {
pr_err("alg: akcipher: decrypt test failed. err %d\n", err);
goto free_all;
@@ -3309,6 +3315,25 @@ static const struct alg_test_desc alg_test_descs[] = {
}
}
}, {
+   .alg = "pkcs1pad(rsa,sha224)",
+   .test = alg_test_null,
+   .fips_allowed = 1,
+   }, {
+   .alg = "pkcs1pad(rsa,sha256)",
+   .test = alg_test_akcipher,
+   .fips_allowed = 1,
+   .suite = {
+   .akcipher = __VECS(pkcs1pad_rsa_tv_template)
+   }
+   }, {
+   .alg = "pkcs1pad(rsa,sha384)",
+   .test = alg_test_null,
+   .fips_allowed = 1,
+   }, {
+   .alg = "pkcs1pad(rsa,sha512)",
+   .test = alg_test_null,
+   .fips_allowed = 1,
+   }, {
.alg = "poly1305",
.test = alg_test_hash,
.suite = {
diff --git a/crypto/testmgr.h b/crypto/testmgr.h
index db2e26c..9188f9e 100644
--- a/crypto/testmgr.h
+++ b/crypto/testmgr.h
@@ -133,6 +133,7 @@ struct akcipher_testvec {
unsigned int m_size;
unsigned int c_size;
bool public_key_vec;
+   bool siggen_sigver_test;
 };
 
 struct kpp_testvec {
@@ -541,6 +542,101 @@ static const struct akcipher_testvec rsa_tv_template[] = {
}
 };
 
+/*
+ * PKCS#1 RSA test vectors. Obtained from CAVS testing.
+ */
+static const struct akcipher_testvec pkcs1pad_rsa_tv_template[] = {
+   {
+   .key =
+   "\x30\x82\x03\x1f\x02\x01\x10\x02\x82\x01\x01\x00\xd7\x1e\x77\x82"
+   "\x8c\x92\x31\xe7\x69\x02\xa2\xd5\x5c\x78\xde\xa2\x0c\x8f\xfe\x28"
+   "\x59\x31\xdf\x40\x9c\x60\x61\x06\xb9\x2f\x62\x40\x80\x76\xcb\x67"
+   "\x4a\xb5\x59\x56\x69\x17\x07\xfa\xf9\x4c\xbd\x6c\x37\x7a\x46\x7d"
+   "\x70\xa7\x67\x22\xb3\x4d\x7a\x94\xc3\xba\x4b\x7c\x4b\xa9\x32\x7c"
+   "\xb7\x38\x95\x45\x64\xa4\x05\xa8\x9f\x12\x7c\x4e\xc6\xc8\x2d\x40"
+   "\x06\x30\xf4\x60\xa6\x91\xbb\x9b\xca\x04\x79\x11\x13\x75\xf0\xae"
+   "\xd3\x51\x89\xc5\x74\xb9\xaa\x3f\xb6\x83\xe4\x78\x6b\xcd\xf9\x5c"
+   "\x4c\x85\xea\x52\x3b\x51\x93\xfc\x14\x6b\x33\x5d\x30\x70\xfa\x50"
+   "\x1b\x1b\x38\x81\x13\x8d\xf7\xa5\x0c\xc0\x8e\xf9\x63\x52\x18\x4e"
+   "\xa9\xf9\xf8\x5c\x5d\xcd\x7a\x0d\xd4\x8e\x7b\xee\x91\x7b\xad\x7d"
+   "\xb4\x92\xd5\xab\x16\x3b\x0a\x8a\xce\x8e\xde\x47\x1a\x17\x01\x86"
+   "\x7b\xab\x99\xf1\x4b\x0c\x3a\x0d\x82\x47\xc1\x91\x8c\xbb\x2e\x22"
+   "\x9e\x49\x63\x6e\x02\xc1\xc9\x3a\x9b\xa5\x22\x1b\x07\x95\xd6\x10"
+   "\x02\x50\xfd\xfd\xd1\x9b\xbe\xab\xc2\xc0\x74\xd7\xec\x00\xfb\x11"
+   "\x71\xcb\x7a\xdc\x81\x79\x9f\x86\x68\x46\x63\x82\x4d\xb7\xf1\xe6"
+   "\x16\x6f\x42\x63\xf4\x94\xa0\xca\x33\xcc\x75\x13\x02\x82\x01\x00"
+   "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
+   "\x00\x00\x