Commit b13b1e0c authored by Eric Biggers's avatar Eric Biggers Committed by Herbert Xu

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: default avatarEric Biggers <ebiggers@google.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 5527dfb6
...@@ -83,47 +83,47 @@ struct tcrypt_result { ...@@ -83,47 +83,47 @@ struct tcrypt_result {
struct aead_test_suite { struct aead_test_suite {
struct { struct {
struct aead_testvec *vecs; const struct aead_testvec *vecs;
unsigned int count; unsigned int count;
} enc, dec; } enc, dec;
}; };
struct cipher_test_suite { struct cipher_test_suite {
struct { struct {
struct cipher_testvec *vecs; const struct cipher_testvec *vecs;
unsigned int count; unsigned int count;
} enc, dec; } enc, dec;
}; };
struct comp_test_suite { struct comp_test_suite {
struct { struct {
struct comp_testvec *vecs; const struct comp_testvec *vecs;
unsigned int count; unsigned int count;
} comp, decomp; } comp, decomp;
}; };
struct hash_test_suite { struct hash_test_suite {
struct hash_testvec *vecs; const struct hash_testvec *vecs;
unsigned int count; unsigned int count;
}; };
struct cprng_test_suite { struct cprng_test_suite {
struct cprng_testvec *vecs; const struct cprng_testvec *vecs;
unsigned int count; unsigned int count;
}; };
struct drbg_test_suite { struct drbg_test_suite {
struct drbg_testvec *vecs; const struct drbg_testvec *vecs;
unsigned int count; unsigned int count;
}; };
struct akcipher_test_suite { struct akcipher_test_suite {
struct akcipher_testvec *vecs; const struct akcipher_testvec *vecs;
unsigned int count; unsigned int count;
}; };
struct kpp_test_suite { struct kpp_test_suite {
struct kpp_testvec *vecs; const struct kpp_testvec *vecs;
unsigned int count; unsigned int count;
}; };
...@@ -145,7 +145,8 @@ struct alg_test_desc { ...@@ -145,7 +145,8 @@ struct alg_test_desc {
} suite; } suite;
}; };
static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 }; static const unsigned int IDX[8] = {
IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
static void hexdump(unsigned char *buf, unsigned int len) static void hexdump(unsigned char *buf, unsigned int len)
{ {
...@@ -203,7 +204,7 @@ static int wait_async_op(struct tcrypt_result *tr, int ret) ...@@ -203,7 +204,7 @@ static int wait_async_op(struct tcrypt_result *tr, int ret)
} }
static int ahash_partial_update(struct ahash_request **preq, static int ahash_partial_update(struct ahash_request **preq,
struct crypto_ahash *tfm, struct hash_testvec *template, struct crypto_ahash *tfm, const struct hash_testvec *template,
void *hash_buff, int k, int temp, struct scatterlist *sg, void *hash_buff, int k, int temp, struct scatterlist *sg,
const char *algo, char *result, struct tcrypt_result *tresult) const char *algo, char *result, struct tcrypt_result *tresult)
{ {
...@@ -260,9 +261,9 @@ static int ahash_partial_update(struct ahash_request **preq, ...@@ -260,9 +261,9 @@ static int ahash_partial_update(struct ahash_request **preq,
return ret; return ret;
} }
static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, static int __test_hash(struct crypto_ahash *tfm,
unsigned int tcount, bool use_digest, const struct hash_testvec *template, unsigned int tcount,
const int align_offset) bool use_digest, const int align_offset)
{ {
const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm)); const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
size_t digest_size = crypto_ahash_digestsize(tfm); size_t digest_size = crypto_ahash_digestsize(tfm);
...@@ -538,7 +539,8 @@ static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, ...@@ -538,7 +539,8 @@ static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
return ret; return ret;
} }
static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, static int test_hash(struct crypto_ahash *tfm,
const struct hash_testvec *template,
unsigned int tcount, bool use_digest) unsigned int tcount, bool use_digest)
{ {
unsigned int alignmask; unsigned int alignmask;
...@@ -566,7 +568,7 @@ static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, ...@@ -566,7 +568,7 @@ static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
} }
static int __test_aead(struct crypto_aead *tfm, int enc, static int __test_aead(struct crypto_aead *tfm, int enc,
struct aead_testvec *template, unsigned int tcount, const struct aead_testvec *template, unsigned int tcount,
const bool diff_dst, const int align_offset) const bool diff_dst, const int align_offset)
{ {
const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm)); const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
...@@ -957,7 +959,7 @@ static int __test_aead(struct crypto_aead *tfm, int enc, ...@@ -957,7 +959,7 @@ static int __test_aead(struct crypto_aead *tfm, int enc,
} }
static int test_aead(struct crypto_aead *tfm, int enc, static int test_aead(struct crypto_aead *tfm, int enc,
struct aead_testvec *template, unsigned int tcount) const struct aead_testvec *template, unsigned int tcount)
{ {
unsigned int alignmask; unsigned int alignmask;
int ret; int ret;
...@@ -990,7 +992,8 @@ static int test_aead(struct crypto_aead *tfm, int enc, ...@@ -990,7 +992,8 @@ static int test_aead(struct crypto_aead *tfm, int enc,
} }
static int test_cipher(struct crypto_cipher *tfm, int enc, static int test_cipher(struct crypto_cipher *tfm, int enc,
struct cipher_testvec *template, unsigned int tcount) const struct cipher_testvec *template,
unsigned int tcount)
{ {
const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm)); const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
unsigned int i, j, k; unsigned int i, j, k;
...@@ -1068,7 +1071,8 @@ static int test_cipher(struct crypto_cipher *tfm, int enc, ...@@ -1068,7 +1071,8 @@ static int test_cipher(struct crypto_cipher *tfm, int enc,
} }
static int __test_skcipher(struct crypto_skcipher *tfm, int enc, static int __test_skcipher(struct crypto_skcipher *tfm, int enc,
struct cipher_testvec *template, unsigned int tcount, const struct cipher_testvec *template,
unsigned int tcount,
const bool diff_dst, const int align_offset) const bool diff_dst, const int align_offset)
{ {
const char *algo = const char *algo =
...@@ -1332,7 +1336,8 @@ static int __test_skcipher(struct crypto_skcipher *tfm, int enc, ...@@ -1332,7 +1336,8 @@ static int __test_skcipher(struct crypto_skcipher *tfm, int enc,
} }
static int test_skcipher(struct crypto_skcipher *tfm, int enc, static int test_skcipher(struct crypto_skcipher *tfm, int enc,
struct cipher_testvec *template, unsigned int tcount) const struct cipher_testvec *template,
unsigned int tcount)
{ {
unsigned int alignmask; unsigned int alignmask;
int ret; int ret;
...@@ -1364,8 +1369,10 @@ static int test_skcipher(struct crypto_skcipher *tfm, int enc, ...@@ -1364,8 +1369,10 @@ static int test_skcipher(struct crypto_skcipher *tfm, int enc,
return 0; return 0;
} }
static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate, static int test_comp(struct crypto_comp *tfm,
struct comp_testvec *dtemplate, int ctcount, int dtcount) const struct comp_testvec *ctemplate,
const struct comp_testvec *dtemplate,
int ctcount, int dtcount)
{ {
const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm)); const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
unsigned int i; unsigned int i;
...@@ -1444,8 +1451,10 @@ static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate, ...@@ -1444,8 +1451,10 @@ static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
return ret; return ret;
} }
static int test_acomp(struct crypto_acomp *tfm, struct comp_testvec *ctemplate, static int test_acomp(struct crypto_acomp *tfm,
struct comp_testvec *dtemplate, int ctcount, int dtcount) const struct comp_testvec *ctemplate,
const struct comp_testvec *dtemplate,
int ctcount, int dtcount)
{ {
const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm)); const char *algo = crypto_tfm_alg_driver_name(crypto_acomp_tfm(tfm));
unsigned int i; unsigned int i;
...@@ -1588,7 +1597,8 @@ static int test_acomp(struct crypto_acomp *tfm, struct comp_testvec *ctemplate, ...@@ -1588,7 +1597,8 @@ static int test_acomp(struct crypto_acomp *tfm, struct comp_testvec *ctemplate,
return ret; return ret;
} }
static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template, static int test_cprng(struct crypto_rng *tfm,
const struct cprng_testvec *template,
unsigned int tcount) unsigned int tcount)
{ {
const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm)); 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,7 +1875,7 @@ static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
} }
static int drbg_cavs_test(struct drbg_testvec *test, int pr, static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
const char *driver, u32 type, u32 mask) const char *driver, u32 type, u32 mask)
{ {
int ret = -EAGAIN; int ret = -EAGAIN;
...@@ -1939,7 +1949,7 @@ static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver, ...@@ -1939,7 +1949,7 @@ static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
int err = 0; int err = 0;
int pr = 0; int pr = 0;
int i = 0; int i = 0;
struct drbg_testvec *template = desc->suite.drbg.vecs; const struct drbg_testvec *template = desc->suite.drbg.vecs;
unsigned int tcount = desc->suite.drbg.count; unsigned int tcount = desc->suite.drbg.count;
if (0 == memcmp(driver, "drbg_pr_", 8)) 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,7 +1968,7 @@ static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
} }
static int do_test_kpp(struct crypto_kpp *tfm, struct kpp_testvec *vec, static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec,
const char *alg) const char *alg)
{ {
struct kpp_request *req; struct kpp_request *req;
...@@ -2050,7 +2060,7 @@ static int do_test_kpp(struct crypto_kpp *tfm, struct kpp_testvec *vec, ...@@ -2050,7 +2060,7 @@ static int do_test_kpp(struct crypto_kpp *tfm, struct kpp_testvec *vec,
} }
static int test_kpp(struct crypto_kpp *tfm, const char *alg, static int test_kpp(struct crypto_kpp *tfm, const char *alg,
struct kpp_testvec *vecs, unsigned int tcount) const struct kpp_testvec *vecs, unsigned int tcount)
{ {
int ret, i; int ret, i;
...@@ -2086,7 +2096,7 @@ static int alg_test_kpp(const struct alg_test_desc *desc, const char *driver, ...@@ -2086,7 +2096,7 @@ static int alg_test_kpp(const struct alg_test_desc *desc, const char *driver,
} }
static int test_akcipher_one(struct crypto_akcipher *tfm, static int test_akcipher_one(struct crypto_akcipher *tfm,
struct akcipher_testvec *vecs) const struct akcipher_testvec *vecs)
{ {
char *xbuf[XBUFSIZE]; char *xbuf[XBUFSIZE];
struct akcipher_request *req; struct akcipher_request *req;
...@@ -2206,7 +2216,8 @@ static int test_akcipher_one(struct crypto_akcipher *tfm, ...@@ -2206,7 +2216,8 @@ static int test_akcipher_one(struct crypto_akcipher *tfm,
} }
static int test_akcipher(struct crypto_akcipher *tfm, const char *alg, static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
struct akcipher_testvec *vecs, unsigned int tcount) const struct akcipher_testvec *vecs,
unsigned int tcount)
{ {
const char *algo = const char *algo =
crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm)); crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm));
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment