24 #include <linux/module.h>
26 #include <linux/types.h>
41 #define CAST6_PARALLEL_BLOCKS 8
75 cast6_dec_blk_xway(ctx, (
u8 *)dst, (
u8 *)src);
77 for (j = 0; j < CAST6_PARALLEL_BLOCKS - 1; j++)
78 u128_xor(dst + (j + 1), dst + (j + 1), ivs + j);
81 static void cast6_crypt_ctr(
void *ctx,
u128 *dst,
const u128 *src,
u128 *
iv)
85 u128_to_be128(&ctrblk, iv);
89 u128_xor(dst, src, (
u128 *)&ctrblk);
92 static void cast6_crypt_ctr_xway(
void *ctx,
u128 *dst,
const u128 *src,
102 u128_to_be128(&ctrblks[i], iv);
106 cast6_enc_blk_xway_xor(ctx, (
u8 *)dst, (
u8 *)ctrblks);
193 static inline bool cast6_fpu_begin(
bool fpu_enabled,
unsigned int nbytes)
196 NULL, fpu_enabled, nbytes);
199 static inline void cast6_fpu_end(
bool fpu_enabled)
201 glue_fpu_end(fpu_enabled);
209 static void encrypt_callback(
void *
priv,
u8 *srcdst,
unsigned int nbytes)
217 if (nbytes == bsize * CAST6_PARALLEL_BLOCKS) {
218 cast6_enc_blk_xway(ctx->
ctx, srcdst, srcdst);
222 for (i = 0; i < nbytes / bsize; i++, srcdst += bsize)
226 static void decrypt_callback(
void *priv,
u8 *srcdst,
unsigned int nbytes)
234 if (nbytes == bsize * CAST6_PARALLEL_BLOCKS) {
235 cast6_dec_blk_xway(ctx->
ctx, srcdst, srcdst);
239 for (i = 0; i < nbytes / bsize; i++, srcdst += bsize)
269 .fpu_enabled =
false,
273 .tbuflen =
sizeof(
buf),
276 .crypt_ctx = &crypt_ctx,
277 .crypt_fn = encrypt_callback,
282 ret =
lrw_crypt(desc, dst, src, nbytes, &req);
295 .fpu_enabled =
false,
299 .tbuflen =
sizeof(
buf),
302 .crypt_ctx = &crypt_ctx,
303 .crypt_fn = decrypt_callback,
308 ret =
lrw_crypt(desc, dst, src, nbytes, &req);
314 static void lrw_exit_tfm(
struct crypto_tfm *tfm)
326 static int xts_cast6_setkey(
struct crypto_tfm *tfm,
const u8 *key,
358 .fpu_enabled =
false,
362 .tbuflen =
sizeof(
buf),
367 .crypt_fn = encrypt_callback,
372 ret =
xts_crypt(desc, dst, src, nbytes, &req);
385 .fpu_enabled =
false,
389 .tbuflen =
sizeof(
buf),
394 .crypt_fn = decrypt_callback,
399 ret =
xts_crypt(desc, dst, src, nbytes, &req);
406 .cra_name =
"__ecb-cast6-avx",
407 .cra_driver_name =
"__driver-ecb-cast6-avx",
420 .encrypt = ecb_encrypt,
421 .decrypt = ecb_decrypt,
425 .cra_name =
"__cbc-cast6-avx",
426 .cra_driver_name =
"__driver-cbc-cast6-avx",
439 .encrypt = cbc_encrypt,
440 .decrypt = cbc_decrypt,
444 .cra_name =
"__ctr-cast6-avx",
445 .cra_driver_name =
"__driver-ctr-cast6-avx",
459 .encrypt = ctr_crypt,
460 .decrypt = ctr_crypt,
464 .cra_name =
"__lrw-cast6-avx",
465 .cra_driver_name =
"__driver-lrw-cast6-avx",
473 .cra_exit = lrw_exit_tfm,
481 .setkey = lrw_cast6_setkey,
482 .encrypt = lrw_encrypt,
483 .decrypt = lrw_decrypt,
487 .cra_name =
"__xts-cast6-avx",
488 .cra_driver_name =
"__driver-xts-cast6-avx",
501 .setkey = xts_cast6_setkey,
502 .encrypt = xts_encrypt,
503 .decrypt = xts_decrypt,
507 .cra_name =
"ecb(cast6)",
508 .cra_driver_name =
"ecb-cast6-avx",
528 .cra_name =
"cbc(cast6)",
529 .cra_driver_name =
"cbc-cast6-avx",
550 .cra_name =
"ctr(cast6)",
551 .cra_driver_name =
"ctr-cast6-avx",
573 .cra_name =
"lrw(cast6)",
574 .cra_driver_name =
"lrw-cast6-avx",
597 .cra_name =
"xts(cast6)",
598 .cra_driver_name =
"xts-cast6-avx",
620 static int __init cast6_init(
void)
624 if (!cpu_has_avx || !cpu_has_osxsave) {
625 pr_info(
"AVX instructions are not detected.\n");
631 pr_info(
"AVX detected but unusable.\n");
638 static void __exit cast6_exit(
void)