~ubuntu-branches/debian/wheezy/linux-2.6/wheezy

« back to all changes in this revision

Viewing changes to crypto/testmgr.c

  • Committer: Bazaar Package Importer
  • Author(s): Ben Hutchings, Ben Hutchings, Aurelien Jarno, Martin Michlmayr
  • Date: 2011-04-06 13:53:30 UTC
  • mfrom: (43.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110406135330-wjufxhd0tvn3zx4z
Tags: 2.6.38-3
[ Ben Hutchings ]
* [ppc64] Add to linux-tools package architectures (Closes: #620124)
* [amd64] Save cr4 to mmu_cr4_features at boot time (Closes: #620284)
* appletalk: Fix bugs introduced when removing use of BKL
* ALSA: Fix yet another race in disconnection
* cciss: Fix lost command issue
* ath9k: Fix kernel panic in AR2427
* ses: Avoid kernel panic when lun 0 is not mapped
* PCI/ACPI: Report ASPM support to BIOS if not disabled from command line

[ Aurelien Jarno ]
* rtlwifi: fix build when PCI is not enabled.

[ Martin Michlmayr ]
* rtlwifi: Eliminate udelay calls with too large values (Closes: #620204)

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 * Copyright (c) 2007 Nokia Siemens Networks
7
7
 * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
8
8
 *
 
9
 * Updated RFC4106 AES-GCM testing.
 
10
 *    Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
 
11
 *             Adrian Hoban <adrian.hoban@intel.com>
 
12
 *             Gabriele Paoloni <gabriele.paoloni@intel.com>
 
13
 *             Tadeusz Struk (tadeusz.struk@intel.com)
 
14
 *    Copyright (c) 2010, Intel Corporation.
 
15
 *
9
16
 * This program is free software; you can redistribute it and/or modify it
10
17
 * under the terms of the GNU General Public License as published by the Free
11
18
 * Software Foundation; either version 2 of the License, or (at your option)
22
29
#include <crypto/rng.h>
23
30
 
24
31
#include "internal.h"
 
32
 
 
33
#ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
 
34
 
 
35
/* a perfect nop */
 
36
int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
 
37
{
 
38
        return 0;
 
39
}
 
40
 
 
41
#else
 
42
 
25
43
#include "testmgr.h"
26
44
 
27
45
/*
153
171
                free_page((unsigned long)buf[i]);
154
172
}
155
173
 
 
174
static int do_one_async_hash_op(struct ahash_request *req,
 
175
                                struct tcrypt_result *tr,
 
176
                                int ret)
 
177
{
 
178
        if (ret == -EINPROGRESS || ret == -EBUSY) {
 
179
                ret = wait_for_completion_interruptible(&tr->completion);
 
180
                if (!ret)
 
181
                        ret = tr->err;
 
182
                INIT_COMPLETION(tr->completion);
 
183
        }
 
184
        return ret;
 
185
}
 
186
 
156
187
static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
157
 
                     unsigned int tcount)
 
188
                     unsigned int tcount, bool use_digest)
158
189
{
159
190
        const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
160
191
        unsigned int i, j, k, temp;
206
237
                }
207
238
 
208
239
                ahash_request_set_crypt(req, sg, result, template[i].psize);
209
 
                ret = crypto_ahash_digest(req);
210
 
                switch (ret) {
211
 
                case 0:
212
 
                        break;
213
 
                case -EINPROGRESS:
214
 
                case -EBUSY:
215
 
                        ret = wait_for_completion_interruptible(
216
 
                                &tresult.completion);
217
 
                        if (!ret && !(ret = tresult.err)) {
218
 
                                INIT_COMPLETION(tresult.completion);
219
 
                                break;
220
 
                        }
221
 
                        /* fall through */
222
 
                default:
223
 
                        printk(KERN_ERR "alg: hash: digest failed on test %d "
224
 
                               "for %s: ret=%d\n", j, algo, -ret);
225
 
                        goto out;
 
240
                if (use_digest) {
 
241
                        ret = do_one_async_hash_op(req, &tresult,
 
242
                                                   crypto_ahash_digest(req));
 
243
                        if (ret) {
 
244
                                pr_err("alg: hash: digest failed on test %d "
 
245
                                       "for %s: ret=%d\n", j, algo, -ret);
 
246
                                goto out;
 
247
                        }
 
248
                } else {
 
249
                        ret = do_one_async_hash_op(req, &tresult,
 
250
                                                   crypto_ahash_init(req));
 
251
                        if (ret) {
 
252
                                pr_err("alt: hash: init failed on test %d "
 
253
                                       "for %s: ret=%d\n", j, algo, -ret);
 
254
                                goto out;
 
255
                        }
 
256
                        ret = do_one_async_hash_op(req, &tresult,
 
257
                                                   crypto_ahash_update(req));
 
258
                        if (ret) {
 
259
                                pr_err("alt: hash: update failed on test %d "
 
260
                                       "for %s: ret=%d\n", j, algo, -ret);
 
261
                                goto out;
 
262
                        }
 
263
                        ret = do_one_async_hash_op(req, &tresult,
 
264
                                                   crypto_ahash_final(req));
 
265
                        if (ret) {
 
266
                                pr_err("alt: hash: final failed on test %d "
 
267
                                       "for %s: ret=%d\n", j, algo, -ret);
 
268
                                goto out;
 
269
                        }
226
270
                }
227
271
 
228
272
                if (memcmp(result, template[i].digest,
1201
1245
                      unsigned int tcount)
1202
1246
{
1203
1247
        const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
1204
 
        int err, i, j, seedsize;
 
1248
        int err = 0, i, j, seedsize;
1205
1249
        u8 *seed;
1206
1250
        char result[32];
1207
1251
 
1402
1446
                return PTR_ERR(tfm);
1403
1447
        }
1404
1448
 
1405
 
        err = test_hash(tfm, desc->suite.hash.vecs, desc->suite.hash.count);
 
1449
        err = test_hash(tfm, desc->suite.hash.vecs,
 
1450
                        desc->suite.hash.count, true);
 
1451
        if (!err)
 
1452
                err = test_hash(tfm, desc->suite.hash.vecs,
 
1453
                                desc->suite.hash.count, false);
1406
1454
 
1407
1455
        crypto_free_ahash(tfm);
1408
1456
        return err;
1477
1525
        return err;
1478
1526
}
1479
1527
 
 
1528
static int alg_test_null(const struct alg_test_desc *desc,
 
1529
                             const char *driver, u32 type, u32 mask)
 
1530
{
 
1531
        return 0;
 
1532
}
 
1533
 
1480
1534
/* Please keep this list sorted by algorithm name. */
1481
1535
static const struct alg_test_desc alg_test_descs[] = {
1482
1536
        {
 
1537
                .alg = "__driver-cbc-aes-aesni",
 
1538
                .test = alg_test_null,
 
1539
                .suite = {
 
1540
                        .cipher = {
 
1541
                                .enc = {
 
1542
                                        .vecs = NULL,
 
1543
                                        .count = 0
 
1544
                                },
 
1545
                                .dec = {
 
1546
                                        .vecs = NULL,
 
1547
                                        .count = 0
 
1548
                                }
 
1549
                        }
 
1550
                }
 
1551
        }, {
 
1552
                .alg = "__driver-ecb-aes-aesni",
 
1553
                .test = alg_test_null,
 
1554
                .suite = {
 
1555
                        .cipher = {
 
1556
                                .enc = {
 
1557
                                        .vecs = NULL,
 
1558
                                        .count = 0
 
1559
                                },
 
1560
                                .dec = {
 
1561
                                        .vecs = NULL,
 
1562
                                        .count = 0
 
1563
                                }
 
1564
                        }
 
1565
                }
 
1566
        }, {
 
1567
                .alg = "__ghash-pclmulqdqni",
 
1568
                .test = alg_test_null,
 
1569
                .suite = {
 
1570
                        .hash = {
 
1571
                                .vecs = NULL,
 
1572
                                .count = 0
 
1573
                        }
 
1574
                }
 
1575
        }, {
1483
1576
                .alg = "ansi_cprng",
1484
1577
                .test = alg_test_cprng,
1485
1578
                .fips_allowed = 1,
1623
1716
                        }
1624
1717
                }
1625
1718
        }, {
 
1719
                .alg = "cryptd(__driver-ecb-aes-aesni)",
 
1720
                .test = alg_test_null,
 
1721
                .suite = {
 
1722
                        .cipher = {
 
1723
                                .enc = {
 
1724
                                        .vecs = NULL,
 
1725
                                        .count = 0
 
1726
                                },
 
1727
                                .dec = {
 
1728
                                        .vecs = NULL,
 
1729
                                        .count = 0
 
1730
                                }
 
1731
                        }
 
1732
                }
 
1733
        }, {
 
1734
                .alg = "cryptd(__ghash-pclmulqdqni)",
 
1735
                .test = alg_test_null,
 
1736
                .suite = {
 
1737
                        .hash = {
 
1738
                                .vecs = NULL,
 
1739
                                .count = 0
 
1740
                        }
 
1741
                }
 
1742
        }, {
1626
1743
                .alg = "ctr(aes)",
1627
1744
                .test = alg_test_skcipher,
1628
1745
                .fips_allowed = 1,
1669
1786
                        }
1670
1787
                }
1671
1788
        }, {
 
1789
                .alg = "ecb(__aes-aesni)",
 
1790
                .test = alg_test_null,
 
1791
                .suite = {
 
1792
                        .cipher = {
 
1793
                                .enc = {
 
1794
                                        .vecs = NULL,
 
1795
                                        .count = 0
 
1796
                                },
 
1797
                                .dec = {
 
1798
                                        .vecs = NULL,
 
1799
                                        .count = 0
 
1800
                                }
 
1801
                        }
 
1802
                }
 
1803
        }, {
1672
1804
                .alg = "ecb(aes)",
1673
1805
                .test = alg_test_skcipher,
1674
1806
                .fips_allowed = 1,
1943
2075
                        }
1944
2076
                }
1945
2077
        }, {
 
2078
                .alg = "ghash",
 
2079
                .test = alg_test_hash,
 
2080
                .suite = {
 
2081
                        .hash = {
 
2082
                                .vecs = ghash_tv_template,
 
2083
                                .count = GHASH_TEST_VECTORS
 
2084
                        }
 
2085
                }
 
2086
        }, {
1946
2087
                .alg = "hmac(md5)",
1947
2088
                .test = alg_test_hash,
1948
2089
                .suite = {
2108
2249
                        }
2109
2250
                }
2110
2251
        }, {
 
2252
                .alg = "rfc4106(gcm(aes))",
 
2253
                .test = alg_test_aead,
 
2254
                .suite = {
 
2255
                        .aead = {
 
2256
                                .enc = {
 
2257
                                        .vecs = aes_gcm_rfc4106_enc_tv_template,
 
2258
                                        .count = AES_GCM_4106_ENC_TEST_VECTORS
 
2259
                                },
 
2260
                                .dec = {
 
2261
                                        .vecs = aes_gcm_rfc4106_dec_tv_template,
 
2262
                                        .count = AES_GCM_4106_DEC_TEST_VECTORS
 
2263
                                }
 
2264
                        }
 
2265
                }
 
2266
        }, {
 
2267
 
 
2268
 
2111
2269
                .alg = "rfc4309(ccm(aes))",
2112
2270
                .test = alg_test_aead,
2113
2271
                .fips_allowed = 1,
2407
2565
non_fips_alg:
2408
2566
        return -EINVAL;
2409
2567
}
 
2568
 
 
2569
#endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
 
2570
 
2410
2571
EXPORT_SYMBOL_GPL(alg_test);