aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/twofish.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2005-10-30 05:25:15 -0500
committerDavid S. Miller <davem@sunset.davemloft.net>2006-01-09 17:15:34 -0500
commit06ace7a9bafeb9047352707eb79e8eaa0dfdf5f2 (patch)
treefa22bbc2e8ea5bee00b6aec353783144b6f8735a /crypto/twofish.c
parent2df15fffc612b53b2c8e4ff3c981a82441bc00ae (diff)
[CRYPTO] Use standard byte order macros wherever possible
A lot of crypto code needs to read/write a 32-bit/64-bit words in a specific gender. Many of them open code them by reading/writing one byte at a time. This patch converts all the applicable usages over to use the standard byte order macros. This is based on a previous patch by Denis Vlasenko. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/twofish.c')
-rw-r--r--crypto/twofish.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/crypto/twofish.c b/crypto/twofish.c
index 4efff8cf9958..b501d5ab9c45 100644
--- a/crypto/twofish.c
+++ b/crypto/twofish.c
@@ -37,6 +37,8 @@
37 * Abstract Algebra_ by Joseph A. Gallian, especially chapter 22 in the 37 * Abstract Algebra_ by Joseph A. Gallian, especially chapter 22 in the
38 * Third Edition. 38 * Third Edition.
39 */ 39 */
40
41#include <asm/byteorder.h>
40#include <linux/module.h> 42#include <linux/module.h>
41#include <linux/init.h> 43#include <linux/init.h>
42#include <linux/types.h> 44#include <linux/types.h>
@@ -621,13 +623,11 @@ static const u8 calc_sb_tbl[512] = {
621 * whitening subkey number m. */ 623 * whitening subkey number m. */
622 624
623#define INPACK(n, x, m) \ 625#define INPACK(n, x, m) \
624 x = in[4 * (n)] ^ (in[4 * (n) + 1] << 8) \ 626 x = le32_to_cpu(src[n]) ^ ctx->w[m]
625 ^ (in[4 * (n) + 2] << 16) ^ (in[4 * (n) + 3] << 24) ^ ctx->w[m]
626 627
627#define OUTUNPACK(n, x, m) \ 628#define OUTUNPACK(n, x, m) \
628 x ^= ctx->w[m]; \ 629 x ^= ctx->w[m]; \
629 out[4 * (n)] = x; out[4 * (n) + 1] = x >> 8; \ 630 dst[n] = cpu_to_le32(x)
630 out[4 * (n) + 2] = x >> 16; out[4 * (n) + 3] = x >> 24
631 631
632#define TF_MIN_KEY_SIZE 16 632#define TF_MIN_KEY_SIZE 16
633#define TF_MAX_KEY_SIZE 32 633#define TF_MAX_KEY_SIZE 32
@@ -804,6 +804,8 @@ static int twofish_setkey(void *cx, const u8 *key,
804static void twofish_encrypt(void *cx, u8 *out, const u8 *in) 804static void twofish_encrypt(void *cx, u8 *out, const u8 *in)
805{ 805{
806 struct twofish_ctx *ctx = cx; 806 struct twofish_ctx *ctx = cx;
807 const __le32 *src = (const __le32 *)in;
808 __le32 *dst = (__le32 *)out;
807 809
808 /* The four 32-bit chunks of the text. */ 810 /* The four 32-bit chunks of the text. */
809 u32 a, b, c, d; 811 u32 a, b, c, d;
@@ -839,6 +841,8 @@ static void twofish_encrypt(void *cx, u8 *out, const u8 *in)
839static void twofish_decrypt(void *cx, u8 *out, const u8 *in) 841static void twofish_decrypt(void *cx, u8 *out, const u8 *in)
840{ 842{
841 struct twofish_ctx *ctx = cx; 843 struct twofish_ctx *ctx = cx;
844 const __le32 *src = (const __le32 *)in;
845 __le32 *dst = (__le32 *)out;
842 846
843 /* The four 32-bit chunks of the text. */ 847 /* The four 32-bit chunks of the text. */
844 u32 a, b, c, d; 848 u32 a, b, c, d;