crypto: aead - Add common IV generation code
[deliverable/linux.git] / crypto / testmgr.c
index f4ed6d4205e713880f1d3b8fb2a6b567c0a3154e..277b3ac0ca1a1e71324a1d7346d20daadbec4e7b 100644 (file)
  *
  */
 
+#include <crypto/aead.h>
 #include <crypto/hash.h>
 #include <linux/err.h>
+#include <linux/fips.h>
 #include <linux/module.h>
 #include <linux/scatterlist.h>
 #include <linux/slab.h>
@@ -1474,11 +1476,11 @@ static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
                for (j = 0; j < template[i].loops; j++) {
                        err = crypto_rng_get_bytes(tfm, result,
                                                   template[i].rlen);
-                       if (err != template[i].rlen) {
+                       if (err < 0) {
                                printk(KERN_ERR "alg: cprng: Failed to obtain "
                                       "the correct amount of random data for "
-                                      "%s (requested %d, got %d)\n", algo,
-                                      template[i].rlen, err);
+                                      "%s (requested %d)\n", algo,
+                                      template[i].rlen);
                                goto out;
                        }
                }
@@ -1505,7 +1507,7 @@ static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
        struct crypto_aead *tfm;
        int err = 0;
 
-       tfm = crypto_alloc_aead(driver, type, mask);
+       tfm = crypto_alloc_aead(driver, type | CRYPTO_ALG_INTERNAL, mask);
        if (IS_ERR(tfm)) {
                printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
                       "%ld\n", driver, PTR_ERR(tfm));
@@ -1534,7 +1536,7 @@ static int alg_test_cipher(const struct alg_test_desc *desc,
        struct crypto_cipher *tfm;
        int err = 0;
 
-       tfm = crypto_alloc_cipher(driver, type, mask);
+       tfm = crypto_alloc_cipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
        if (IS_ERR(tfm)) {
                printk(KERN_ERR "alg: cipher: Failed to load transform for "
                       "%s: %ld\n", driver, PTR_ERR(tfm));
@@ -1563,7 +1565,7 @@ static int alg_test_skcipher(const struct alg_test_desc *desc,
        struct crypto_ablkcipher *tfm;
        int err = 0;
 
-       tfm = crypto_alloc_ablkcipher(driver, type, mask);
+       tfm = crypto_alloc_ablkcipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
        if (IS_ERR(tfm)) {
                printk(KERN_ERR "alg: skcipher: Failed to load transform for "
                       "%s: %ld\n", driver, PTR_ERR(tfm));
@@ -1636,7 +1638,7 @@ static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
        struct crypto_ahash *tfm;
        int err;
 
-       tfm = crypto_alloc_ahash(driver, type, mask);
+       tfm = crypto_alloc_ahash(driver, type | CRYPTO_ALG_INTERNAL, mask);
        if (IS_ERR(tfm)) {
                printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
                       "%ld\n", driver, PTR_ERR(tfm));
@@ -1664,7 +1666,7 @@ static int alg_test_crc32c(const struct alg_test_desc *desc,
        if (err)
                goto out;
 
-       tfm = crypto_alloc_shash(driver, type, mask);
+       tfm = crypto_alloc_shash(driver, type | CRYPTO_ALG_INTERNAL, mask);
        if (IS_ERR(tfm)) {
                printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
                       "%ld\n", driver, PTR_ERR(tfm));
@@ -1706,7 +1708,7 @@ static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
        struct crypto_rng *rng;
        int err;
 
-       rng = crypto_alloc_rng(driver, type, mask);
+       rng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
        if (IS_ERR(rng)) {
                printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
                       "%ld\n", driver, PTR_ERR(rng));
@@ -1733,7 +1735,7 @@ static int drbg_cavs_test(struct drbg_testvec *test, int pr,
        if (!buf)
                return -ENOMEM;
 
-       drng = crypto_alloc_rng(driver, type, mask);
+       drng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
        if (IS_ERR(drng)) {
                printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
                       "%s\n", driver);
@@ -1759,7 +1761,7 @@ static int drbg_cavs_test(struct drbg_testvec *test, int pr,
                ret = crypto_drbg_get_bytes_addtl(drng,
                        buf, test->expectedlen, &addtl);
        }
-       if (ret <= 0) {
+       if (ret < 0) {
                printk(KERN_ERR "alg: drbg: could not obtain random data for "
                       "driver %s\n", driver);
                goto outbuf;
@@ -1774,7 +1776,7 @@ static int drbg_cavs_test(struct drbg_testvec *test, int pr,
                ret = crypto_drbg_get_bytes_addtl(drng,
                        buf, test->expectedlen, &addtl);
        }
-       if (ret <= 0) {
+       if (ret < 0) {
                printk(KERN_ERR "alg: drbg: could not obtain random data for "
                       "driver %s\n", driver);
                goto outbuf;
@@ -2317,6 +2319,15 @@ static const struct alg_test_desc alg_test_descs[] = {
        }, {
                .alg = "compress_null",
                .test = alg_test_null,
+       }, {
+               .alg = "crc32",
+               .test = alg_test_hash,
+               .suite = {
+                       .hash = {
+                               .vecs = crc32_tv_template,
+                               .count = CRC32_TEST_VECTORS
+                       }
+               }
        }, {
                .alg = "crc32c",
                .test = alg_test_crc32c,
@@ -3094,6 +3105,10 @@ static const struct alg_test_desc alg_test_descs[] = {
                                .count = HMAC_SHA512_TEST_VECTORS
                        }
                }
+       }, {
+               .alg = "jitterentropy_rng",
+               .fips_allowed = 1,
+               .test = alg_test_null,
        }, {
                .alg = "lrw(aes)",
                .test = alg_test_skcipher,
This page took 0.025483 seconds and 5 git commands to generate.