Commit 6e5972fa authored by Eric Biggers's avatar Eric Biggers Committed by Herbert Xu

crypto: testmgr - always print the actual skcipher driver name

When alg_test() is called from tcrypt.ko rather than from the algorithm
registration code, "driver" is actually the algorithm name, not the
driver name.  So it shouldn't be used in places where a driver name is
wanted, e.g. when reporting a test failure or when checking whether the
driver is the generic driver or not.

Fix this for the skcipher algorithm tests by getting the driver name
from the crypto_skcipher that actually got allocated.
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 2257f471
...@@ -2685,8 +2685,7 @@ static int test_cipher(struct crypto_cipher *tfm, int enc, ...@@ -2685,8 +2685,7 @@ static int test_cipher(struct crypto_cipher *tfm, int enc,
return ret; return ret;
} }
static int test_skcipher_vec_cfg(const char *driver, int enc, static int test_skcipher_vec_cfg(int enc, const struct cipher_testvec *vec,
const struct cipher_testvec *vec,
const char *vec_name, const char *vec_name,
const struct testvec_config *cfg, const struct testvec_config *cfg,
struct skcipher_request *req, struct skcipher_request *req,
...@@ -2695,6 +2694,7 @@ static int test_skcipher_vec_cfg(const char *driver, int enc, ...@@ -2695,6 +2694,7 @@ static int test_skcipher_vec_cfg(const char *driver, int enc,
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
const unsigned int alignmask = crypto_skcipher_alignmask(tfm); const unsigned int alignmask = crypto_skcipher_alignmask(tfm);
const unsigned int ivsize = crypto_skcipher_ivsize(tfm); const unsigned int ivsize = crypto_skcipher_ivsize(tfm);
const char *driver = crypto_skcipher_driver_name(tfm);
const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags; const u32 req_flags = CRYPTO_TFM_REQ_MAY_BACKLOG | cfg->req_flags;
const char *op = enc ? "encryption" : "decryption"; const char *op = enc ? "encryption" : "decryption";
DECLARE_CRYPTO_WAIT(wait); DECLARE_CRYPTO_WAIT(wait);
...@@ -2849,8 +2849,7 @@ static int test_skcipher_vec_cfg(const char *driver, int enc, ...@@ -2849,8 +2849,7 @@ static int test_skcipher_vec_cfg(const char *driver, int enc,
return 0; return 0;
} }
static int test_skcipher_vec(const char *driver, int enc, static int test_skcipher_vec(int enc, const struct cipher_testvec *vec,
const struct cipher_testvec *vec,
unsigned int vec_num, unsigned int vec_num,
struct skcipher_request *req, struct skcipher_request *req,
struct cipher_test_sglists *tsgls) struct cipher_test_sglists *tsgls)
...@@ -2865,7 +2864,7 @@ static int test_skcipher_vec(const char *driver, int enc, ...@@ -2865,7 +2864,7 @@ static int test_skcipher_vec(const char *driver, int enc,
sprintf(vec_name, "%u", vec_num); sprintf(vec_name, "%u", vec_num);
for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++) { for (i = 0; i < ARRAY_SIZE(default_cipher_testvec_configs); i++) {
err = test_skcipher_vec_cfg(driver, enc, vec, vec_name, err = test_skcipher_vec_cfg(enc, vec, vec_name,
&default_cipher_testvec_configs[i], &default_cipher_testvec_configs[i],
req, tsgls); req, tsgls);
if (err) if (err)
...@@ -2880,7 +2879,7 @@ static int test_skcipher_vec(const char *driver, int enc, ...@@ -2880,7 +2879,7 @@ static int test_skcipher_vec(const char *driver, int enc,
for (i = 0; i < fuzz_iterations; i++) { for (i = 0; i < fuzz_iterations; i++) {
generate_random_testvec_config(&cfg, cfgname, generate_random_testvec_config(&cfg, cfgname,
sizeof(cfgname)); sizeof(cfgname));
err = test_skcipher_vec_cfg(driver, enc, vec, vec_name, err = test_skcipher_vec_cfg(enc, vec, vec_name,
&cfg, req, tsgls); &cfg, req, tsgls);
if (err) if (err)
return err; return err;
...@@ -2951,8 +2950,7 @@ static void generate_random_cipher_testvec(struct skcipher_request *req, ...@@ -2951,8 +2950,7 @@ static void generate_random_cipher_testvec(struct skcipher_request *req,
* Test the skcipher algorithm represented by @req against the corresponding * Test the skcipher algorithm represented by @req against the corresponding
* generic implementation, if one is available. * generic implementation, if one is available.
*/ */
static int test_skcipher_vs_generic_impl(const char *driver, static int test_skcipher_vs_generic_impl(const char *generic_driver,
const char *generic_driver,
struct skcipher_request *req, struct skcipher_request *req,
struct cipher_test_sglists *tsgls) struct cipher_test_sglists *tsgls)
{ {
...@@ -2962,6 +2960,7 @@ static int test_skcipher_vs_generic_impl(const char *driver, ...@@ -2962,6 +2960,7 @@ static int test_skcipher_vs_generic_impl(const char *driver,
const unsigned int blocksize = crypto_skcipher_blocksize(tfm); const unsigned int blocksize = crypto_skcipher_blocksize(tfm);
const unsigned int maxdatasize = (2 * PAGE_SIZE) - TESTMGR_POISON_LEN; const unsigned int maxdatasize = (2 * PAGE_SIZE) - TESTMGR_POISON_LEN;
const char *algname = crypto_skcipher_alg(tfm)->base.cra_name; const char *algname = crypto_skcipher_alg(tfm)->base.cra_name;
const char *driver = crypto_skcipher_driver_name(tfm);
char _generic_driver[CRYPTO_MAX_ALG_NAME]; char _generic_driver[CRYPTO_MAX_ALG_NAME];
struct crypto_skcipher *generic_tfm = NULL; struct crypto_skcipher *generic_tfm = NULL;
struct skcipher_request *generic_req = NULL; struct skcipher_request *generic_req = NULL;
...@@ -3067,11 +3066,11 @@ static int test_skcipher_vs_generic_impl(const char *driver, ...@@ -3067,11 +3066,11 @@ static int test_skcipher_vs_generic_impl(const char *driver,
vec_name, sizeof(vec_name)); vec_name, sizeof(vec_name));
generate_random_testvec_config(cfg, cfgname, sizeof(cfgname)); generate_random_testvec_config(cfg, cfgname, sizeof(cfgname));
err = test_skcipher_vec_cfg(driver, ENCRYPT, &vec, vec_name, err = test_skcipher_vec_cfg(ENCRYPT, &vec, vec_name,
cfg, req, tsgls); cfg, req, tsgls);
if (err) if (err)
goto out; goto out;
err = test_skcipher_vec_cfg(driver, DECRYPT, &vec, vec_name, err = test_skcipher_vec_cfg(DECRYPT, &vec, vec_name,
cfg, req, tsgls); cfg, req, tsgls);
if (err) if (err)
goto out; goto out;
...@@ -3089,8 +3088,7 @@ static int test_skcipher_vs_generic_impl(const char *driver, ...@@ -3089,8 +3088,7 @@ static int test_skcipher_vs_generic_impl(const char *driver,
return err; return err;
} }
#else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */ #else /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
static int test_skcipher_vs_generic_impl(const char *driver, static int test_skcipher_vs_generic_impl(const char *generic_driver,
const char *generic_driver,
struct skcipher_request *req, struct skcipher_request *req,
struct cipher_test_sglists *tsgls) struct cipher_test_sglists *tsgls)
{ {
...@@ -3098,8 +3096,7 @@ static int test_skcipher_vs_generic_impl(const char *driver, ...@@ -3098,8 +3096,7 @@ static int test_skcipher_vs_generic_impl(const char *driver,
} }
#endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */ #endif /* !CONFIG_CRYPTO_MANAGER_EXTRA_TESTS */
static int test_skcipher(const char *driver, int enc, static int test_skcipher(int enc, const struct cipher_test_suite *suite,
const struct cipher_test_suite *suite,
struct skcipher_request *req, struct skcipher_request *req,
struct cipher_test_sglists *tsgls) struct cipher_test_sglists *tsgls)
{ {
...@@ -3107,8 +3104,7 @@ static int test_skcipher(const char *driver, int enc, ...@@ -3107,8 +3104,7 @@ static int test_skcipher(const char *driver, int enc,
int err; int err;
for (i = 0; i < suite->count; i++) { for (i = 0; i < suite->count; i++) {
err = test_skcipher_vec(driver, enc, &suite->vecs[i], i, req, err = test_skcipher_vec(enc, &suite->vecs[i], i, req, tsgls);
tsgls);
if (err) if (err)
return err; return err;
cond_resched(); cond_resched();
...@@ -3136,6 +3132,7 @@ static int alg_test_skcipher(const struct alg_test_desc *desc, ...@@ -3136,6 +3132,7 @@ static int alg_test_skcipher(const struct alg_test_desc *desc,
driver, PTR_ERR(tfm)); driver, PTR_ERR(tfm));
return PTR_ERR(tfm); return PTR_ERR(tfm);
} }
driver = crypto_skcipher_driver_name(tfm);
req = skcipher_request_alloc(tfm, GFP_KERNEL); req = skcipher_request_alloc(tfm, GFP_KERNEL);
if (!req) { if (!req) {
...@@ -3153,16 +3150,15 @@ static int alg_test_skcipher(const struct alg_test_desc *desc, ...@@ -3153,16 +3150,15 @@ static int alg_test_skcipher(const struct alg_test_desc *desc,
goto out; goto out;
} }
err = test_skcipher(driver, ENCRYPT, suite, req, tsgls); err = test_skcipher(ENCRYPT, suite, req, tsgls);
if (err) if (err)
goto out; goto out;
err = test_skcipher(driver, DECRYPT, suite, req, tsgls); err = test_skcipher(DECRYPT, suite, req, tsgls);
if (err) if (err)
goto out; goto out;
err = test_skcipher_vs_generic_impl(driver, desc->generic_driver, req, err = test_skcipher_vs_generic_impl(desc->generic_driver, req, tsgls);
tsgls);
out: out:
free_cipher_test_sglists(tsgls); free_cipher_test_sglists(tsgls);
skcipher_request_free(req); skcipher_request_free(req);
......
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