aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/twofish.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda@ilport.com.ua>2006-01-16 01:42:28 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2006-03-21 04:14:08 -0500
commita5f8c473052bc693cdbe2f9ae4b424b993886ff5 (patch)
tree0ec45cbad059c744a27d85902ba2db6b0e960f41 /crypto/twofish.c
parentc4a1745aa09fc110afdefea0e5d025043e348bae (diff)
[CRYPTO] twofish: Use rol32/ror32 where appropriate
Convert open coded rotations to rol32/ror32. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/twofish.c')
-rw-r--r--crypto/twofish.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/crypto/twofish.c b/crypto/twofish.c
index a26d885486fb..ddfd5a3fcc5f 100644
--- a/crypto/twofish.c
+++ b/crypto/twofish.c
@@ -44,6 +44,7 @@
44#include <linux/types.h> 44#include <linux/types.h>
45#include <linux/errno.h> 45#include <linux/errno.h>
46#include <linux/crypto.h> 46#include <linux/crypto.h>
47#include <linux/bitops.h>
47 48
48 49
49/* The large precomputed tables for the Twofish cipher (twofish.c) 50/* The large precomputed tables for the Twofish cipher (twofish.c)
@@ -542,9 +543,9 @@ static const u8 calc_sb_tbl[512] = {
542#define CALC_K(a, j, k, l, m, n) \ 543#define CALC_K(a, j, k, l, m, n) \
543 x = CALC_K_2 (k, l, k, l, 0); \ 544 x = CALC_K_2 (k, l, k, l, 0); \
544 y = CALC_K_2 (m, n, m, n, 4); \ 545 y = CALC_K_2 (m, n, m, n, 4); \
545 y = (y << 8) + (y >> 24); \ 546 y = rol32(y, 8); \
546 x += y; y += x; ctx->a[j] = x; \ 547 x += y; y += x; ctx->a[j] = x; \
547 ctx->a[(j) + 1] = (y << 9) + (y >> 23) 548 ctx->a[(j) + 1] = rol32(y, 9)
548 549
549#define CALC_K192_2(a, b, c, d, j) \ 550#define CALC_K192_2(a, b, c, d, j) \
550 CALC_K_2 (q0[a ^ key[(j) + 16]], \ 551 CALC_K_2 (q0[a ^ key[(j) + 16]], \
@@ -555,9 +556,9 @@ static const u8 calc_sb_tbl[512] = {
555#define CALC_K192(a, j, k, l, m, n) \ 556#define CALC_K192(a, j, k, l, m, n) \
556 x = CALC_K192_2 (l, l, k, k, 0); \ 557 x = CALC_K192_2 (l, l, k, k, 0); \
557 y = CALC_K192_2 (n, n, m, m, 4); \ 558 y = CALC_K192_2 (n, n, m, m, 4); \
558 y = (y << 8) + (y >> 24); \ 559 y = rol32(y, 8); \
559 x += y; y += x; ctx->a[j] = x; \ 560 x += y; y += x; ctx->a[j] = x; \
560 ctx->a[(j) + 1] = (y << 9) + (y >> 23) 561 ctx->a[(j) + 1] = rol32(y, 9)
561 562
562#define CALC_K256_2(a, b, j) \ 563#define CALC_K256_2(a, b, j) \
563 CALC_K192_2 (q1[b ^ key[(j) + 24]], \ 564 CALC_K192_2 (q1[b ^ key[(j) + 24]], \
@@ -568,9 +569,9 @@ static const u8 calc_sb_tbl[512] = {
568#define CALC_K256(a, j, k, l, m, n) \ 569#define CALC_K256(a, j, k, l, m, n) \
569 x = CALC_K256_2 (k, l, 0); \ 570 x = CALC_K256_2 (k, l, 0); \
570 y = CALC_K256_2 (m, n, 4); \ 571 y = CALC_K256_2 (m, n, 4); \
571 y = (y << 8) + (y >> 24); \ 572 y = rol32(y, 8); \
572 x += y; y += x; ctx->a[j] = x; \ 573 x += y; y += x; ctx->a[j] = x; \
573 ctx->a[(j) + 1] = (y << 9) + (y >> 23) 574 ctx->a[(j) + 1] = rol32(y, 9)
574 575
575 576
576/* Macros to compute the g() function in the encryption and decryption 577/* Macros to compute the g() function in the encryption and decryption
@@ -594,15 +595,15 @@ static const u8 calc_sb_tbl[512] = {
594 x = G1 (a); y = G2 (b); \ 595 x = G1 (a); y = G2 (b); \
595 x += y; y += x + ctx->k[2 * (n) + 1]; \ 596 x += y; y += x + ctx->k[2 * (n) + 1]; \
596 (c) ^= x + ctx->k[2 * (n)]; \ 597 (c) ^= x + ctx->k[2 * (n)]; \
597 (c) = ((c) >> 1) + ((c) << 31); \ 598 (c) = ror32((c), 1); \
598 (d) = (((d) << 1)+((d) >> 31)) ^ y 599 (d) = rol32((d), 1) ^ y
599 600
600#define DECROUND(n, a, b, c, d) \ 601#define DECROUND(n, a, b, c, d) \
601 x = G1 (a); y = G2 (b); \ 602 x = G1 (a); y = G2 (b); \
602 x += y; y += x; \ 603 x += y; y += x; \
603 (d) ^= y + ctx->k[2 * (n) + 1]; \ 604 (d) ^= y + ctx->k[2 * (n) + 1]; \
604 (d) = ((d) >> 1) + ((d) << 31); \ 605 (d) = ror32((d), 1); \
605 (c) = (((c) << 1)+((c) >> 31)); \ 606 (c) = rol32((c), 1); \
606 (c) ^= (x + ctx->k[2 * (n)]) 607 (c) ^= (x + ctx->k[2 * (n)])
607 608
608/* Encryption and decryption cycles; each one is simply two Feistel rounds 609/* Encryption and decryption cycles; each one is simply two Feistel rounds