net: CONFIG_COMPAT redux
[safe/jmp/linux-2.6] / crypto / testmgr.c
index 376ea88..7620bfc 100644 (file)
@@ -180,7 +180,12 @@ static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
        ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
                                   tcrypt_complete, &tresult);
 
+       j = 0;
        for (i = 0; i < tcount; i++) {
+               if (template[i].np)
+                       continue;
+
+               j++;
                memset(result, 0, 64);
 
                hash_buff = xbuf[0];
@@ -194,7 +199,7 @@ static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
                                                  template[i].ksize);
                        if (ret) {
                                printk(KERN_ERR "alg: hash: setkey failed on "
-                                      "test %d for %s: ret=%d\n", i + 1, algo,
+                                      "test %d for %s: ret=%d\n", j, algo,
                                       -ret);
                                goto out;
                        }
@@ -216,14 +221,14 @@ static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
                        /* fall through */
                default:
                        printk(KERN_ERR "alg: hash: digest failed on test %d "
-                              "for %s: ret=%d\n", i + 1, algo, -ret);
+                              "for %s: ret=%d\n", j, algo, -ret);
                        goto out;
                }
 
                if (memcmp(result, template[i].digest,
                           crypto_ahash_digestsize(tfm))) {
                        printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
-                              i + 1, algo);
+                              j, algo);
                        hexdump(result, crypto_ahash_digestsize(tfm));
                        ret = -EINVAL;
                        goto out;
@@ -238,7 +243,11 @@ static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
 
                        temp = 0;
                        sg_init_table(sg, template[i].np);
+                       ret = -EINVAL;
                        for (k = 0; k < template[i].np; k++) {
+                               if (WARN_ON(offset_in_page(IDX[k]) +
+                                           template[i].tap[k] > PAGE_SIZE))
+                                       goto out;
                                sg_set_buf(&sg[k],
                                           memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
                                                  offset_in_page(IDX[k]),
@@ -357,6 +366,11 @@ static int test_aead(struct crypto_aead *tfm, int enc,
                        input = xbuf[0];
                        assoc = axbuf[0];
 
+                       ret = -EINVAL;
+                       if (WARN_ON(template[i].ilen > PAGE_SIZE ||
+                                   template[i].alen > PAGE_SIZE))
+                               goto out;
+
                        memcpy(input, template[i].input, template[i].ilen);
                        memcpy(assoc, template[i].assoc, template[i].alen);
                        if (template[i].iv)
@@ -516,7 +530,11 @@ static int test_aead(struct crypto_aead *tfm, int enc,
                        }
 
                        sg_init_table(asg, template[i].anp);
+                       ret = -EINVAL;
                        for (k = 0, temp = 0; k < template[i].anp; k++) {
+                               if (WARN_ON(offset_in_page(IDX[k]) +
+                                           template[i].atap[k] > PAGE_SIZE))
+                                       goto out;
                                sg_set_buf(&asg[k],
                                           memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
                                                  offset_in_page(IDX[k]),
@@ -650,6 +668,10 @@ static int test_cipher(struct crypto_cipher *tfm, int enc,
 
                j++;
 
+               ret = -EINVAL;
+               if (WARN_ON(template[i].ilen > PAGE_SIZE))
+                       goto out;
+
                data = xbuf[0];
                memcpy(data, template[i].input, template[i].ilen);
 
@@ -741,6 +763,10 @@ static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
                if (!(template[i].np)) {
                        j++;
 
+                       ret = -EINVAL;
+                       if (WARN_ON(template[i].ilen > PAGE_SIZE))
+                               goto out;
+
                        data = xbuf[0];
                        memcpy(data, template[i].input, template[i].ilen);
 
@@ -1175,7 +1201,7 @@ static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
                      unsigned int tcount)
 {
        const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
-       int err, i, j, seedsize;
+       int err = 0, i, j, seedsize;
        u8 *seed;
        char result[32];
 
@@ -1917,6 +1943,15 @@ static const struct alg_test_desc alg_test_descs[] = {
                        }
                }
        }, {
+               .alg = "ghash",
+               .test = alg_test_hash,
+               .suite = {
+                       .hash = {
+                               .vecs = ghash_tv_template,
+                               .count = GHASH_TEST_VECTORS
+                       }
+               }
+       }, {
                .alg = "hmac(md5)",
                .test = alg_test_hash,
                .suite = {
@@ -2222,6 +2257,15 @@ static const struct alg_test_desc alg_test_descs[] = {
                        }
                }
        }, {
+               .alg = "vmac(aes)",
+               .test = alg_test_hash,
+               .suite = {
+                       .hash = {
+                               .vecs = aes_vmac128_tv_template,
+                               .count = VMAC_AES_TEST_VECTORS
+                       }
+               }
+       }, {
                .alg = "wp256",
                .test = alg_test_hash,
                .suite = {
@@ -2318,6 +2362,7 @@ static int alg_find_test(const char *alg)
 int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
 {
        int i;
+       int j;
        int rc;
 
        if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
@@ -2339,14 +2384,22 @@ int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
        }
 
        i = alg_find_test(alg);
-       if (i < 0)
+       j = alg_find_test(driver);
+       if (i < 0 && j < 0)
                goto notest;
 
-       if (fips_enabled && !alg_test_descs[i].fips_allowed)
+       if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
+                            (j >= 0 && !alg_test_descs[j].fips_allowed)))
                goto non_fips_alg;
 
-       rc = alg_test_descs[i].test(alg_test_descs + i, driver,
-                                     type, mask);
+       rc = 0;
+       if (i >= 0)
+               rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
+                                            type, mask);
+       if (j >= 0)
+               rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
+                                            type, mask);
+
 test_done:
        if (fips_enabled && rc)
                panic("%s: %s alg self test failed in fips mode!\n", driver, alg);