aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/khazad.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/khazad.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/khazad.c')
-rw-r--r--crypto/khazad.c45
1 files changed, 9 insertions, 36 deletions
diff --git a/crypto/khazad.c b/crypto/khazad.c
index 738cb0dd1e7c..6809210362c1 100644
--- a/crypto/khazad.c
+++ b/crypto/khazad.c
@@ -22,8 +22,10 @@
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/mm.h> 24#include <linux/mm.h>
25#include <asm/byteorder.h>
25#include <asm/scatterlist.h> 26#include <asm/scatterlist.h>
26#include <linux/crypto.h> 27#include <linux/crypto.h>
28#include <linux/types.h>
27 29
28#define KHAZAD_KEY_SIZE 16 30#define KHAZAD_KEY_SIZE 16
29#define KHAZAD_BLOCK_SIZE 8 31#define KHAZAD_BLOCK_SIZE 8
@@ -755,8 +757,8 @@ static const u64 c[KHAZAD_ROUNDS + 1] = {
755static int khazad_setkey(void *ctx_arg, const u8 *in_key, 757static int khazad_setkey(void *ctx_arg, const u8 *in_key,
756 unsigned int key_len, u32 *flags) 758 unsigned int key_len, u32 *flags)
757{ 759{
758
759 struct khazad_ctx *ctx = ctx_arg; 760 struct khazad_ctx *ctx = ctx_arg;
761 const __be64 *key = (const __be64 *)in_key;
760 int r; 762 int r;
761 const u64 *S = T7; 763 const u64 *S = T7;
762 u64 K2, K1; 764 u64 K2, K1;
@@ -767,22 +769,8 @@ static int khazad_setkey(void *ctx_arg, const u8 *in_key,
767 return -EINVAL; 769 return -EINVAL;
768 } 770 }
769 771
770 K2 = ((u64)in_key[ 0] << 56) ^ 772 K2 = be64_to_cpu(key[0]);
771 ((u64)in_key[ 1] << 48) ^ 773 K1 = be64_to_cpu(key[1]);
772 ((u64)in_key[ 2] << 40) ^
773 ((u64)in_key[ 3] << 32) ^
774 ((u64)in_key[ 4] << 24) ^
775 ((u64)in_key[ 5] << 16) ^
776 ((u64)in_key[ 6] << 8) ^
777 ((u64)in_key[ 7] );
778 K1 = ((u64)in_key[ 8] << 56) ^
779 ((u64)in_key[ 9] << 48) ^
780 ((u64)in_key[10] << 40) ^
781 ((u64)in_key[11] << 32) ^
782 ((u64)in_key[12] << 24) ^
783 ((u64)in_key[13] << 16) ^
784 ((u64)in_key[14] << 8) ^
785 ((u64)in_key[15] );
786 774
787 /* setup the encrypt key */ 775 /* setup the encrypt key */
788 for (r = 0; r <= KHAZAD_ROUNDS; r++) { 776 for (r = 0; r <= KHAZAD_ROUNDS; r++) {
@@ -820,19 +808,12 @@ static int khazad_setkey(void *ctx_arg, const u8 *in_key,
820static void khazad_crypt(const u64 roundKey[KHAZAD_ROUNDS + 1], 808static void khazad_crypt(const u64 roundKey[KHAZAD_ROUNDS + 1],
821 u8 *ciphertext, const u8 *plaintext) 809 u8 *ciphertext, const u8 *plaintext)
822{ 810{
823 811 const __be64 *src = (const __be64 *)plaintext;
812 __be64 *dst = (__be64 *)ciphertext;
824 int r; 813 int r;
825 u64 state; 814 u64 state;
826 815
827 state = ((u64)plaintext[0] << 56) ^ 816 state = be64_to_cpu(*src) ^ roundKey[0];
828 ((u64)plaintext[1] << 48) ^
829 ((u64)plaintext[2] << 40) ^
830 ((u64)plaintext[3] << 32) ^
831 ((u64)plaintext[4] << 24) ^
832 ((u64)plaintext[5] << 16) ^
833 ((u64)plaintext[6] << 8) ^
834 ((u64)plaintext[7] ) ^
835 roundKey[0];
836 817
837 for (r = 1; r < KHAZAD_ROUNDS; r++) { 818 for (r = 1; r < KHAZAD_ROUNDS; r++) {
838 state = T0[(int)(state >> 56) ] ^ 819 state = T0[(int)(state >> 56) ] ^
@@ -856,15 +837,7 @@ static void khazad_crypt(const u64 roundKey[KHAZAD_ROUNDS + 1],
856 (T7[(int)(state ) & 0xff] & 0x00000000000000ffULL) ^ 837 (T7[(int)(state ) & 0xff] & 0x00000000000000ffULL) ^
857 roundKey[KHAZAD_ROUNDS]; 838 roundKey[KHAZAD_ROUNDS];
858 839
859 ciphertext[0] = (u8)(state >> 56); 840 *dst = cpu_to_be64(state);
860 ciphertext[1] = (u8)(state >> 48);
861 ciphertext[2] = (u8)(state >> 40);
862 ciphertext[3] = (u8)(state >> 32);
863 ciphertext[4] = (u8)(state >> 24);
864 ciphertext[5] = (u8)(state >> 16);
865 ciphertext[6] = (u8)(state >> 8);
866 ciphertext[7] = (u8)(state );
867
868} 841}
869 842
870static void khazad_encrypt(void *ctx_arg, u8 *dst, const u8 *src) 843static void khazad_encrypt(void *ctx_arg, u8 *dst, const u8 *src)