diff options
Diffstat (limited to 'crypto/tcrypt.c')
-rw-r--r-- | crypto/tcrypt.c | 44 |
1 files changed, 16 insertions, 28 deletions
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c index df93595c2c68..a6d4160c37f7 100644 --- a/crypto/tcrypt.c +++ b/crypto/tcrypt.c | |||
@@ -235,6 +235,7 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template, | |||
235 | struct scatterlist asg[8]; | 235 | struct scatterlist asg[8]; |
236 | const char *e; | 236 | const char *e; |
237 | struct tcrypt_result result; | 237 | struct tcrypt_result result; |
238 | unsigned int authsize; | ||
238 | 239 | ||
239 | if (enc == ENCRYPT) | 240 | if (enc == ENCRYPT) |
240 | e = "encryption"; | 241 | e = "encryption"; |
@@ -265,6 +266,8 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template, | |||
265 | return; | 266 | return; |
266 | } | 267 | } |
267 | 268 | ||
269 | authsize = crypto_aead_authsize(tfm); | ||
270 | |||
268 | req = aead_request_alloc(tfm, GFP_KERNEL); | 271 | req = aead_request_alloc(tfm, GFP_KERNEL); |
269 | if (!req) { | 272 | if (!req) { |
270 | printk(KERN_INFO "failed to allocate request for %s\n", algo); | 273 | printk(KERN_INFO "failed to allocate request for %s\n", algo); |
@@ -296,7 +299,7 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template, | |||
296 | } | 299 | } |
297 | 300 | ||
298 | sg_init_one(&sg[0], aead_tv[i].input, | 301 | sg_init_one(&sg[0], aead_tv[i].input, |
299 | aead_tv[i].ilen); | 302 | aead_tv[i].ilen + (enc ? authsize : 0)); |
300 | 303 | ||
301 | sg_init_one(&asg[0], aead_tv[i].assoc, | 304 | sg_init_one(&asg[0], aead_tv[i].assoc, |
302 | aead_tv[i].alen); | 305 | aead_tv[i].alen); |
@@ -307,13 +310,9 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template, | |||
307 | 310 | ||
308 | aead_request_set_assoc(req, asg, aead_tv[i].alen); | 311 | aead_request_set_assoc(req, asg, aead_tv[i].alen); |
309 | 312 | ||
310 | if (enc) { | 313 | ret = enc ? |
311 | ret = crypto_aead_encrypt(req); | 314 | crypto_aead_encrypt(req) : |
312 | } else { | 315 | crypto_aead_decrypt(req); |
313 | memcpy(req->__ctx, aead_tv[i].tag, | ||
314 | aead_tv[i].tlen); | ||
315 | ret = crypto_aead_decrypt(req); | ||
316 | } | ||
317 | 316 | ||
318 | switch (ret) { | 317 | switch (ret) { |
319 | case 0: | 318 | case 0: |
@@ -335,16 +334,10 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template, | |||
335 | 334 | ||
336 | q = kmap(sg_page(&sg[0])) + sg[0].offset; | 335 | q = kmap(sg_page(&sg[0])) + sg[0].offset; |
337 | hexdump(q, aead_tv[i].rlen); | 336 | hexdump(q, aead_tv[i].rlen); |
338 | printk(KERN_INFO "auth tag: "); | ||
339 | hexdump((unsigned char *)req->__ctx, aead_tv[i].tlen); | ||
340 | 337 | ||
341 | printk(KERN_INFO "enc/dec: %s\n", | 338 | printk(KERN_INFO "enc/dec: %s\n", |
342 | memcmp(q, aead_tv[i].result, | 339 | memcmp(q, aead_tv[i].result, |
343 | aead_tv[i].rlen) ? "fail" : "pass"); | 340 | aead_tv[i].rlen) ? "fail" : "pass"); |
344 | |||
345 | printk(KERN_INFO "auth tag: %s\n", | ||
346 | memcmp(req->__ctx, aead_tv[i].tag, | ||
347 | aead_tv[i].tlen) ? "fail" : "pass"); | ||
348 | } | 341 | } |
349 | } | 342 | } |
350 | 343 | ||
@@ -381,6 +374,9 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template, | |||
381 | aead_tv[i].tap[k]); | 374 | aead_tv[i].tap[k]); |
382 | } | 375 | } |
383 | 376 | ||
377 | if (enc) | ||
378 | sg[k - 1].length += authsize; | ||
379 | |||
384 | sg_init_table(asg, aead_tv[i].anp); | 380 | sg_init_table(asg, aead_tv[i].anp); |
385 | for (k = 0, temp = 0; k < aead_tv[i].anp; k++) { | 381 | for (k = 0, temp = 0; k < aead_tv[i].anp; k++) { |
386 | memcpy(&axbuf[IDX[k]], | 382 | memcpy(&axbuf[IDX[k]], |
@@ -397,13 +393,9 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template, | |||
397 | 393 | ||
398 | aead_request_set_assoc(req, asg, aead_tv[i].alen); | 394 | aead_request_set_assoc(req, asg, aead_tv[i].alen); |
399 | 395 | ||
400 | if (enc) { | 396 | ret = enc ? |
401 | ret = crypto_aead_encrypt(req); | 397 | crypto_aead_encrypt(req) : |
402 | } else { | 398 | crypto_aead_decrypt(req); |
403 | memcpy(req->__ctx, aead_tv[i].tag, | ||
404 | aead_tv[i].tlen); | ||
405 | ret = crypto_aead_decrypt(req); | ||
406 | } | ||
407 | 399 | ||
408 | switch (ret) { | 400 | switch (ret) { |
409 | case 0: | 401 | case 0: |
@@ -429,17 +421,13 @@ static void test_aead(char *algo, int enc, struct aead_testvec *template, | |||
429 | hexdump(q, aead_tv[i].tap[k]); | 421 | hexdump(q, aead_tv[i].tap[k]); |
430 | printk(KERN_INFO "%s\n", | 422 | printk(KERN_INFO "%s\n", |
431 | memcmp(q, aead_tv[i].result + temp, | 423 | memcmp(q, aead_tv[i].result + temp, |
432 | aead_tv[i].tap[k]) ? | 424 | aead_tv[i].tap[k] - |
425 | (k < aead_tv[i].np - 1 || enc ? | ||
426 | 0 : authsize)) ? | ||
433 | "fail" : "pass"); | 427 | "fail" : "pass"); |
434 | 428 | ||
435 | temp += aead_tv[i].tap[k]; | 429 | temp += aead_tv[i].tap[k]; |
436 | } | 430 | } |
437 | printk(KERN_INFO "auth tag: "); | ||
438 | hexdump((unsigned char *)req->__ctx, aead_tv[i].tlen); | ||
439 | |||
440 | printk(KERN_INFO "auth tag: %s\n", | ||
441 | memcmp(req->__ctx, aead_tv[i].tag, | ||
442 | aead_tv[i].tlen) ? "fail" : "pass"); | ||
443 | } | 431 | } |
444 | } | 432 | } |
445 | 433 | ||