diff options
Diffstat (limited to 'crypto/testmgr.c')
-rw-r--r-- | crypto/testmgr.c | 66 |
1 files changed, 48 insertions, 18 deletions
diff --git a/crypto/testmgr.c b/crypto/testmgr.c index c494d7610be1..5c8aaa0cb0b9 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c | |||
@@ -153,8 +153,21 @@ static void testmgr_free_buf(char *buf[XBUFSIZE]) | |||
153 | free_page((unsigned long)buf[i]); | 153 | free_page((unsigned long)buf[i]); |
154 | } | 154 | } |
155 | 155 | ||
156 | static int do_one_async_hash_op(struct ahash_request *req, | ||
157 | struct tcrypt_result *tr, | ||
158 | int ret) | ||
159 | { | ||
160 | if (ret == -EINPROGRESS || ret == -EBUSY) { | ||
161 | ret = wait_for_completion_interruptible(&tr->completion); | ||
162 | if (!ret) | ||
163 | ret = tr->err; | ||
164 | INIT_COMPLETION(tr->completion); | ||
165 | } | ||
166 | return ret; | ||
167 | } | ||
168 | |||
156 | static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, | 169 | static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, |
157 | unsigned int tcount) | 170 | unsigned int tcount, bool use_digest) |
158 | { | 171 | { |
159 | const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm)); | 172 | const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm)); |
160 | unsigned int i, j, k, temp; | 173 | unsigned int i, j, k, temp; |
@@ -206,23 +219,36 @@ static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template, | |||
206 | } | 219 | } |
207 | 220 | ||
208 | ahash_request_set_crypt(req, sg, result, template[i].psize); | 221 | ahash_request_set_crypt(req, sg, result, template[i].psize); |
209 | ret = crypto_ahash_digest(req); | 222 | if (use_digest) { |
210 | switch (ret) { | 223 | ret = do_one_async_hash_op(req, &tresult, |
211 | case 0: | 224 | crypto_ahash_digest(req)); |
212 | break; | 225 | if (ret) { |
213 | case -EINPROGRESS: | 226 | pr_err("alg: hash: digest failed on test %d " |
214 | case -EBUSY: | 227 | "for %s: ret=%d\n", j, algo, -ret); |
215 | ret = wait_for_completion_interruptible( | 228 | goto out; |
216 | &tresult.completion); | 229 | } |
217 | if (!ret && !(ret = tresult.err)) { | 230 | } else { |
218 | INIT_COMPLETION(tresult.completion); | 231 | ret = do_one_async_hash_op(req, &tresult, |
219 | break; | 232 | crypto_ahash_init(req)); |
233 | if (ret) { | ||
234 | pr_err("alt: hash: init failed on test %d " | ||
235 | "for %s: ret=%d\n", j, algo, -ret); | ||
236 | goto out; | ||
237 | } | ||
238 | ret = do_one_async_hash_op(req, &tresult, | ||
239 | crypto_ahash_update(req)); | ||
240 | if (ret) { | ||
241 | pr_err("alt: hash: update failed on test %d " | ||
242 | "for %s: ret=%d\n", j, algo, -ret); | ||
243 | goto out; | ||
244 | } | ||
245 | ret = do_one_async_hash_op(req, &tresult, | ||
246 | crypto_ahash_final(req)); | ||
247 | if (ret) { | ||
248 | pr_err("alt: hash: final failed on test %d " | ||
249 | "for %s: ret=%d\n", j, algo, -ret); | ||
250 | goto out; | ||
220 | } | 251 | } |
221 | /* fall through */ | ||
222 | default: | ||
223 | printk(KERN_ERR "alg: hash: digest failed on test %d " | ||
224 | "for %s: ret=%d\n", j, algo, -ret); | ||
225 | goto out; | ||
226 | } | 252 | } |
227 | 253 | ||
228 | if (memcmp(result, template[i].digest, | 254 | if (memcmp(result, template[i].digest, |
@@ -1402,7 +1428,11 @@ static int alg_test_hash(const struct alg_test_desc *desc, const char *driver, | |||
1402 | return PTR_ERR(tfm); | 1428 | return PTR_ERR(tfm); |
1403 | } | 1429 | } |
1404 | 1430 | ||
1405 | err = test_hash(tfm, desc->suite.hash.vecs, desc->suite.hash.count); | 1431 | err = test_hash(tfm, desc->suite.hash.vecs, |
1432 | desc->suite.hash.count, true); | ||
1433 | if (!err) | ||
1434 | err = test_hash(tfm, desc->suite.hash.vecs, | ||
1435 | desc->suite.hash.count, false); | ||
1406 | 1436 | ||
1407 | crypto_free_ahash(tfm); | 1437 | crypto_free_ahash(tfm); |
1408 | return err; | 1438 | return err; |