diff options
author | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2013-04-08 14:50:55 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2013-04-25 09:01:51 -0400 |
commit | a05248ed2d9a83ae7c3e6db7c4ef9331c3dedc81 (patch) | |
tree | 62fead9aac2e2471dbc5d6df7b630589220eea3c /arch/x86/include | |
parent | d2049d8566bf74723f0c353621174b37ff3d75ec (diff) |
crypto: x86 - add more optimized XTS-mode for serpent-avx
This patch adds AVX optimized XTS-mode helper functions/macros and converts
serpent-avx to use the new facilities. Benefits are slightly improved speed
and reduced stack usage as use of temporary IV-array is avoided.
tcrypt results, with Intel i5-2450M:
enc dec
16B 1.00x 1.00x
64B 1.00x 1.00x
256B 1.04x 1.06x
1024B 1.09x 1.09x
8192B 1.10x 1.09x
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.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 | 24 | ||||
-rw-r--r-- | arch/x86/include/asm/crypto/serpent-avx.h | 5 |
2 files changed, 29 insertions, 0 deletions
diff --git a/arch/x86/include/asm/crypto/glue_helper.h b/arch/x86/include/asm/crypto/glue_helper.h index e2d65b061d27..1eef55596e82 100644 --- a/arch/x86/include/asm/crypto/glue_helper.h +++ b/arch/x86/include/asm/crypto/glue_helper.h | |||
@@ -14,10 +14,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 | le128 *iv); | 16 | le128 *iv); |
17 | typedef void (*common_glue_xts_func_t)(void *ctx, u128 *dst, const u128 *src, | ||
18 | le128 *iv); | ||
17 | 19 | ||
18 | #define GLUE_FUNC_CAST(fn) ((common_glue_func_t)(fn)) | 20 | #define GLUE_FUNC_CAST(fn) ((common_glue_func_t)(fn)) |
19 | #define GLUE_CBC_FUNC_CAST(fn) ((common_glue_cbc_func_t)(fn)) | 21 | #define GLUE_CBC_FUNC_CAST(fn) ((common_glue_cbc_func_t)(fn)) |
20 | #define GLUE_CTR_FUNC_CAST(fn) ((common_glue_ctr_func_t)(fn)) | 22 | #define GLUE_CTR_FUNC_CAST(fn) ((common_glue_ctr_func_t)(fn)) |
23 | #define GLUE_XTS_FUNC_CAST(fn) ((common_glue_xts_func_t)(fn)) | ||
21 | 24 | ||
22 | struct common_glue_func_entry { | 25 | struct common_glue_func_entry { |
23 | unsigned int num_blocks; /* number of blocks that @fn will process */ | 26 | unsigned int num_blocks; /* number of blocks that @fn will process */ |
@@ -25,6 +28,7 @@ struct common_glue_func_entry { | |||
25 | common_glue_func_t ecb; | 28 | common_glue_func_t ecb; |
26 | common_glue_cbc_func_t cbc; | 29 | common_glue_cbc_func_t cbc; |
27 | common_glue_ctr_func_t ctr; | 30 | common_glue_ctr_func_t ctr; |
31 | common_glue_xts_func_t xts; | ||
28 | } fn_u; | 32 | } fn_u; |
29 | }; | 33 | }; |
30 | 34 | ||
@@ -96,6 +100,16 @@ static inline void le128_inc(le128 *i) | |||
96 | i->b = cpu_to_le64(b); | 100 | i->b = cpu_to_le64(b); |
97 | } | 101 | } |
98 | 102 | ||
103 | static inline void le128_gf128mul_x_ble(le128 *dst, const le128 *src) | ||
104 | { | ||
105 | u64 a = le64_to_cpu(src->a); | ||
106 | u64 b = le64_to_cpu(src->b); | ||
107 | u64 _tt = ((s64)a >> 63) & 0x87; | ||
108 | |||
109 | dst->a = cpu_to_le64((a << 1) ^ (b >> 63)); | ||
110 | dst->b = cpu_to_le64((b << 1) ^ _tt); | ||
111 | } | ||
112 | |||
99 | extern int glue_ecb_crypt_128bit(const struct common_glue_ctx *gctx, | 113 | extern int glue_ecb_crypt_128bit(const struct common_glue_ctx *gctx, |
100 | struct blkcipher_desc *desc, | 114 | struct blkcipher_desc *desc, |
101 | struct scatterlist *dst, | 115 | struct scatterlist *dst, |
@@ -118,4 +132,14 @@ extern int glue_ctr_crypt_128bit(const struct common_glue_ctx *gctx, | |||
118 | struct scatterlist *dst, | 132 | struct scatterlist *dst, |
119 | struct scatterlist *src, unsigned int nbytes); | 133 | struct scatterlist *src, unsigned int nbytes); |
120 | 134 | ||
135 | extern int glue_xts_crypt_128bit(const struct common_glue_ctx *gctx, | ||
136 | struct blkcipher_desc *desc, | ||
137 | struct scatterlist *dst, | ||
138 | struct scatterlist *src, unsigned int nbytes, | ||
139 | common_glue_func_t tweak_fn, void *tweak_ctx, | ||
140 | void *crypt_ctx); | ||
141 | |||
142 | extern void glue_xts_crypt_128bit_one(void *ctx, u128 *dst, const u128 *src, | ||
143 | le128 *iv, common_glue_func_t fn); | ||
144 | |||
121 | #endif /* _CRYPTO_GLUE_HELPER_H */ | 145 | #endif /* _CRYPTO_GLUE_HELPER_H */ |
diff --git a/arch/x86/include/asm/crypto/serpent-avx.h b/arch/x86/include/asm/crypto/serpent-avx.h index 0da1d3e2a55c..56e79cc57eaf 100644 --- a/arch/x86/include/asm/crypto/serpent-avx.h +++ b/arch/x86/include/asm/crypto/serpent-avx.h | |||
@@ -16,4 +16,9 @@ asmlinkage void serpent_cbc_dec_8way_avx(struct serpent_ctx *ctx, u8 *dst, | |||
16 | asmlinkage void serpent_ctr_8way_avx(struct serpent_ctx *ctx, u8 *dst, | 16 | asmlinkage void serpent_ctr_8way_avx(struct serpent_ctx *ctx, u8 *dst, |
17 | const u8 *src, le128 *iv); | 17 | const u8 *src, le128 *iv); |
18 | 18 | ||
19 | asmlinkage void serpent_xts_enc_8way_avx(struct serpent_ctx *ctx, u8 *dst, | ||
20 | const u8 *src, le128 *iv); | ||
21 | asmlinkage void serpent_xts_dec_8way_avx(struct serpent_ctx *ctx, u8 *dst, | ||
22 | const u8 *src, le128 *iv); | ||
23 | |||
19 | #endif | 24 | #endif |