diff options
author | Jussi Kivilinna <jussi.kivilinna@mbnet.fi> | 2012-10-20 08:06:36 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2012-10-24 09:10:54 -0400 |
commit | 58990986f1cba40c23c0c10592ace08616de3ffa (patch) | |
tree | 84466698a28860d1457c804b857b2e97d1995fcb /arch/x86/include | |
parent | e080b17a8cec92ef42343989ae65c73c25529346 (diff) |
crypto: x86/glue_helper - use le128 instead of u128 for CTR mode
'u128' currently used for CTR mode is on little-endian 'long long' swapped
and would require extra swap operations by SSE/AVX code. Use of le128
instead of u128 allows IV calculations to be done with vector registers
easier.
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'arch/x86/include')
-rw-r--r-- | arch/x86/include/asm/crypto/glue_helper.h | 28 | ||||
-rw-r--r-- | arch/x86/include/asm/crypto/twofish.h | 4 |
2 files changed, 19 insertions, 13 deletions
diff --git a/arch/x86/include/asm/crypto/glue_helper.h b/arch/x86/include/asm/crypto/glue_helper.h index 3e408bddc96f..e2d65b061d27 100644 --- a/arch/x86/include/asm/crypto/glue_helper.h +++ b/arch/x86/include/asm/crypto/glue_helper.h | |||
@@ -13,7 +13,7 @@ | |||
13 | typedef void (*common_glue_func_t)(void *ctx, u8 *dst, const u8 *src); | 13 | typedef void (*common_glue_func_t)(void *ctx, u8 *dst, const u8 *src); |
14 | typedef void (*common_glue_cbc_func_t)(void *ctx, u128 *dst, const u128 *src); | 14 | typedef void (*common_glue_cbc_func_t)(void *ctx, u128 *dst, const u128 *src); |
15 | typedef void (*common_glue_ctr_func_t)(void *ctx, u128 *dst, const u128 *src, | 15 | typedef void (*common_glue_ctr_func_t)(void *ctx, u128 *dst, const u128 *src, |
16 | u128 *iv); | 16 | le128 *iv); |
17 | 17 | ||
18 | #define GLUE_FUNC_CAST(fn) ((common_glue_func_t)(fn)) | 18 | #define GLUE_FUNC_CAST(fn) ((common_glue_func_t)(fn)) |
19 | #define GLUE_CBC_FUNC_CAST(fn) ((common_glue_cbc_func_t)(fn)) | 19 | #define GLUE_CBC_FUNC_CAST(fn) ((common_glue_cbc_func_t)(fn)) |
@@ -71,23 +71,29 @@ static inline void glue_fpu_end(bool fpu_enabled) | |||
71 | kernel_fpu_end(); | 71 | kernel_fpu_end(); |
72 | } | 72 | } |
73 | 73 | ||
74 | static inline void u128_to_be128(be128 *dst, const u128 *src) | 74 | static inline void le128_to_be128(be128 *dst, const le128 *src) |
75 | { | 75 | { |
76 | dst->a = cpu_to_be64(src->a); | 76 | dst->a = cpu_to_be64(le64_to_cpu(src->a)); |
77 | dst->b = cpu_to_be64(src->b); | 77 | dst->b = cpu_to_be64(le64_to_cpu(src->b)); |
78 | } | 78 | } |
79 | 79 | ||
80 | static inline void be128_to_u128(u128 *dst, const be128 *src) | 80 | static inline void be128_to_le128(le128 *dst, const be128 *src) |
81 | { | 81 | { |
82 | dst->a = be64_to_cpu(src->a); | 82 | dst->a = cpu_to_le64(be64_to_cpu(src->a)); |
83 | dst->b = be64_to_cpu(src->b); | 83 | dst->b = cpu_to_le64(be64_to_cpu(src->b)); |
84 | } | 84 | } |
85 | 85 | ||
86 | static inline void u128_inc(u128 *i) | 86 | static inline void le128_inc(le128 *i) |
87 | { | 87 | { |
88 | i->b++; | 88 | u64 a = le64_to_cpu(i->a); |
89 | if (!i->b) | 89 | u64 b = le64_to_cpu(i->b); |
90 | i->a++; | 90 | |
91 | b++; | ||
92 | if (!b) | ||
93 | a++; | ||
94 | |||
95 | i->a = cpu_to_le64(a); | ||
96 | i->b = cpu_to_le64(b); | ||
91 | } | 97 | } |
92 | 98 | ||
93 | extern int glue_ecb_crypt_128bit(const struct common_glue_ctx *gctx, | 99 | extern int glue_ecb_crypt_128bit(const struct common_glue_ctx *gctx, |
diff --git a/arch/x86/include/asm/crypto/twofish.h b/arch/x86/include/asm/crypto/twofish.h index 9d2c514bd5f9..878c51ceebb5 100644 --- a/arch/x86/include/asm/crypto/twofish.h +++ b/arch/x86/include/asm/crypto/twofish.h | |||
@@ -31,9 +31,9 @@ asmlinkage void twofish_dec_blk_3way(struct twofish_ctx *ctx, u8 *dst, | |||
31 | /* helpers from twofish_x86_64-3way module */ | 31 | /* helpers from twofish_x86_64-3way module */ |
32 | extern void twofish_dec_blk_cbc_3way(void *ctx, u128 *dst, const u128 *src); | 32 | extern void twofish_dec_blk_cbc_3way(void *ctx, u128 *dst, const u128 *src); |
33 | extern void twofish_enc_blk_ctr(void *ctx, u128 *dst, const u128 *src, | 33 | extern void twofish_enc_blk_ctr(void *ctx, u128 *dst, const u128 *src, |
34 | u128 *iv); | 34 | le128 *iv); |
35 | extern void twofish_enc_blk_ctr_3way(void *ctx, u128 *dst, const u128 *src, | 35 | extern void twofish_enc_blk_ctr_3way(void *ctx, u128 *dst, const u128 *src, |
36 | u128 *iv); | 36 | le128 *iv); |
37 | 37 | ||
38 | extern int lrw_twofish_setkey(struct crypto_tfm *tfm, const u8 *key, | 38 | extern int lrw_twofish_setkey(struct crypto_tfm *tfm, const u8 *key, |
39 | unsigned int keylen); | 39 | unsigned int keylen); |