Skip to content

Commit

Permalink
crypto: testmgr - constify all test vectors
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Eric Biggers authored and Herbert Xu committed Mar 9, 2017
1 parent 5527dfb commit b13b1e0
Show file tree
Hide file tree
Showing 2 changed files with 297 additions and 286 deletions.
71 changes: 41 additions & 30 deletions crypto/testmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,47 +83,47 @@ struct tcrypt_result {

struct aead_test_suite {
struct {
struct aead_testvec *vecs;
const struct aead_testvec *vecs;
unsigned int count;
} enc, dec;
};

struct cipher_test_suite {
struct {
struct cipher_testvec *vecs;
const struct cipher_testvec *vecs;
unsigned int count;
} enc, dec;
};

struct comp_test_suite {
struct {
struct comp_testvec *vecs;
const struct comp_testvec *vecs;
unsigned int count;
} comp, decomp;
};

struct hash_test_suite {
struct hash_testvec *vecs;
const struct hash_testvec *vecs;
unsigned int count;
};

struct cprng_test_suite {
struct cprng_testvec *vecs;
const struct cprng_testvec *vecs;
unsigned int count;
};

struct drbg_test_suite {
struct drbg_testvec *vecs;
const struct drbg_testvec *vecs;
unsigned int count;
};

struct akcipher_test_suite {
struct akcipher_testvec *vecs;
const struct akcipher_testvec *vecs;
unsigned int count;
};

struct kpp_test_suite {
struct kpp_testvec *vecs;
const struct kpp_testvec *vecs;
unsigned int count;
};

Expand All @@ -145,7 +145,8 @@ struct alg_test_desc {
} 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)
{
Expand Down Expand Up @@ -203,7 +204,7 @@ static int wait_async_op(struct tcrypt_result *tr, int ret)
}

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,
const char *algo, char *result, struct tcrypt_result *tresult)
{
Expand Down Expand Up @@ -260,9 +261,9 @@ static int ahash_partial_update(struct ahash_request **preq,
return ret;
}

static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
unsigned int tcount, bool use_digest,
const int align_offset)
static int __test_hash(struct crypto_ahash *tfm,
const struct hash_testvec *template, unsigned int tcount,
bool use_digest, const int align_offset)
{
const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
size_t digest_size = crypto_ahash_digestsize(tfm);
Expand Down Expand Up @@ -538,7 +539,8 @@ static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
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 alignmask;
Expand Down Expand Up @@ -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,
struct aead_testvec *template, unsigned int tcount,
const struct aead_testvec *template, unsigned int tcount,
const bool diff_dst, const int align_offset)
{
const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
Expand Down Expand Up @@ -957,7 +959,7 @@ 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;
int ret;
Expand Down Expand Up @@ -990,7 +992,8 @@ static int test_aead(struct crypto_aead *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));
unsigned int i, j, k;
Expand Down Expand Up @@ -1068,7 +1071,8 @@ static int test_cipher(struct crypto_cipher *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 char *algo =
Expand Down Expand Up @@ -1332,7 +1336,8 @@ 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;
int ret;
Expand Down Expand Up @@ -1364,8 +1369,10 @@ static int test_skcipher(struct crypto_skcipher *tfm, int enc,
return 0;
}

static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
struct comp_testvec *dtemplate, int ctcount, int dtcount)
static int test_comp(struct crypto_comp *tfm,
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));
unsigned int i;
Expand Down Expand Up @@ -1444,8 +1451,10 @@ static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
return ret;
}

static int test_acomp(struct crypto_acomp *tfm, struct comp_testvec *ctemplate,
struct comp_testvec *dtemplate, int ctcount, int dtcount)
static int test_acomp(struct crypto_acomp *tfm,
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));
unsigned int i;
Expand Down Expand Up @@ -1588,7 +1597,8 @@ static int test_acomp(struct crypto_acomp *tfm, struct comp_testvec *ctemplate,
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)
{
const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
Expand Down Expand Up @@ -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)
{
int ret = -EAGAIN;
Expand Down Expand Up @@ -1939,7 +1949,7 @@ static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
int err = 0;
int pr = 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;

if (0 == memcmp(driver, "drbg_pr_", 8))
Expand All @@ -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)
{
struct kpp_request *req;
Expand Down Expand Up @@ -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,
struct kpp_testvec *vecs, unsigned int tcount)
const struct kpp_testvec *vecs, unsigned int tcount)
{
int ret, i;

Expand Down Expand Up @@ -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,
struct akcipher_testvec *vecs)
const struct akcipher_testvec *vecs)
{
char *xbuf[XBUFSIZE];
struct akcipher_request *req;
Expand Down Expand Up @@ -2206,7 +2216,8 @@ static int test_akcipher_one(struct crypto_akcipher *tfm,
}

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 =
crypto_tfm_alg_driver_name(crypto_akcipher_tfm(tfm));
Expand Down
Loading

0 comments on commit b13b1e0

Please sign in to comment.