Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

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

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
Loading
Loading
Loading
Loading
+41 −30
Original line number Diff line number Diff line
@@ -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;
};

@@ -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)
{
@@ -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)
{
@@ -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);
@@ -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;
@@ -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));
@@ -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;
@@ -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;
@@ -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 =
@@ -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;
@@ -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;
@@ -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;
@@ -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));
@@ -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;
@@ -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))
@@ -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;
@@ -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;

@@ -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;
@@ -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));
+256 −256

File changed.

Preview size limit exceeded, changes collapsed.