summaryrefslogtreecommitdiffstats
path: root/crypto/testmgr.c
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2017-02-24 18:46:59 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2017-03-09 05:34:39 -0500
commitb13b1e0c6b171b4f6ad94dd99020708719983494 (patch)
treeb009912627ebc58497f26e7e9f8da8d1d430e315 /crypto/testmgr.c
parent5527dfb6ddac2aac98c2939f27840cb47abd5693 (diff)
crypto: testmgr - constify all test vectors
Cryptographic test vectors should never be modified, so constify them to enforce this at both compile-time and run-time. This moves a significant amount of data from .data to .rodata when the crypto tests are enabled. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/testmgr.c')
-rw-r--r--crypto/testmgr.c71
1 files changed, 41 insertions, 30 deletions
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index f9c378af3907..89f1dd1f4b13 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -83,47 +83,47 @@ struct tcrypt_result {
83 83
84struct aead_test_suite { 84struct aead_test_suite {
85 struct { 85 struct {
86 struct aead_testvec *vecs; 86 const struct aead_testvec *vecs;
87 unsigned int count; 87 unsigned int count;
88 } enc, dec; 88 } enc, dec;
89}; 89};
90 90
91struct cipher_test_suite { 91struct cipher_test_suite {
92 struct { 92 struct {
93 struct cipher_testvec *vecs; 93 const struct cipher_testvec *vecs;
94 unsigned int count; 94 unsigned int count;
95 } enc, dec; 95 } enc, dec;
96}; 96};
97 97
98struct comp_test_suite { 98struct comp_test_suite {
99 struct { 99 struct {
100 struct comp_testvec *vecs; 100 const struct comp_testvec *vecs;
101 unsigned int count; 101 unsigned int count;
102 } comp, decomp; 102 } comp, decomp;
103}; 103};
104 104
105struct hash_test_suite { 105struct hash_test_suite {
106 struct hash_testvec *vecs; 106 const struct hash_testvec *vecs;
107 unsigned int count; 107 unsigned int count;
108}; 108};
109 109
110struct cprng_test_suite { 110struct cprng_test_suite {
111 struct cprng_testvec *vecs; 111 const struct cprng_testvec *vecs;
112 unsigned int count; 112 unsigned int count;
113}; 113};
114 114
115struct drbg_test_suite { 115struct drbg_test_suite {
116 struct drbg_testvec *vecs; 116 const struct drbg_testvec *vecs;
117 unsigned int count; 117 unsigned int count;
118}; 118};
119 119
120struct akcipher_test_suite { 120struct akcipher_test_suite {
121 struct akcipher_testvec *vecs; 121 const struct akcipher_testvec *vecs;
122 unsigned int count; 122 unsigned int count;
123}; 123};
124 124
125struct kpp_test_suite { 125struct kpp_test_suite {
126 struct kpp_testvec *vecs; 126 const struct kpp_testvec *vecs;
127 unsigned int count; 127 unsigned int count;
128}; 128};
129 129
@@ -145,7 +145,8 @@ struct alg_test_desc {
145 } suite; 145 } suite;
146}; 146};
147 147
148static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 }; 148static const unsigned int IDX[8] = {
149 IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
149 150
150static void hexdump(unsigned char *buf, unsigned int len) 151static void hexdump(unsigned char *buf, unsigned int len)
151{ 152{
@@ -203,7 +204,7 @@ static int wait_async_op(struct tcrypt_result *tr, int ret)
203} 204}
204 205
205static int ahash_partial_update(struct ahash_request **preq, 206static int ahash_partial_update(struct ahash_request **preq,
206 struct crypto_ahash *tfm, struct hash_testvec *template, 207 struct crypto_ahash *tfm, const struct hash_testvec *template,
207 void *hash_buff, int k, int temp, struct scatterlist *sg, 208 void *hash_buff, int k, int temp, struct scatterlist *sg,
208 const char *algo, char *result, struct tcrypt_result *tresult) 209 const char *algo, char *result, struct tcrypt_result *tresult)
209{ 210{
@@ -260,9 +261,9 @@ out_nostate:
260 return ret; 261 return ret;
261} 262}
262 263
263static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, 264static int __test_hash(struct crypto_ahash *tfm,
264 unsigned int tcount, bool use_digest, 265 const struct hash_testvec *template, unsigned int tcount,
265 const int align_offset) 266 bool use_digest, const int align_offset)
266{ 267{
267 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm)); 268 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
268 size_t digest_size = crypto_ahash_digestsize(tfm); 269 size_t digest_size = crypto_ahash_digestsize(tfm);
@@ -538,7 +539,8 @@ out_nobuf:
538 return ret; 539 return ret;
539} 540}
540 541
541static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, 542static int test_hash(struct crypto_ahash *tfm,
543 const struct hash_testvec *template,
542 unsigned int tcount, bool use_digest) 544 unsigned int tcount, bool use_digest)
543{ 545{
544 unsigned int alignmask; 546 unsigned int alignmask;
@@ -566,7 +568,7 @@ static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
566} 568}
567 569
568static int __test_aead(struct crypto_aead *tfm, int enc, 570static int __test_aead(struct crypto_aead *tfm, int enc,
569 struct aead_testvec *template, unsigned int tcount, 571 const struct aead_testvec *template, unsigned int tcount,
570 const bool diff_dst, const int align_offset) 572 const bool diff_dst, const int align_offset)
571{ 573{
572 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm)); 574 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
@@ -957,7 +959,7 @@ out_noxbuf:
957} 959}
958 960
959static int test_aead(struct crypto_aead *tfm, int enc, 961static int test_aead(struct crypto_aead *tfm, int enc,
960 struct aead_testvec *template, unsigned int tcount) 962 const struct aead_testvec *template, unsigned int tcount)
961{ 963{
962 unsigned int alignmask; 964 unsigned int alignmask;
963 int ret; 965 int ret;
@@ -990,7 +992,8 @@ static int test_aead(struct crypto_aead *tfm, int enc,
990} 992}
991 993
992static int test_cipher(struct crypto_cipher *tfm, int enc, 994static int test_cipher(struct crypto_cipher *tfm, int enc,
993 struct cipher_testvec *template, unsigned int tcount) 995 const struct cipher_testvec *template,
996 unsigned int tcount)
994{ 997{
995 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm)); 998 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
996 unsigned int i, j, k; 999 unsigned int i, j, k;
@@ -1068,7 +1071,8 @@ out_nobuf:
1068} 1071}
1069 1072
1070static int __test_skcipher(struct crypto_skcipher *tfm, int enc, 1073static int __test_skcipher(struct crypto_skcipher *tfm, int enc,
1071 struct cipher_testvec *template, unsigned int tcount, 1074 const struct cipher_testvec *template,
1075 unsigned int tcount,
1072 const bool diff_dst, const int align_offset) 1076 const bool diff_dst, const int align_offset)
1073{ 1077{
1074 const char *algo = 1078 const char *algo =
@@ -1332,7 +1336,8 @@ out_nobuf:
1332} 1336}
1333 1337
1334static int test_skcipher(struct crypto_skcipher *tfm, int enc, 1338static int test_skcipher(struct crypto_skcipher *tfm, int enc,
1335 struct cipher_testvec *template, unsigned int tcount) 1339 const struct cipher_testvec *template,
1340 unsigned int tcount)
1336{ 1341{
1337 unsigned int alignmask; 1342 unsigned int alignmask;
1338 int ret; 1343 int ret;
@@ -1364,8 +1369,10 @@ static int test_skcipher(struct crypto_skcipher *tfm, int enc,
1364 return 0; 1369 return 0;
1365} 1370}
1366 1371
1367static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate, 1372static int test_comp(struct crypto_comp *tfm,
1368 struct comp_testvec *dtemplate, int ctcount, int dtcount) 1373 const struct comp_testvec *ctemplate,
1374 const struct comp_testvec *dtemplate,
1375 int ctcount, int dtcount)
1369{ 1376{
1370 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm)); 1377 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1371 unsigned int i; 1378 unsigned int i;
@@ -1444,8 +1451,10 @@ out:
1444 return ret; 1451 return ret;
1445} 1452}
1446 1453
1447static int test_acomp(struct crypto_acomp *tfm, struct comp_testvec *ctemplate, 1454static int test_acomp(struct crypto_acomp *tfm,
1448 struct comp_testvec *dtemplate, int ctcount, int dtcount) 1455 const struct comp_testvec *ctemplate,
1456 const struct comp_testvec *dtemplate,
1457 int ctcount, int dtcount)
1449{ 1458{
1450 const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm)); 1459 const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm));
1451 unsigned int i; 1460 unsigned int i;
@@ -1588,7 +1597,8 @@ out:
1588 return ret; 1597 return ret;
1589} 1598}
1590 1599
1591static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template, 1600static int test_cprng(struct crypto_rng *tfm,
1601 const struct cprng_testvec *template,
1592 unsigned int tcount) 1602 unsigned int tcount)
1593{ 1603{
1594 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm)); 1604 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
@@ -1865,7 +1875,7 @@ static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1865} 1875}
1866 1876
1867 1877
1868static int drbg_cavs_test(struct drbg_testvec *test, int pr, 1878static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
1869 const char *driver, u32 type, u32 mask) 1879 const char *driver, u32 type, u32 mask)
1870{ 1880{
1871 int ret = -EAGAIN; 1881 int ret = -EAGAIN;
@@ -1939,7 +1949,7 @@ static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
1939 int err = 0; 1949 int err = 0;
1940 int pr = 0; 1950 int pr = 0;
1941 int i = 0; 1951 int i = 0;
1942 struct drbg_testvec *template = desc->suite.drbg.vecs; 1952 const struct drbg_testvec *template = desc->suite.drbg.vecs;
1943 unsigned int tcount = desc->suite.drbg.count; 1953 unsigned int tcount = desc->suite.drbg.count;
1944 1954
1945 if (0 == memcmp(driver, "drbg_pr_", 8)) 1955 if (0 == memcmp(driver, "drbg_pr_", 8))
@@ -1958,7 +1968,7 @@ static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
1958 1968
1959} 1969}
1960 1970
1961static int do_test_kpp(struct crypto_kpp *tfm, struct kpp_testvec *vec, 1971static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec,
1962 const char *alg) 1972 const char *alg)
1963{ 1973{
1964 struct kpp_request *req; 1974 struct kpp_request *req;
@@ -2050,7 +2060,7 @@ free_req:
2050} 2060}
2051 2061
2052static int test_kpp(struct crypto_kpp *tfm, const char *alg, 2062static int test_kpp(struct crypto_kpp *tfm, const char *alg,
2053 struct kpp_testvec *vecs, unsigned int tcount) 2063 const struct kpp_testvec *vecs, unsigned int tcount)
2054{ 2064{
2055 int ret, i; 2065 int ret, i;
2056 2066
@@ -2086,7 +2096,7 @@ static int alg_test_kpp(const struct alg_test_desc *desc, const char *driver,
2086} 2096}
2087 2097
2088static int test_akcipher_one(struct crypto_akcipher *tfm, 2098static int test_akcipher_one(struct crypto_akcipher *tfm,
2089 struct akcipher_testvec *vecs) 2099 const struct akcipher_testvec *vecs)
2090{ 2100{
2091 char *xbuf[XBUFSIZE]; 2101 char *xbuf[XBUFSIZE];
2092 struct akcipher_request *req; 2102 struct akcipher_request *req;
@@ -2206,7 +2216,8 @@ free_xbuf:
2206} 2216}
2207 2217
2208static int test_akcipher(struct crypto_akcipher *tfm, const char *alg, 2218static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
2209 struct akcipher_testvec *vecs, unsigned int tcount) 2219 const struct akcipher_testvec *vecs,
2220 unsigned int tcount)
2210{ 2221{
2211 const char *algo = 2222 const char *algo =
2212 crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm)); 2223 crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm));