summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorKamil Konieczny <k.konieczny@partner.samsung.com>2018-01-16 09:26:13 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2018-01-25 09:10:29 -0500
commit466d7b9f6175e4ecd409f619ff9fbbd49467ad66 (patch)
tree842c245b900ad81257b702f471234ff8c37b9035 /crypto
parent059bfd1171069025dc134a95f7fcce27483fba41 (diff)
crypto: testmgr - test misuse of result in ahash
Async hash operations can use result pointer in final/finup/digest, but not in init/update/export/import, so test it for misuse. Signed-off-by: Kamil Konieczny <k.konieczny@partner.samsung.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/testmgr.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index 44a85d4b3561..d5e23a142a04 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -177,6 +177,18 @@ static void testmgr_free_buf(char *buf[XBUFSIZE])
177 free_page((unsigned long)buf[i]); 177 free_page((unsigned long)buf[i]);
178} 178}
179 179
180static int ahash_guard_result(char *result, char c, int size)
181{
182 int i;
183
184 for (i = 0; i < size; i++) {
185 if (result[i] != c)
186 return -EINVAL;
187 }
188
189 return 0;
190}
191
180static int ahash_partial_update(struct ahash_request **preq, 192static int ahash_partial_update(struct ahash_request **preq,
181 struct crypto_ahash *tfm, const struct hash_testvec *template, 193 struct crypto_ahash *tfm, const struct hash_testvec *template,
182 void *hash_buff, int k, int temp, struct scatterlist *sg, 194 void *hash_buff, int k, int temp, struct scatterlist *sg,
@@ -186,6 +198,7 @@ static int ahash_partial_update(struct ahash_request **preq,
186 struct ahash_request *req; 198 struct ahash_request *req;
187 int statesize, ret = -EINVAL; 199 int statesize, ret = -EINVAL;
188 static const unsigned char guard[] = { 0x00, 0xba, 0xad, 0x00 }; 200 static const unsigned char guard[] = { 0x00, 0xba, 0xad, 0x00 };
201 int digestsize = crypto_ahash_digestsize(tfm);
189 202
190 req = *preq; 203 req = *preq;
191 statesize = crypto_ahash_statesize( 204 statesize = crypto_ahash_statesize(
@@ -196,12 +209,19 @@ static int ahash_partial_update(struct ahash_request **preq,
196 goto out_nostate; 209 goto out_nostate;
197 } 210 }
198 memcpy(state + statesize, guard, sizeof(guard)); 211 memcpy(state + statesize, guard, sizeof(guard));
212 memset(result, 1, digestsize);
199 ret = crypto_ahash_export(req, state); 213 ret = crypto_ahash_export(req, state);
200 WARN_ON(memcmp(state + statesize, guard, sizeof(guard))); 214 WARN_ON(memcmp(state + statesize, guard, sizeof(guard)));
201 if (ret) { 215 if (ret) {
202 pr_err("alg: hash: Failed to export() for %s\n", algo); 216 pr_err("alg: hash: Failed to export() for %s\n", algo);
203 goto out; 217 goto out;
204 } 218 }
219 ret = ahash_guard_result(result, 1, digestsize);
220 if (ret) {
221 pr_err("alg: hash: Failed, export used req->result for %s\n",
222 algo);
223 goto out;
224 }
205 ahash_request_free(req); 225 ahash_request_free(req);
206 req = ahash_request_alloc(tfm, GFP_KERNEL); 226 req = ahash_request_alloc(tfm, GFP_KERNEL);
207 if (!req) { 227 if (!req) {
@@ -221,6 +241,12 @@ static int ahash_partial_update(struct ahash_request **preq,
221 pr_err("alg: hash: Failed to import() for %s\n", algo); 241 pr_err("alg: hash: Failed to import() for %s\n", algo);
222 goto out; 242 goto out;
223 } 243 }
244 ret = ahash_guard_result(result, 1, digestsize);
245 if (ret) {
246 pr_err("alg: hash: Failed, import used req->result for %s\n",
247 algo);
248 goto out;
249 }
224 ret = crypto_wait_req(crypto_ahash_update(req), wait); 250 ret = crypto_wait_req(crypto_ahash_update(req), wait);
225 if (ret) 251 if (ret)
226 goto out; 252 goto out;
@@ -316,18 +342,31 @@ static int __test_hash(struct crypto_ahash *tfm,
316 goto out; 342 goto out;
317 } 343 }
318 } else { 344 } else {
345 memset(result, 1, digest_size);
319 ret = crypto_wait_req(crypto_ahash_init(req), &wait); 346 ret = crypto_wait_req(crypto_ahash_init(req), &wait);
320 if (ret) { 347 if (ret) {
321 pr_err("alg: hash: init failed on test %d " 348 pr_err("alg: hash: init failed on test %d "
322 "for %s: ret=%d\n", j, algo, -ret); 349 "for %s: ret=%d\n", j, algo, -ret);
323 goto out; 350 goto out;
324 } 351 }
352 ret = ahash_guard_result(result, 1, digest_size);
353 if (ret) {
354 pr_err("alg: hash: init failed on test %d "
355 "for %s: used req->result\n", j, algo);
356 goto out;
357 }
325 ret = crypto_wait_req(crypto_ahash_update(req), &wait); 358 ret = crypto_wait_req(crypto_ahash_update(req), &wait);
326 if (ret) { 359 if (ret) {
327 pr_err("alg: hash: update failed on test %d " 360 pr_err("alg: hash: update failed on test %d "
328 "for %s: ret=%d\n", j, algo, -ret); 361 "for %s: ret=%d\n", j, algo, -ret);
329 goto out; 362 goto out;
330 } 363 }
364 ret = ahash_guard_result(result, 1, digest_size);
365 if (ret) {
366 pr_err("alg: hash: update failed on test %d "
367 "for %s: used req->result\n", j, algo);
368 goto out;
369 }
331 ret = crypto_wait_req(crypto_ahash_final(req), &wait); 370 ret = crypto_wait_req(crypto_ahash_final(req), &wait);
332 if (ret) { 371 if (ret) {
333 pr_err("alg: hash: final failed on test %d " 372 pr_err("alg: hash: final failed on test %d "