aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/tgr192.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/tgr192.c')
-rw-r--r--crypto/tgr192.c64
1 files changed, 17 insertions, 47 deletions
diff --git a/crypto/tgr192.c b/crypto/tgr192.c
index f0a45cf716d0..2d8e44f6fbe9 100644
--- a/crypto/tgr192.c
+++ b/crypto/tgr192.c
@@ -24,8 +24,10 @@
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/mm.h> 26#include <linux/mm.h>
27#include <asm/byteorder.h>
27#include <asm/scatterlist.h> 28#include <asm/scatterlist.h>
28#include <linux/crypto.h> 29#include <linux/crypto.h>
30#include <linux/types.h>
29 31
30#define TGR192_DIGEST_SIZE 24 32#define TGR192_DIGEST_SIZE 24
31#define TGR160_DIGEST_SIZE 20 33#define TGR160_DIGEST_SIZE 20
@@ -467,18 +469,10 @@ static void tgr192_transform(struct tgr192_ctx *tctx, const u8 * data)
467 u64 a, b, c, aa, bb, cc; 469 u64 a, b, c, aa, bb, cc;
468 u64 x[8]; 470 u64 x[8];
469 int i; 471 int i;
470 const u8 *ptr = data; 472 const __le64 *ptr = (const __le64 *)data;
471 473
472 for (i = 0; i < 8; i++, ptr += 8) { 474 for (i = 0; i < 8; i++)
473 x[i] = (((u64)ptr[7] ) << 56) ^ 475 x[i] = le64_to_cpu(ptr[i]);
474 (((u64)ptr[6] & 0xffL) << 48) ^
475 (((u64)ptr[5] & 0xffL) << 40) ^
476 (((u64)ptr[4] & 0xffL) << 32) ^
477 (((u64)ptr[3] & 0xffL) << 24) ^
478 (((u64)ptr[2] & 0xffL) << 16) ^
479 (((u64)ptr[1] & 0xffL) << 8) ^
480 (((u64)ptr[0] & 0xffL) );
481 }
482 476
483 /* save */ 477 /* save */
484 a = aa = tctx->a; 478 a = aa = tctx->a;
@@ -558,9 +552,10 @@ static void tgr192_update(void *ctx, const u8 * inbuf, unsigned int len)
558static void tgr192_final(void *ctx, u8 * out) 552static void tgr192_final(void *ctx, u8 * out)
559{ 553{
560 struct tgr192_ctx *tctx = ctx; 554 struct tgr192_ctx *tctx = ctx;
555 __be64 *dst = (__be64 *)out;
556 __be64 *be64p;
557 __le32 *le32p;
561 u32 t, msb, lsb; 558 u32 t, msb, lsb;
562 u8 *p;
563 int i, j;
564 559
565 tgr192_update(tctx, NULL, 0); /* flush */ ; 560 tgr192_update(tctx, NULL, 0); /* flush */ ;
566 561
@@ -594,41 +589,16 @@ static void tgr192_final(void *ctx, u8 * out)
594 memset(tctx->hash, 0, 56); /* fill next block with zeroes */ 589 memset(tctx->hash, 0, 56); /* fill next block with zeroes */
595 } 590 }
596 /* append the 64 bit count */ 591 /* append the 64 bit count */
597 tctx->hash[56] = lsb; 592 le32p = (__le32 *)&tctx->hash[56];
598 tctx->hash[57] = lsb >> 8; 593 le32p[0] = cpu_to_le32(lsb);
599 tctx->hash[58] = lsb >> 16; 594 le32p[1] = cpu_to_le32(msb);
600 tctx->hash[59] = lsb >> 24; 595
601 tctx->hash[60] = msb;
602 tctx->hash[61] = msb >> 8;
603 tctx->hash[62] = msb >> 16;
604 tctx->hash[63] = msb >> 24;
605 tgr192_transform(tctx, tctx->hash); 596 tgr192_transform(tctx, tctx->hash);
606 597
607 p = tctx->hash; 598 be64p = (__be64 *)tctx->hash;
608 *p++ = tctx->a >> 56; *p++ = tctx->a >> 48; *p++ = tctx->a >> 40; 599 dst[0] = be64p[0] = cpu_to_be64(tctx->a);
609 *p++ = tctx->a >> 32; *p++ = tctx->a >> 24; *p++ = tctx->a >> 16; 600 dst[1] = be64p[1] = cpu_to_be64(tctx->b);
610 *p++ = tctx->a >> 8; *p++ = tctx->a;\ 601 dst[2] = be64p[2] = cpu_to_be64(tctx->c);
611 *p++ = tctx->b >> 56; *p++ = tctx->b >> 48; *p++ = tctx->b >> 40;
612 *p++ = tctx->b >> 32; *p++ = tctx->b >> 24; *p++ = tctx->b >> 16;
613 *p++ = tctx->b >> 8; *p++ = tctx->b;
614 *p++ = tctx->c >> 56; *p++ = tctx->c >> 48; *p++ = tctx->c >> 40;
615 *p++ = tctx->c >> 32; *p++ = tctx->c >> 24; *p++ = tctx->c >> 16;
616 *p++ = tctx->c >> 8; *p++ = tctx->c;
617
618
619 /* unpack the hash */
620 j = 7;
621 for (i = 0; i < 8; i++) {
622 out[j--] = (tctx->a >> 8 * i) & 0xff;
623 }
624 j = 15;
625 for (i = 0; i < 8; i++) {
626 out[j--] = (tctx->b >> 8 * i) & 0xff;
627 }
628 j = 23;
629 for (i = 0; i < 8; i++) {
630 out[j--] = (tctx->c >> 8 * i) & 0xff;
631 }
632} 602}
633 603
634static void tgr160_final(void *ctx, u8 * out) 604static void tgr160_final(void *ctx, u8 * out)