aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJussi Kivilinna <jussi.kivilinna@mbnet.fi>2012-10-20 08:06:36 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2012-10-24 09:10:54 -0400
commit58990986f1cba40c23c0c10592ace08616de3ffa (patch)
tree84466698a28860d1457c804b857b2e97d1995fcb
parente080b17a8cec92ef42343989ae65c73c25529346 (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>
-rw-r--r--arch/x86/crypto/camellia_glue.c16
-rw-r--r--arch/x86/crypto/cast6_avx_glue.c12
-rw-r--r--arch/x86/crypto/glue_helper.c12
-rw-r--r--arch/x86/crypto/serpent_avx_glue.c12
-rw-r--r--arch/x86/crypto/serpent_sse2_glue.c12
-rw-r--r--arch/x86/crypto/twofish_avx_glue.c6
-rw-r--r--arch/x86/crypto/twofish_glue_3way.c20
-rw-r--r--arch/x86/include/asm/crypto/glue_helper.h28
-rw-r--r--arch/x86/include/asm/crypto/twofish.h4
9 files changed, 64 insertions, 58 deletions
diff --git a/arch/x86/crypto/camellia_glue.c b/arch/x86/crypto/camellia_glue.c
index 42ffd2bbab5b..021a0086186b 100644
--- a/arch/x86/crypto/camellia_glue.c
+++ b/arch/x86/crypto/camellia_glue.c
@@ -1317,21 +1317,21 @@ static void camellia_decrypt_cbc_2way(void *ctx, u128 *dst, const u128 *src)
1317 u128_xor(&dst[1], &dst[1], &iv); 1317 u128_xor(&dst[1], &dst[1], &iv);
1318} 1318}
1319 1319
1320static void camellia_crypt_ctr(void *ctx, u128 *dst, const u128 *src, u128 *iv) 1320static void camellia_crypt_ctr(void *ctx, u128 *dst, const u128 *src, le128 *iv)
1321{ 1321{
1322 be128 ctrblk; 1322 be128 ctrblk;
1323 1323
1324 if (dst != src) 1324 if (dst != src)
1325 *dst = *src; 1325 *dst = *src;
1326 1326
1327 u128_to_be128(&ctrblk, iv); 1327 le128_to_be128(&ctrblk, iv);
1328 u128_inc(iv); 1328 le128_inc(iv);
1329 1329
1330 camellia_enc_blk_xor(ctx, (u8 *)dst, (u8 *)&ctrblk); 1330 camellia_enc_blk_xor(ctx, (u8 *)dst, (u8 *)&ctrblk);
1331} 1331}
1332 1332
1333static void camellia_crypt_ctr_2way(void *ctx, u128 *dst, const u128 *src, 1333static void camellia_crypt_ctr_2way(void *ctx, u128 *dst, const u128 *src,
1334 u128 *iv) 1334 le128 *iv)
1335{ 1335{
1336 be128 ctrblks[2]; 1336 be128 ctrblks[2];
1337 1337
@@ -1340,10 +1340,10 @@ static void camellia_crypt_ctr_2way(void *ctx, u128 *dst, const u128 *src,
1340 dst[1] = src[1]; 1340 dst[1] = src[1];
1341 } 1341 }
1342 1342
1343 u128_to_be128(&ctrblks[0], iv); 1343 le128_to_be128(&ctrblks[0], iv);
1344 u128_inc(iv); 1344 le128_inc(iv);
1345 u128_to_be128(&ctrblks[1], iv); 1345 le128_to_be128(&ctrblks[1], iv);
1346 u128_inc(iv); 1346 le128_inc(iv);
1347 1347
1348 camellia_enc_blk_xor_2way(ctx, (u8 *)dst, (u8 *)ctrblks); 1348 camellia_enc_blk_xor_2way(ctx, (u8 *)dst, (u8 *)ctrblks);
1349} 1349}
diff --git a/arch/x86/crypto/cast6_avx_glue.c b/arch/x86/crypto/cast6_avx_glue.c
index 15e5f85a5011..1dfd33b5b4fb 100644
--- a/arch/x86/crypto/cast6_avx_glue.c
+++ b/arch/x86/crypto/cast6_avx_glue.c
@@ -78,19 +78,19 @@ static void cast6_decrypt_cbc_xway(void *ctx, u128 *dst, const u128 *src)
78 u128_xor(dst + (j + 1), dst + (j + 1), ivs + j); 78 u128_xor(dst + (j + 1), dst + (j + 1), ivs + j);
79} 79}
80 80
81static void cast6_crypt_ctr(void *ctx, u128 *dst, const u128 *src, u128 *iv) 81static void cast6_crypt_ctr(void *ctx, u128 *dst, const u128 *src, le128 *iv)
82{ 82{
83 be128 ctrblk; 83 be128 ctrblk;
84 84
85 u128_to_be128(&ctrblk, iv); 85 le128_to_be128(&ctrblk, iv);
86 u128_inc(iv); 86 le128_inc(iv);
87 87
88 __cast6_encrypt(ctx, (u8 *)&ctrblk, (u8 *)&ctrblk); 88 __cast6_encrypt(ctx, (u8 *)&ctrblk, (u8 *)&ctrblk);
89 u128_xor(dst, src, (u128 *)&ctrblk); 89 u128_xor(dst, src, (u128 *)&ctrblk);
90} 90}
91 91
92static void cast6_crypt_ctr_xway(void *ctx, u128 *dst, const u128 *src, 92static void cast6_crypt_ctr_xway(void *ctx, u128 *dst, const u128 *src,
93 u128 *iv) 93 le128 *iv)
94{ 94{
95 be128 ctrblks[CAST6_PARALLEL_BLOCKS]; 95 be128 ctrblks[CAST6_PARALLEL_BLOCKS];
96 unsigned int i; 96 unsigned int i;
@@ -99,8 +99,8 @@ static void cast6_crypt_ctr_xway(void *ctx, u128 *dst, const u128 *src,
99 if (dst != src) 99 if (dst != src)
100 dst[i] = src[i]; 100 dst[i] = src[i];
101 101
102 u128_to_be128(&ctrblks[i], iv); 102 le128_to_be128(&ctrblks[i], iv);
103 u128_inc(iv); 103 le128_inc(iv);
104 } 104 }
105 105
106 cast6_enc_blk_xway_xor(ctx, (u8 *)dst, (u8 *)ctrblks); 106 cast6_enc_blk_xway_xor(ctx, (u8 *)dst, (u8 *)ctrblks);
diff --git a/arch/x86/crypto/glue_helper.c b/arch/x86/crypto/glue_helper.c
index 30b3927bd733..22ce4f683e55 100644
--- a/arch/x86/crypto/glue_helper.c
+++ b/arch/x86/crypto/glue_helper.c
@@ -221,16 +221,16 @@ static void glue_ctr_crypt_final_128bit(const common_glue_ctr_func_t fn_ctr,
221 u8 *src = (u8 *)walk->src.virt.addr; 221 u8 *src = (u8 *)walk->src.virt.addr;
222 u8 *dst = (u8 *)walk->dst.virt.addr; 222 u8 *dst = (u8 *)walk->dst.virt.addr;
223 unsigned int nbytes = walk->nbytes; 223 unsigned int nbytes = walk->nbytes;
224 u128 ctrblk; 224 le128 ctrblk;
225 u128 tmp; 225 u128 tmp;
226 226
227 be128_to_u128(&ctrblk, (be128 *)walk->iv); 227 be128_to_le128(&ctrblk, (be128 *)walk->iv);
228 228
229 memcpy(&tmp, src, nbytes); 229 memcpy(&tmp, src, nbytes);
230 fn_ctr(ctx, &tmp, &tmp, &ctrblk); 230 fn_ctr(ctx, &tmp, &tmp, &ctrblk);
231 memcpy(dst, &tmp, nbytes); 231 memcpy(dst, &tmp, nbytes);
232 232
233 u128_to_be128((be128 *)walk->iv, &ctrblk); 233 le128_to_be128((be128 *)walk->iv, &ctrblk);
234} 234}
235EXPORT_SYMBOL_GPL(glue_ctr_crypt_final_128bit); 235EXPORT_SYMBOL_GPL(glue_ctr_crypt_final_128bit);
236 236
@@ -243,11 +243,11 @@ static unsigned int __glue_ctr_crypt_128bit(const struct common_glue_ctx *gctx,
243 unsigned int nbytes = walk->nbytes; 243 unsigned int nbytes = walk->nbytes;
244 u128 *src = (u128 *)walk->src.virt.addr; 244 u128 *src = (u128 *)walk->src.virt.addr;
245 u128 *dst = (u128 *)walk->dst.virt.addr; 245 u128 *dst = (u128 *)walk->dst.virt.addr;
246 u128 ctrblk; 246 le128 ctrblk;
247 unsigned int num_blocks, func_bytes; 247 unsigned int num_blocks, func_bytes;
248 unsigned int i; 248 unsigned int i;
249 249
250 be128_to_u128(&ctrblk, (be128 *)walk->iv); 250 be128_to_le128(&ctrblk, (be128 *)walk->iv);
251 251
252 /* Process multi-block batch */ 252 /* Process multi-block batch */
253 for (i = 0; i < gctx->num_funcs; i++) { 253 for (i = 0; i < gctx->num_funcs; i++) {
@@ -269,7 +269,7 @@ static unsigned int __glue_ctr_crypt_128bit(const struct common_glue_ctx *gctx,
269 } 269 }
270 270
271done: 271done:
272 u128_to_be128((be128 *)walk->iv, &ctrblk); 272 le128_to_be128((be128 *)walk->iv, &ctrblk);
273 return nbytes; 273 return nbytes;
274} 274}
275 275
diff --git a/arch/x86/crypto/serpent_avx_glue.c b/arch/x86/crypto/serpent_avx_glue.c
index 3f543a04cf1e..2aa31ade1e68 100644
--- a/arch/x86/crypto/serpent_avx_glue.c
+++ b/arch/x86/crypto/serpent_avx_glue.c
@@ -56,19 +56,19 @@ static void serpent_decrypt_cbc_xway(void *ctx, u128 *dst, const u128 *src)
56 u128_xor(dst + (j + 1), dst + (j + 1), ivs + j); 56 u128_xor(dst + (j + 1), dst + (j + 1), ivs + j);
57} 57}
58 58
59static void serpent_crypt_ctr(void *ctx, u128 *dst, const u128 *src, u128 *iv) 59static void serpent_crypt_ctr(void *ctx, u128 *dst, const u128 *src, le128 *iv)
60{ 60{
61 be128 ctrblk; 61 be128 ctrblk;
62 62
63 u128_to_be128(&ctrblk, iv); 63 le128_to_be128(&ctrblk, iv);
64 u128_inc(iv); 64 le128_inc(iv);
65 65
66 __serpent_encrypt(ctx, (u8 *)&ctrblk, (u8 *)&ctrblk); 66 __serpent_encrypt(ctx, (u8 *)&ctrblk, (u8 *)&ctrblk);
67 u128_xor(dst, src, (u128 *)&ctrblk); 67 u128_xor(dst, src, (u128 *)&ctrblk);
68} 68}
69 69
70static void serpent_crypt_ctr_xway(void *ctx, u128 *dst, const u128 *src,