6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10 #include <linux/module.h>
12 #include <linux/types.h>
32 static void encrypt_to_decrypt(
u64 *
d,
const u64 *
e)
78 static void des_decrypt(
struct crypto_tfm *tfm,
u8 *dst,
const u8 *src)
91 #define DES_BLOCK_MASK (~(DES_BLOCK_SIZE - 1))
101 blkcipher_walk_init(&walk, dst, src, nbytes);
108 while ((nbytes = walk.
nbytes)) {
127 return __ecb_crypt(desc, dst, src, nbytes,
true);
134 return __ecb_crypt(desc, dst, src, nbytes,
false);
138 unsigned int len,
u64 *
iv);
148 blkcipher_walk_init(&walk, dst, src, nbytes);
152 while ((nbytes = walk.nbytes)) {
157 (
u64 *) walk.dst.virt.addr,
158 block_len, (
u64 *) walk.iv);
168 unsigned int len,
u64 *
iv);
178 blkcipher_walk_init(&walk, dst, src, nbytes);
182 while ((nbytes = walk.nbytes)) {
187 (
u64 *) walk.dst.virt.addr,
188 block_len, (
u64 *) walk.iv);
197 static int des3_ede_set_key(
struct crypto_tfm *tfm,
const u8 *key,
201 const u32 *K = (
const u32 *)key;
207 if (
unlikely(!((K[0] ^ K[2]) | (K[1] ^ K[3])) ||
208 !((K[2] ^ K[4]) | (K[3] ^ K[5]))) &&
237 static void des3_ede_encrypt(
struct crypto_tfm *tfm,
u8 *dst,
const u8 *src)
245 static void des3_ede_decrypt(
struct crypto_tfm *tfm,
u8 *dst,
const u8 *src)
256 u64 *output,
unsigned int len);
260 unsigned int nbytes,
bool encrypt)
267 blkcipher_walk_init(&walk, dst, src, nbytes);
275 while ((nbytes = walk.nbytes)) {
279 const u64 *src64 = (
const u64 *)walk.src.virt.addr;
281 (
u64 *) walk.dst.virt.addr,
295 return __ecb3_crypt(desc, dst, src, nbytes,
true);
302 return __ecb3_crypt(desc, dst, src, nbytes,
false);
306 u64 *output,
unsigned int len,
318 blkcipher_walk_init(&walk, dst, src, nbytes);
323 while ((nbytes = walk.nbytes)) {
327 const u64 *src64 = (
const u64 *)walk.src.virt.addr;
329 (
u64 *) walk.dst.virt.addr,
341 u64 *output,
unsigned int len,
353 blkcipher_walk_init(&walk, dst, src, nbytes);
358 while ((nbytes = walk.nbytes)) {
362 const u64 *src64 = (
const u64 *)walk.src.virt.addr;
364 (
u64 *) walk.dst.virt.addr,
377 .cra_driver_name =
"des-sparc64",
388 .cia_setkey = des_set_key,
389 .cia_encrypt = des_encrypt,
390 .cia_decrypt = des_decrypt
394 .cra_name =
"ecb(des)",
395 .cra_driver_name =
"ecb-des-sparc64",
407 .setkey = des_set_key,
408 .encrypt = ecb_encrypt,
409 .decrypt = ecb_decrypt,
413 .cra_name =
"cbc(des)",
414 .cra_driver_name =
"cbc-des-sparc64",
426 .setkey = des_set_key,
427 .encrypt = cbc_encrypt,
428 .decrypt = cbc_decrypt,
432 .cra_name =
"des3_ede",
433 .cra_driver_name =
"des3_ede-sparc64",
444 .cia_setkey = des3_ede_set_key,
445 .cia_encrypt = des3_ede_encrypt,
446 .cia_decrypt = des3_ede_decrypt
450 .cra_name =
"ecb(des3_ede)",
451 .cra_driver_name =
"ecb-des3_ede-sparc64",
463 .setkey = des3_ede_set_key,
464 .encrypt = ecb3_encrypt,
465 .decrypt = ecb3_decrypt,
469 .cra_name =
"cbc(des3_ede)",
470 .cra_driver_name =
"cbc-des3_ede-sparc64",
482 .setkey = des3_ede_set_key,
483 .encrypt = cbc3_encrypt,
484 .decrypt = cbc3_decrypt,
489 static bool __init sparc64_has_des_opcode(
void)
496 __asm__ __volatile__(
"rd %%asr26, %0" :
"=r" (cfr));
503 static int __init des_sparc64_mod_init(
void)
508 INIT_LIST_HEAD(&algs[i].cra_list);
510 if (sparc64_has_des_opcode()) {
511 pr_info(
"Using sparc64 des opcodes optimized DES implementation\n");
514 pr_info(
"sparc64 des opcodes not available.\n");
518 static void __exit des_sparc64_mod_fini(
void)
527 MODULE_DESCRIPTION(
"DES & Triple DES EDE Cipher Algorithms, sparc64 des opcode accelerated");