28 #include <asm/processor.h>
32 #include <linux/module.h>
33 #include <linux/types.h>
52 static inline void blowfish_enc_blk_xor(
struct bf_ctx *
ctx,
u8 *
dst,
58 static inline void blowfish_enc_blk_4way(
struct bf_ctx *
ctx,
u8 *
dst,
64 static inline void blowfish_enc_blk_xor_4way(
struct bf_ctx *
ctx,
u8 *
dst,
72 blowfish_enc_blk(crypto_tfm_ctx(tfm), dst, src);
75 static void blowfish_decrypt(
struct crypto_tfm *tfm,
u8 *dst,
const u8 *src)
82 void (*fn_4way)(
struct bf_ctx *,
u8 *,
const u8 *))
91 while ((nbytes = walk->
nbytes)) {
96 if (nbytes >= bsize * 4) {
98 fn_4way(ctx, wdst, wsrc);
103 }
while (nbytes >= bsize * 4);
116 }
while (nbytes >= bsize);
130 blkcipher_walk_init(&walk, dst, src, nbytes);
131 return ecb_crypt(desc, &walk, blowfish_enc_blk, blowfish_enc_blk_4way);
139 blkcipher_walk_init(&walk, dst, src, nbytes);
146 struct bf_ctx *ctx = crypto_blkcipher_ctx(desc->
tfm);
148 unsigned int nbytes = walk->
nbytes;
155 blowfish_enc_blk(ctx, (
u8 *)
dst, (
u8 *)dst);
161 }
while (nbytes >= bsize);
163 *(
u64 *)walk->
iv = *iv;
173 blkcipher_walk_init(&walk, dst, src, nbytes);
176 while ((nbytes = walk.
nbytes)) {
177 nbytes = __cbc_encrypt(desc, &walk);
187 struct bf_ctx *ctx = crypto_blkcipher_ctx(desc->
tfm);
189 unsigned int nbytes = walk->
nbytes;
196 src += nbytes / bsize - 1;
197 dst += nbytes / bsize - 1;
202 if (nbytes >= bsize * 4) {
204 nbytes -= bsize * 4 - bsize;
225 }
while (nbytes >= bsize * 4);
245 *dst ^= *(
u64 *)walk->
iv;
246 *(
u64 *)walk->
iv = last_iv;
257 blkcipher_walk_init(&walk, dst, src, nbytes);
260 while ((nbytes = walk.
nbytes)) {
261 nbytes = __cbc_decrypt(desc, &walk);
270 u8 *ctrblk = walk->
iv;
274 unsigned int nbytes = walk->
nbytes;
276 blowfish_enc_blk(ctx, keystream, ctrblk);
278 memcpy(dst, keystream, nbytes);
286 struct bf_ctx *ctx = crypto_blkcipher_ctx(desc->
tfm);
288 unsigned int nbytes = walk->
nbytes;
295 if (nbytes >= bsize * 4) {
310 blowfish_enc_blk_xor_4way(ctx, (
u8 *)dst,
315 }
while ((nbytes -= bsize * 4) >= bsize * 4);
328 blowfish_enc_blk_xor(ctx, (
u8 *)dst, (
u8 *)ctrblocks);
332 }
while ((nbytes -= bsize) >= bsize);
345 blkcipher_walk_init(&walk, dst, src, nbytes);
349 nbytes = __ctr_crypt(desc, &walk);
354 ctr_crypt_final(crypto_blkcipher_ctx(desc->
tfm), &walk);
362 .cra_name =
"blowfish",
363 .cra_driver_name =
"blowfish-asm",
367 .cra_ctxsize =
sizeof(
struct bf_ctx),
375 .cia_encrypt = blowfish_encrypt,
376 .cia_decrypt = blowfish_decrypt,
380 .cra_name =
"ecb(blowfish)",
381 .cra_driver_name =
"ecb-blowfish-asm",
385 .cra_ctxsize =
sizeof(
struct bf_ctx),
394 .encrypt = ecb_encrypt,
395 .decrypt = ecb_decrypt,
399 .cra_name =
"cbc(blowfish)",
400 .cra_driver_name =
"cbc-blowfish-asm",
404 .cra_ctxsize =
sizeof(
struct bf_ctx),
414 .encrypt = cbc_encrypt,
415 .decrypt = cbc_decrypt,
419 .cra_name =
"ctr(blowfish)",
420 .cra_driver_name =
"ctr-blowfish-asm",
424 .cra_ctxsize =
sizeof(
struct bf_ctx),
434 .encrypt = ctr_crypt,
435 .decrypt = ctr_crypt,
440 static bool is_blacklisted_cpu(
void)
463 if (!force && is_blacklisted_cpu()) {
465 "blowfish-x86_64: performance on this CPU "
466 "would be suboptimal: disabling "
467 "blowfish-x86_64.\n");
474 static void __exit fini(
void)