aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2018-02-20 02:48:18 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2018-03-02 11:03:30 -0500
commit6fcb81b562cf5b75c543a9e29fea30d439af3560 (patch)
tree60b80994354dce5f7047df4b23416ee6ba1f839d
parent09c0f03bf8ce9304e0d17131c46690b2c95209f4 (diff)
crypto: x86/camellia-aesni-avx - remove LRW algorithm
The LRW template now wraps an ECB mode algorithm rather than the block cipher directly. Therefore it is now redundant for crypto modules to wrap their ECB code with generic LRW code themselves via lrw_crypt(). Remove the lrw-camellia-aesni algorithm which did this. Users who request lrw(camellia) and previously would have gotten lrw-camellia-aesni will now get lrw(ecb-camellia-aesni) instead, which is just as fast. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--arch/x86/crypto/camellia_aesni_avx_glue.c168
-rw-r--r--arch/x86/include/asm/crypto/camellia.h1
-rw-r--r--crypto/Kconfig1
3 files changed, 2 insertions, 168 deletions
diff --git a/arch/x86/crypto/camellia_aesni_avx_glue.c b/arch/x86/crypto/camellia_aesni_avx_glue.c
index d96429da88eb..038bc2ae5313 100644
--- a/arch/x86/crypto/camellia_aesni_avx_glue.c
+++ b/arch/x86/crypto/camellia_aesni_avx_glue.c
@@ -17,7 +17,6 @@
17#include <crypto/ablk_helper.h> 17#include <crypto/ablk_helper.h>
18#include <crypto/algapi.h> 18#include <crypto/algapi.h>
19#include <crypto/ctr.h> 19#include <crypto/ctr.h>
20#include <crypto/lrw.h>
21#include <crypto/xts.h> 20#include <crypto/xts.h>
22#include <asm/fpu/api.h> 21#include <asm/fpu/api.h>
23#include <asm/crypto/camellia.h> 22#include <asm/crypto/camellia.h>
@@ -186,18 +185,6 @@ static int ctr_crypt(struct blkcipher_desc *desc, struct scatterlist *dst,
186 return glue_ctr_crypt_128bit(&camellia_ctr, desc, dst, src, nbytes); 185 return glue_ctr_crypt_128bit(&camellia_ctr, desc, dst, src, nbytes);
187} 186}
188 187
189static inline bool camellia_fpu_begin(bool fpu_enabled, unsigned int nbytes)
190{
191 return glue_fpu_begin(CAMELLIA_BLOCK_SIZE,
192 CAMELLIA_AESNI_PARALLEL_BLOCKS, NULL, fpu_enabled,
193 nbytes);
194}
195
196static inline void camellia_fpu_end(bool fpu_enabled)
197{
198 glue_fpu_end(fpu_enabled);
199}
200
201static int camellia_setkey(struct crypto_tfm *tfm, const u8 *in_key, 188static int camellia_setkey(struct crypto_tfm *tfm, const u8 *in_key,
202 unsigned int key_len) 189 unsigned int key_len)
203{ 190{
@@ -205,111 +192,6 @@ static int camellia_setkey(struct crypto_tfm *tfm, const u8 *in_key,
205 &tfm->crt_flags); 192 &tfm->crt_flags);
206} 193}
207 194
208struct crypt_priv {
209 struct camellia_ctx *ctx;
210 bool fpu_enabled;
211};
212
213static void encrypt_callback(void *priv, u8 *srcdst, unsigned int nbytes)
214{
215 const unsigned int bsize = CAMELLIA_BLOCK_SIZE;
216 struct crypt_priv *ctx = priv;
217 int i;
218
219 ctx->fpu_enabled = camellia_fpu_begin(ctx->fpu_enabled, nbytes);
220
221 if (nbytes >= CAMELLIA_AESNI_PARALLEL_BLOCKS * bsize) {
222 camellia_ecb_enc_16way(ctx->ctx, srcdst, srcdst);
223 srcdst += bsize * CAMELLIA_AESNI_PARALLEL_BLOCKS;
224 nbytes -= bsize * CAMELLIA_AESNI_PARALLEL_BLOCKS;
225 }
226
227 while (nbytes >= CAMELLIA_PARALLEL_BLOCKS * bsize) {
228 camellia_enc_blk_2way(ctx->ctx, srcdst, srcdst);
229 srcdst += bsize * CAMELLIA_PARALLEL_BLOCKS;
230 nbytes -= bsize * CAMELLIA_PARALLEL_BLOCKS;
231 }
232
233 for (i = 0; i < nbytes / bsize; i++, srcdst += bsize)
234 camellia_enc_blk(ctx->ctx, srcdst, srcdst);
235}
236
237static void decrypt_callback(void *priv, u8 *srcdst, unsigned int nbytes)
238{
239 const unsigned int bsize = CAMELLIA_BLOCK_SIZE;
240 struct crypt_priv *ctx = priv;
241 int i;
242
243 ctx->fpu_enabled = camellia_fpu_begin(ctx->fpu_enabled, nbytes);
244
245 if (nbytes >= CAMELLIA_AESNI_PARALLEL_BLOCKS * bsize) {
246 camellia_ecb_dec_16way(ctx->ctx, srcdst, srcdst);
247 srcdst += bsize * CAMELLIA_AESNI_PARALLEL_BLOCKS;
248 nbytes -= bsize * CAMELLIA_AESNI_PARALLEL_BLOCKS;
249 }
250
251 while (nbytes >= CAMELLIA_PARALLEL_BLOCKS * bsize) {
252 camellia_dec_blk_2way(ctx->ctx, srcdst, srcdst);
253 srcdst += bsize * CAMELLIA_PARALLEL_BLOCKS;
254 nbytes -= bsize * CAMELLIA_PARALLEL_BLOCKS;
255 }
256
257 for (i = 0; i < nbytes / bsize; i++, srcdst += bsize)
258 camellia_dec_blk(ctx->ctx, srcdst, srcdst);
259}
260
261static int lrw_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
262 struct scatterlist *src, unsigned int nbytes)
263{
264 struct camellia_lrw_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
265 be128 buf[CAMELLIA_AESNI_PARALLEL_BLOCKS];
266 struct crypt_priv crypt_ctx = {
267 .ctx = &ctx->camellia_ctx,
268 .fpu_enabled = false,
269 };
270 struct lrw_crypt_req req = {
271 .tbuf = buf,
272 .tbuflen = sizeof(buf),
273
274 .table_ctx = &ctx->lrw_table,
275 .crypt_ctx = &crypt_ctx,
276 .crypt_fn = encrypt_callback,
277 };
278 int ret;
279
280 desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
281 ret = lrw_crypt(desc, dst, src, nbytes, &req);
282 camellia_fpu_end(crypt_ctx.fpu_enabled);
283
284 return ret;
285}
286
287static int lrw_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
288 struct scatterlist *src, unsigned int nbytes)
289{
290 struct camellia_lrw_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
291 be128 buf[CAMELLIA_AESNI_PARALLEL_BLOCKS];
292 struct crypt_priv crypt_ctx = {
293 .ctx = &ctx->camellia_ctx,
294 .fpu_enabled = false,
295 };
296 struct lrw_crypt_req req = {
297 .tbuf = buf,
298 .tbuflen = sizeof(buf),
299
300 .table_ctx = &ctx->lrw_table,
301 .crypt_ctx = &crypt_ctx,
302 .crypt_fn = decrypt_callback,
303 };
304 int ret;
305
306 desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
307 ret = lrw_crypt(desc, dst, src, nbytes, &req);
308 camellia_fpu_end(crypt_ctx.fpu_enabled);
309
310 return ret;
311}
312
313static int xts_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, 195static int xts_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
314 struct scatterlist *src, unsigned int nbytes) 196 struct scatterlist *src, unsigned int nbytes)
315{ 197{
@@ -330,7 +212,7 @@ static int xts_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
330 &ctx->tweak_ctx, &ctx->crypt_ctx); 212 &ctx->tweak_ctx, &ctx->crypt_ctx);
331} 213}
332 214
333static struct crypto_alg cmll_algs[10] = { { 215static struct crypto_alg cmll_algs[] = { {
334 .cra_name = "__ecb-camellia-aesni", 216 .cra_name = "__ecb-camellia-aesni",
335 .cra_driver_name = "__driver-ecb-camellia-aesni", 217 .cra_driver_name = "__driver-ecb-camellia-aesni",
336 .cra_priority = 0, 218 .cra_priority = 0,
@@ -392,30 +274,6 @@ static struct crypto_alg cmll_algs[10] = { {
392 }, 274 },
393 }, 275 },
394}, { 276}, {
395 .cra_name = "__lrw-camellia-aesni",
396 .cra_driver_name = "__driver-lrw-camellia-aesni",
397 .cra_priority = 0,
398 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER |
399 CRYPTO_ALG_INTERNAL,
400 .cra_blocksize = CAMELLIA_BLOCK_SIZE,
401 .cra_ctxsize = sizeof(struct camellia_lrw_ctx),
402 .cra_alignmask = 0,
403 .cra_type = &crypto_blkcipher_type,
404 .cra_module = THIS_MODULE,
405 .cra_exit = lrw_camellia_exit_tfm,
406 .cra_u = {
407 .blkcipher = {
408 .min_keysize = CAMELLIA_MIN_KEY_SIZE +
409 CAMELLIA_BLOCK_SIZE,
410 .max_keysize = CAMELLIA_MAX_KEY_SIZE +
411 CAMELLIA_BLOCK_SIZE,
412 .ivsize = CAMELLIA_BLOCK_SIZE,
413 .setkey = lrw_camellia_setkey,
414 .encrypt = lrw_encrypt,
415 .decrypt = lrw_decrypt,
416 },
417 },
418}, {
419 .cra_name = "__xts-camellia-aesni", 277 .cra_name = "__xts-camellia-aesni",
420 .cra_driver_name = "__driver-xts-camellia-aesni", 278 .cra_driver_name = "__driver-xts-camellia-aesni",
421 .cra_priority = 0, 279 .cra_priority = 0,
@@ -503,30 +361,6 @@ static struct crypto_alg cmll_algs[10] = { {
503 }, 361 },
504 }, 362 },
505}, { 363}, {
506 .cra_name = "lrw(camellia)",
507 .cra_driver_name = "lrw-camellia-aesni",
508 .cra_priority = 400,
509 .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
510 .cra_blocksize = CAMELLIA_BLOCK_SIZE,
511 .cra_ctxsize = sizeof(struct async_helper_ctx),
512 .cra_alignmask = 0,
513 .cra_type = &crypto_ablkcipher_type,
514 .cra_module = THIS_MODULE,
515 .cra_init = ablk_init,
516 .cra_exit = ablk_exit,
517 .cra_u = {
518 .ablkcipher = {
519 .min_keysize = CAMELLIA_MIN_KEY_SIZE +
520 CAMELLIA_BLOCK_SIZE,
521 .max_keysize = CAMELLIA_MAX_KEY_SIZE +
522 CAMELLIA_BLOCK_SIZE,
523 .ivsize = CAMELLIA_BLOCK_SIZE,
524 .setkey = ablk_set_key,
525 .encrypt = ablk_encrypt,
526 .decrypt = ablk_decrypt,
527 },
528 },
529}, {
530 .cra_name = "xts(camellia)", 364 .cra_name = "xts(camellia)",
531 .cra_driver_name = "xts-camellia-aesni", 365 .cra_driver_name = "xts-camellia-aesni",
532 .cra_priority = 400, 366 .cra_priority = 400,
diff --git a/arch/x86/include/asm/crypto/camellia.h b/arch/x86/include/asm/crypto/camellia.h
index 10f8d590bcfe..24eff92a5356 100644
--- a/arch/x86/include/asm/crypto/camellia.h
+++ b/arch/x86/include/asm/crypto/camellia.h
@@ -2,6 +2,7 @@
2#ifndef ASM_X86_CAMELLIA_H 2#ifndef ASM_X86_CAMELLIA_H
3#define ASM_X86_CAMELLIA_H 3#define ASM_X86_CAMELLIA_H
4 4
5#include <crypto/lrw.h>
5#include <linux/kernel.h> 6#include <linux/kernel.h>
6#include <linux/crypto.h> 7#include <linux/crypto.h>
7 8
diff --git a/crypto/Kconfig b/crypto/Kconfig
index 12b92328f5c5..b7c33bc0fb3b 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -1169,7 +1169,6 @@ config CRYPTO_CAMELLIA_AESNI_AVX_X86_64
1169 select CRYPTO_ABLK_HELPER 1169 select CRYPTO_ABLK_HELPER
1170 select CRYPTO_GLUE_HELPER_X86 1170 select CRYPTO_GLUE_HELPER_X86
1171 select CRYPTO_CAMELLIA_X86_64 1171 select CRYPTO_CAMELLIA_X86_64
1172 select CRYPTO_LRW
1173 select CRYPTO_XTS 1172 select CRYPTO_XTS
1174 help 1173 help
1175 Camellia cipher algorithm module (x86_64/AES-NI/AVX). 1174 Camellia cipher algorithm module (x86_64/AES-NI/AVX).