Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[CRYPTO] twofish: Use rol32/ror32 where appropriate

Convert open coded rotations to rol32/ror32.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Denis Vlasenko and committed by
Herbert Xu
a5f8c473 c4a1745a

+11 -10
+11 -10
crypto/twofish.c
··· 44 44 #include <linux/types.h> 45 45 #include <linux/errno.h> 46 46 #include <linux/crypto.h> 47 + #include <linux/bitops.h> 47 48 48 49 49 50 /* The large precomputed tables for the Twofish cipher (twofish.c) ··· 543 542 #define CALC_K(a, j, k, l, m, n) \ 544 543 x = CALC_K_2 (k, l, k, l, 0); \ 545 544 y = CALC_K_2 (m, n, m, n, 4); \ 546 - y = (y << 8) + (y >> 24); \ 545 + y = rol32(y, 8); \ 547 546 x += y; y += x; ctx->a[j] = x; \ 548 - ctx->a[(j) + 1] = (y << 9) + (y >> 23) 547 + ctx->a[(j) + 1] = rol32(y, 9) 549 548 550 549 #define CALC_K192_2(a, b, c, d, j) \ 551 550 CALC_K_2 (q0[a ^ key[(j) + 16]], \ ··· 556 555 #define CALC_K192(a, j, k, l, m, n) \ 557 556 x = CALC_K192_2 (l, l, k, k, 0); \ 558 557 y = CALC_K192_2 (n, n, m, m, 4); \ 559 - y = (y << 8) + (y >> 24); \ 558 + y = rol32(y, 8); \ 560 559 x += y; y += x; ctx->a[j] = x; \ 561 - ctx->a[(j) + 1] = (y << 9) + (y >> 23) 560 + ctx->a[(j) + 1] = rol32(y, 9) 562 561 563 562 #define CALC_K256_2(a, b, j) \ 564 563 CALC_K192_2 (q1[b ^ key[(j) + 24]], \ ··· 569 568 #define CALC_K256(a, j, k, l, m, n) \ 570 569 x = CALC_K256_2 (k, l, 0); \ 571 570 y = CALC_K256_2 (m, n, 4); \ 572 - y = (y << 8) + (y >> 24); \ 571 + y = rol32(y, 8); \ 573 572 x += y; y += x; ctx->a[j] = x; \ 574 - ctx->a[(j) + 1] = (y << 9) + (y >> 23) 573 + ctx->a[(j) + 1] = rol32(y, 9) 575 574 576 575 577 576 /* Macros to compute the g() function in the encryption and decryption ··· 595 594 x = G1 (a); y = G2 (b); \ 596 595 x += y; y += x + ctx->k[2 * (n) + 1]; \ 597 596 (c) ^= x + ctx->k[2 * (n)]; \ 598 - (c) = ((c) >> 1) + ((c) << 31); \ 599 - (d) = (((d) << 1)+((d) >> 31)) ^ y 597 + (c) = ror32((c), 1); \ 598 + (d) = rol32((d), 1) ^ y 600 599 601 600 #define DECROUND(n, a, b, c, d) \ 602 601 x = G1 (a); y = G2 (b); \ 603 602 x += y; y += x; \ 604 603 (d) ^= y + ctx->k[2 * (n) + 1]; \ 605 - (d) = ((d) >> 1) + ((d) << 31); \ 606 - (c) = (((c) << 1)+((c) >> 31)); \ 604 + (d) = ror32((d), 1); \ 605 + (c) = rol32((c), 1); \ 607 606 (c) ^= (x + ctx->k[2 * (n)]) 608 607 609 608 /* Encryption and decryption cycles; each one is simply two Feistel rounds