32 #include <linux/module.h>
34 #include <linux/types.h>
56 serpent_dec_blk_xway(ctx, (
u8 *)dst, (
u8 *)src);
58 for (j = 0; j < SERPENT_PARALLEL_BLOCKS - 1; j++)
59 u128_xor(dst + (j + 1), dst + (j + 1), ivs + j);
62 static void serpent_crypt_ctr(
void *ctx,
u128 *dst,
const u128 *src,
u128 *
iv)
66 u128_to_be128(&ctrblk, iv);
70 u128_xor(dst, src, (
u128 *)&ctrblk);
73 static void serpent_crypt_ctr_xway(
void *ctx,
u128 *dst,
const u128 *src,
83 u128_to_be128(&ctrblks[i], iv);
87 serpent_enc_blk_xway_xor(ctx, (
u8 *)dst, (
u8 *)ctrblks);
174 static inline bool serpent_fpu_begin(
bool fpu_enabled,
unsigned int nbytes)
177 NULL, fpu_enabled, nbytes);
180 static inline void serpent_fpu_end(
bool fpu_enabled)
182 glue_fpu_end(fpu_enabled);
190 static void encrypt_callback(
void *
priv,
u8 *srcdst,
unsigned int nbytes)
198 if (nbytes == bsize * SERPENT_PARALLEL_BLOCKS) {
199 serpent_enc_blk_xway(ctx->
ctx, srcdst, srcdst);
203 for (i = 0; i < nbytes / bsize; i++, srcdst += bsize)
207 static void decrypt_callback(
void *priv,
u8 *srcdst,
unsigned int nbytes)
215 if (nbytes == bsize * SERPENT_PARALLEL_BLOCKS) {
216 serpent_dec_blk_xway(ctx->
ctx, srcdst, srcdst);
220 for (i = 0; i < nbytes / bsize; i++, srcdst += bsize)
251 .fpu_enabled =
false,
255 .tbuflen =
sizeof(
buf),
258 .crypt_ctx = &crypt_ctx,
259 .crypt_fn = encrypt_callback,
264 ret =
lrw_crypt(desc, dst, src, nbytes, &req);
277 .fpu_enabled =
false,
281 .tbuflen =
sizeof(
buf),
284 .crypt_ctx = &crypt_ctx,
285 .crypt_fn = decrypt_callback,
290 ret =
lrw_crypt(desc, dst, src, nbytes, &req);
296 static void lrw_exit_tfm(
struct crypto_tfm *tfm)
308 static int xts_serpent_setkey(
struct crypto_tfm *tfm,
const u8 *key,
339 .fpu_enabled =
false,
343 .tbuflen =
sizeof(
buf),
348 .crypt_fn = encrypt_callback,
353 ret =
xts_crypt(desc, dst, src, nbytes, &req);
366 .fpu_enabled =
false,
370 .tbuflen =
sizeof(
buf),
375 .crypt_fn = decrypt_callback,
380 ret =
xts_crypt(desc, dst, src, nbytes, &req);
386 static struct crypto_alg serpent_algs[10] = { {
387 .cra_name =
"__ecb-serpent-sse2",
388 .cra_driver_name =
"__driver-ecb-serpent-sse2",
401 .encrypt = ecb_encrypt,
402 .decrypt = ecb_decrypt,
406 .cra_name =
"__cbc-serpent-sse2",
407 .cra_driver_name =
"__driver-cbc-serpent-sse2",
420 .encrypt = cbc_encrypt,
421 .decrypt = cbc_decrypt,
425 .cra_name =
"__ctr-serpent-sse2",
426 .cra_driver_name =
"__driver-ctr-serpent-sse2",
440 .encrypt = ctr_crypt,
441 .decrypt = ctr_crypt,
445 .cra_name =
"__lrw-serpent-sse2",
446 .cra_driver_name =
"__driver-lrw-serpent-sse2",
454 .cra_exit = lrw_exit_tfm,
462 .setkey = lrw_serpent_setkey,
463 .encrypt = lrw_encrypt,
464 .decrypt = lrw_decrypt,
468 .cra_name =
"__xts-serpent-sse2",
469 .cra_driver_name =
"__driver-xts-serpent-sse2",
482 .setkey = xts_serpent_setkey,
483 .encrypt = xts_encrypt,
484 .decrypt = xts_decrypt,
488 .cra_name =
"ecb(serpent)",
489 .cra_driver_name =
"ecb-serpent-sse2",
509 .cra_name =
"cbc(serpent)",
510 .cra_driver_name =
"cbc-serpent-sse2",
531 .cra_name =
"ctr(serpent)",
532 .cra_driver_name =
"ctr-serpent-sse2",
554 .cra_name =
"lrw(serpent)",
555 .cra_driver_name =
"lrw-serpent-sse2",
578 .cra_name =
"xts(serpent)",
579 .cra_driver_name =
"xts-serpent-sse2",
601 static int __init serpent_sse2_init(
void)
611 static void __exit serpent_sse2_exit(
void)