diff options
Diffstat (limited to 'crypto/khazad.c')
| -rw-r--r-- | crypto/khazad.c | 46 |
1 files changed, 10 insertions, 36 deletions
diff --git a/crypto/khazad.c b/crypto/khazad.c index 738cb0dd1e7c..807f2bf4ea24 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] = { | |||
| 755 | static int khazad_setkey(void *ctx_arg, const u8 *in_key, | 757 | static 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, | |||
| 820 | static void khazad_crypt(const u64 roundKey[KHAZAD_ROUNDS + 1], | 808 | static 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 | ||
| 870 | static void khazad_encrypt(void *ctx_arg, u8 *dst, const u8 *src) | 843 | static void khazad_encrypt(void *ctx_arg, u8 *dst, const u8 *src) |
| @@ -884,6 +857,7 @@ static struct crypto_alg khazad_alg = { | |||
| 884 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, | 857 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, |
| 885 | .cra_blocksize = KHAZAD_BLOCK_SIZE, | 858 | .cra_blocksize = KHAZAD_BLOCK_SIZE, |
| 886 | .cra_ctxsize = sizeof (struct khazad_ctx), | 859 | .cra_ctxsize = sizeof (struct khazad_ctx), |
| 860 | .cra_alignmask = 7, | ||
| 887 | .cra_module = THIS_MODULE, | 861 | .cra_module = THIS_MODULE, |
| 888 | .cra_list = LIST_HEAD_INIT(khazad_alg.cra_list), | 862 | .cra_list = LIST_HEAD_INIT(khazad_alg.cra_list), |
| 889 | .cra_u = { .cipher = { | 863 | .cra_u = { .cipher = { |
