aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/anubis.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/anubis.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/anubis.c')
-rw-r--r--crypto/anubis.c38
1 files changed, 13 insertions, 25 deletions
diff --git a/crypto/anubis.c b/crypto/anubis.c
index 3925eb0133cb..94c4b1f3e3a7 100644
--- a/crypto/anubis.c
+++ b/crypto/anubis.c
@@ -32,8 +32,10 @@
32#include <linux/init.h> 32#include <linux/init.h>
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/mm.h> 34#include <linux/mm.h>
35#include <asm/byteorder.h>
35#include <asm/scatterlist.h> 36#include <asm/scatterlist.h>
36#include <linux/crypto.h> 37#include <linux/crypto.h>
38#include <linux/types.h>
37 39
38#define ANUBIS_MIN_KEY_SIZE 16 40#define ANUBIS_MIN_KEY_SIZE 16
39#define ANUBIS_MAX_KEY_SIZE 40 41#define ANUBIS_MAX_KEY_SIZE 40
@@ -461,8 +463,8 @@ static const u32 rc[] = {
461static int anubis_setkey(void *ctx_arg, const u8 *in_key, 463static int anubis_setkey(void *ctx_arg, const u8 *in_key,
462 unsigned int key_len, u32 *flags) 464 unsigned int key_len, u32 *flags)
463{ 465{
464 466 const __be32 *key = (const __be32 *)in_key;
465 int N, R, i, pos, r; 467 int N, R, i, r;
466 u32 kappa[ANUBIS_MAX_N]; 468 u32 kappa[ANUBIS_MAX_N];
467 u32 inter[ANUBIS_MAX_N]; 469 u32 inter[ANUBIS_MAX_N];
468 470
@@ -483,13 +485,8 @@ static int anubis_setkey(void *ctx_arg, const u8 *in_key,
483 ctx->R = R = 8 + N; 485 ctx->R = R = 8 + N;
484 486
485 /* * map cipher key to initial key state (mu): */ 487 /* * map cipher key to initial key state (mu): */
486 for (i = 0, pos = 0; i < N; i++, pos += 4) { 488 for (i = 0; i < N; i++)
487 kappa[i] = 489 kappa[i] = be32_to_cpu(key[i]);
488 (in_key[pos ] << 24) ^
489 (in_key[pos + 1] << 16) ^
490 (in_key[pos + 2] << 8) ^
491 (in_key[pos + 3] );
492 }
493 490
494 /* 491 /*
495 * generate R + 1 round keys: 492 * generate R + 1 round keys:
@@ -578,7 +575,9 @@ static int anubis_setkey(void *ctx_arg, const u8 *in_key,
578static void anubis_crypt(u32 roundKey[ANUBIS_MAX_ROUNDS + 1][4], 575static void anubis_crypt(u32 roundKey[ANUBIS_MAX_ROUNDS + 1][4],
579 u8 *ciphertext, const u8 *plaintext, const int R) 576 u8 *ciphertext, const u8 *plaintext, const int R)
580{ 577{
581 int i, pos, r; 578 const __be32 *src = (const __be32 *)plaintext;
579 __be32 *dst = (__be32 *)ciphertext;
580 int i, r;
582 u32 state[4]; 581 u32 state[4];
583 u32 inter[4]; 582 u32 inter[4];
584 583
@@ -586,14 +585,8 @@ static void anubis_crypt(u32 roundKey[ANUBIS_MAX_ROUNDS + 1][4],
586 * map plaintext block to cipher state (mu) 585 * map plaintext block to cipher state (mu)
587 * and add initial round key (sigma[K^0]): 586 * and add initial round key (sigma[K^0]):
588 */ 587 */
589 for (i = 0, pos = 0; i < 4; i++, pos += 4) { 588 for (i = 0; i < 4; i++)
590 state[i] = 589 state[i] = be32_to_cpu(src[i]) ^ roundKey[0][i];
591 (plaintext[pos ] << 24) ^
592 (plaintext[pos + 1] << 16) ^
593 (plaintext[pos + 2] << 8) ^
594 (plaintext[pos + 3] ) ^
595 roundKey[0][i];
596 }
597 590
598 /* 591 /*
599 * R - 1 full rounds: 592 * R - 1 full rounds:
@@ -663,13 +656,8 @@ static void anubis_crypt(u32 roundKey[ANUBIS_MAX_ROUNDS + 1][4],
663 * map cipher state to ciphertext block (mu^{-1}): 656 * map cipher state to ciphertext block (mu^{-1}):
664 */ 657 */
665 658
666 for (i = 0, pos = 0; i < 4; i++, pos += 4) { 659 for (i = 0; i < 4; i++)
667 u32 w = inter[i]; 660 dst[i] = cpu_to_be32(inter[i]);
668 ciphertext[pos ] = (u8)(w >> 24);
669 ciphertext[pos + 1] = (u8)(w >> 16);
670 ciphertext[pos + 2] = (u8)(w >> 8);
671 ciphertext[pos + 3] = (u8)(w );
672 }
673} 661}
674 662
675static void anubis_encrypt(void *ctx_arg, u8 *dst, const u8 *src) 663static void anubis_encrypt(void *ctx_arg, u8 *dst, const u8 *src)