crypto: aead - Remove blkcipher null for IV generators
[cascardo/linux.git] / crypto / testmgr.c
index ff79eb8..769cc2a 100644 (file)
@@ -1911,8 +1911,8 @@ static int alg_test_kpp(const struct alg_test_desc *desc, const char *driver,
        return err;
 }
 
-static int do_test_rsa(struct crypto_akcipher *tfm,
-                      struct akcipher_testvec *vecs)
+static int test_akcipher_one(struct crypto_akcipher *tfm,
+                            struct akcipher_testvec *vecs)
 {
        char *xbuf[XBUFSIZE];
        struct akcipher_request *req;
@@ -1941,6 +1941,7 @@ static int do_test_rsa(struct crypto_akcipher *tfm,
        if (err)
                goto free_req;
 
+       err = -ENOMEM;
        out_len_max = crypto_akcipher_maxsize(tfm);
        outbuf_enc = kzalloc(out_len_max, GFP_KERNEL);
        if (!outbuf_enc)
@@ -1963,17 +1964,18 @@ static int do_test_rsa(struct crypto_akcipher *tfm,
        /* Run RSA encrypt - c = m^e mod n;*/
        err = wait_async_op(&result, crypto_akcipher_encrypt(req));
        if (err) {
-               pr_err("alg: rsa: encrypt test failed. err %d\n", err);
+               pr_err("alg: akcipher: encrypt test failed. err %d\n", err);
                goto free_all;
        }
        if (req->dst_len != vecs->c_size) {
-               pr_err("alg: rsa: encrypt test failed. Invalid output len\n");
+               pr_err("alg: akcipher: encrypt test failed. Invalid output len\n");
                err = -EINVAL;
                goto free_all;
        }
        /* verify that encrypted message is equal to expected */
        if (memcmp(vecs->c, outbuf_enc, vecs->c_size)) {
-               pr_err("alg: rsa: encrypt test failed. Invalid output\n");
+               pr_err("alg: akcipher: encrypt test failed. Invalid output\n");
+               hexdump(outbuf_enc, vecs->c_size);
                err = -EINVAL;
                goto free_all;
        }
@@ -2001,18 +2003,22 @@ static int do_test_rsa(struct crypto_akcipher *tfm,
        /* Run RSA decrypt - m = c^d mod n;*/
        err = wait_async_op(&result, crypto_akcipher_decrypt(req));
        if (err) {
-               pr_err("alg: rsa: decrypt test failed. err %d\n", err);
+               pr_err("alg: akcipher: decrypt test failed. err %d\n", err);
                goto free_all;
        }
        out_len = req->dst_len;
-       if (out_len != vecs->m_size) {
-               pr_err("alg: rsa: decrypt test failed. Invalid output len\n");
+       if (out_len < vecs->m_size) {
+               pr_err("alg: akcipher: decrypt test failed. "
+                      "Invalid output len %u\n", out_len);
                err = -EINVAL;
                goto free_all;
        }
        /* verify that decrypted message is equal to the original msg */
-       if (memcmp(vecs->m, outbuf_dec, vecs->m_size)) {
-               pr_err("alg: rsa: decrypt test failed. Invalid output\n");
+       if (memchr_inv(outbuf_dec, 0, out_len - vecs->m_size) ||
+           memcmp(vecs->m, outbuf_dec + out_len - vecs->m_size,
+                  vecs->m_size)) {
+               pr_err("alg: akcipher: decrypt test failed. Invalid output\n");
+               hexdump(outbuf_dec, out_len);
                err = -EINVAL;
        }
 free_all:
@@ -2025,28 +2031,20 @@ free_xbuf:
        return err;
 }
 
-static int test_rsa(struct crypto_akcipher *tfm, struct akcipher_testvec *vecs,
-                   unsigned int tcount)
+static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
+                        struct akcipher_testvec *vecs, unsigned int tcount)
 {
        int ret, i;
 
        for (i = 0; i < tcount; i++) {
-               ret = do_test_rsa(tfm, vecs++);
-               if (ret) {
-                       pr_err("alg: rsa: test failed on vector %d, err=%d\n",
-                              i + 1, ret);
-                       return ret;
-               }
-       }
-       return 0;
-}
-
-static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
-                        struct akcipher_testvec *vecs, unsigned int tcount)
-{
-       if (strncmp(alg, "rsa", 3) == 0)
-               return test_rsa(tfm, vecs, tcount);
+               ret = test_akcipher_one(tfm, vecs++);
+               if (!ret)
+                       continue;
 
+               pr_err("alg: akcipher: test failed on vector %d, err=%d\n",
+                      i + 1, ret);
+               return ret;
+       }
        return 0;
 }
 
@@ -3300,6 +3298,16 @@ static const struct alg_test_desc alg_test_descs[] = {
                                }
                        }
                }
+       }, {
+               .alg = "ecdh",
+               .test = alg_test_kpp,
+               .fips_allowed = 1,
+               .suite = {
+                       .kpp = {
+                               .vecs = ecdh_tv_template,
+                               .count = ECDH_TEST_VECTORS
+                       }
+               }
        }, {
                .alg = "gcm(aes)",
                .test = alg_test_aead,
@@ -3392,6 +3400,46 @@ static const struct alg_test_desc alg_test_descs[] = {
                                .count = HMAC_SHA256_TEST_VECTORS
                        }
                }
+       }, {
+               .alg = "hmac(sha3-224)",
+               .test = alg_test_hash,
+               .fips_allowed = 1,
+               .suite = {
+                       .hash = {
+                               .vecs = hmac_sha3_224_tv_template,
+                               .count = HMAC_SHA3_224_TEST_VECTORS
+                       }
+               }
+       }, {
+               .alg = "hmac(sha3-256)",
+               .test = alg_test_hash,
+               .fips_allowed = 1,
+               .suite = {
+                       .hash = {
+                               .vecs = hmac_sha3_256_tv_template,
+                               .count = HMAC_SHA3_256_TEST_VECTORS
+                       }
+               }
+       }, {
+               .alg = "hmac(sha3-384)",
+               .test = alg_test_hash,
+               .fips_allowed = 1,
+               .suite = {
+                       .hash = {
+                               .vecs = hmac_sha3_384_tv_template,
+                               .count = HMAC_SHA3_384_TEST_VECTORS
+                       }
+               }
+       }, {
+               .alg = "hmac(sha3-512)",
+               .test = alg_test_hash,
+               .fips_allowed = 1,
+               .suite = {
+                       .hash = {
+                               .vecs = hmac_sha3_512_tv_template,
+                               .count = HMAC_SHA3_512_TEST_VECTORS
+                       }
+               }
        }, {
                .alg = "hmac(sha384)",
                .test = alg_test_hash,