27 #include <linux/module.h>
29 #include <linux/types.h>
53 serpent_dec_blk_xway(ctx, (
u8 *)dst, (
u8 *)src);
55 for (j = 0; j < SERPENT_PARALLEL_BLOCKS - 1; j++)
56 u128_xor(dst + (j + 1), dst + (j + 1), ivs + j);
59 static void serpent_crypt_ctr(
void *ctx,
u128 *dst,
const u128 *src,
u128 *
iv)
63 u128_to_be128(&ctrblk, iv);
67 u128_xor(dst, src, (
u128 *)&ctrblk);
70 static void serpent_crypt_ctr_xway(
void *ctx,
u128 *dst,
const u128 *src,
80 u128_to_be128(&ctrblks[i], iv);
84 serpent_enc_blk_xway_xor(ctx, (
u8 *)dst, (
u8 *)ctrblks);
171 static inline bool serpent_fpu_begin(
bool fpu_enabled,
unsigned int nbytes)
174 NULL, fpu_enabled, nbytes);
177 static inline void serpent_fpu_end(
bool fpu_enabled)
179 glue_fpu_end(fpu_enabled);
187 static void encrypt_callback(
void *
priv,
u8 *srcdst,
unsigned int nbytes)
195 if (nbytes == bsize * SERPENT_PARALLEL_BLOCKS) {
196 serpent_enc_blk_xway(ctx->
ctx, srcdst, srcdst);
200 for (i = 0; i < nbytes / bsize; i++, srcdst += bsize)
204 static void decrypt_callback(
void *priv,
u8 *srcdst,
unsigned int nbytes)
212 if (nbytes == bsize * SERPENT_PARALLEL_BLOCKS) {
213 serpent_dec_blk_xway(ctx->
ctx, srcdst, srcdst);
217 for (i = 0; i < nbytes / bsize; i++, srcdst += bsize)
248 .fpu_enabled =
false,
252 .tbuflen =
sizeof(
buf),
255 .crypt_ctx = &crypt_ctx,
256 .crypt_fn = encrypt_callback,
261 ret =
lrw_crypt(desc, dst, src, nbytes, &req);
274 .fpu_enabled =
false,
278 .tbuflen =
sizeof(
buf),
281 .crypt_ctx = &crypt_ctx,
282 .crypt_fn = decrypt_callback,
287 ret =
lrw_crypt(desc, dst, src, nbytes, &req);
293 static void lrw_exit_tfm(
struct crypto_tfm *tfm)
305 static int xts_serpent_setkey(
struct crypto_tfm *tfm,
const u8 *key,
336 .fpu_enabled =
false,
340 .tbuflen =
sizeof(
buf),
345 .crypt_fn = encrypt_callback,
350 ret =
xts_crypt(desc, dst, src, nbytes, &req);
363 .fpu_enabled =
false,
367 .tbuflen =
sizeof(
buf),
372 .crypt_fn = decrypt_callback,
377 ret =
xts_crypt(desc, dst, src, nbytes, &req);
383 static struct crypto_alg serpent_algs[10] = { {
384 .cra_name =
"__ecb-serpent-avx",
385 .cra_driver_name =
"__driver-ecb-serpent-avx",
398 .encrypt = ecb_encrypt,
399 .decrypt = ecb_decrypt,
403 .cra_name =
"__cbc-serpent-avx",
404 .cra_driver_name =
"__driver-cbc-serpent-avx",
417 .encrypt = cbc_encrypt,
418 .decrypt = cbc_decrypt,
422 .cra_name =
"__ctr-serpent-avx",
423 .cra_driver_name =
"__driver-ctr-serpent-avx",
437 .encrypt = ctr_crypt,
438 .decrypt = ctr_crypt,
442 .cra_name =
"__lrw-serpent-avx",
443 .cra_driver_name =
"__driver-lrw-serpent-avx",
451 .cra_exit = lrw_exit_tfm,
459 .setkey = lrw_serpent_setkey,
460 .encrypt = lrw_encrypt,
461 .decrypt = lrw_decrypt,
465 .cra_name =
"__xts-serpent-avx",
466 .cra_driver_name =
"__driver-xts-serpent-avx",
479 .setkey = xts_serpent_setkey,
480 .encrypt = xts_encrypt,
481 .decrypt = xts_decrypt,
485 .cra_name =
"ecb(serpent)",
486 .cra_driver_name =
"ecb-serpent-avx",
506 .cra_name =
"cbc(serpent)",
507 .cra_driver_name =
"cbc-serpent-avx",
528 .cra_name =
"ctr(serpent)",
529 .cra_driver_name =
"ctr-serpent-avx",
551 .cra_name =
"lrw(serpent)",
552 .cra_driver_name =
"lrw-serpent-avx",
575 .cra_name =
"xts(serpent)",
576 .cra_driver_name =
"xts-serpent-avx",
598 static int __init serpent_init(
void)
602 if (!cpu_has_avx || !cpu_has_osxsave) {
616 static void __exit serpent_exit(
void)