1 // SPDX-License-Identifier: GPL-2.0-or-later 1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 2 /* 3 * Cryptographic API 3 * Cryptographic API 4 * 4 * 5 * ARC4 Cipher Algorithm 5 * ARC4 Cipher Algorithm 6 * 6 * 7 * Jon Oberheide <jon@oberheide.org> 7 * Jon Oberheide <jon@oberheide.org> 8 */ 8 */ 9 9 >> 10 #include <crypto/algapi.h> 10 #include <crypto/arc4.h> 11 #include <crypto/arc4.h> 11 #include <crypto/internal/skcipher.h> 12 #include <crypto/internal/skcipher.h> 12 #include <linux/init.h> 13 #include <linux/init.h> 13 #include <linux/kernel.h> 14 #include <linux/kernel.h> 14 #include <linux/module.h> 15 #include <linux/module.h> 15 #include <linux/sched.h> 16 #include <linux/sched.h> 16 17 17 #define ARC4_ALIGN __alignof__(struct arc4_ctx !! 18 static int crypto_arc4_setkey(struct crypto_skcipher *tfm, const u8 *in_key, 18 << 19 static int crypto_arc4_setkey(struct crypto_ls << 20 unsigned int key 19 unsigned int key_len) 21 { 20 { 22 struct arc4_ctx *ctx = crypto_lskciphe !! 21 struct arc4_ctx *ctx = crypto_skcipher_ctx(tfm); 23 22 24 return arc4_setkey(ctx, in_key, key_le 23 return arc4_setkey(ctx, in_key, key_len); 25 } 24 } 26 25 27 static int crypto_arc4_crypt(struct crypto_lsk !! 26 static int crypto_arc4_crypt(struct skcipher_request *req) 28 u8 *dst, unsigned << 29 { 27 { 30 struct arc4_ctx *ctx = crypto_lskciphe !! 28 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); 31 !! 29 struct arc4_ctx *ctx = crypto_skcipher_ctx(tfm); 32 if (!(flags & CRYPTO_LSKCIPHER_FLAG_CO !! 30 struct skcipher_walk walk; 33 memcpy(siv, ctx, sizeof(*ctx)) !! 31 int err; >> 32 >> 33 err = skcipher_walk_virt(&walk, req, false); >> 34 >> 35 while (walk.nbytes > 0) { >> 36 arc4_crypt(ctx, walk.dst.virt.addr, walk.src.virt.addr, >> 37 walk.nbytes); >> 38 err = skcipher_walk_done(&walk, 0); >> 39 } 34 40 35 ctx = (struct arc4_ctx *)siv; !! 41 return err; 36 << 37 arc4_crypt(ctx, dst, src, nbytes); << 38 return 0; << 39 } 42 } 40 43 41 static int crypto_arc4_init(struct crypto_lskc !! 44 static int crypto_arc4_init(struct crypto_skcipher *tfm) 42 { 45 { 43 pr_warn_ratelimited("\"%s\" (%ld) uses 46 pr_warn_ratelimited("\"%s\" (%ld) uses obsolete ecb(arc4) skcipher\n", 44 current->comm, (un 47 current->comm, (unsigned long)current->pid); 45 48 46 return 0; 49 return 0; 47 } 50 } 48 51 49 static struct lskcipher_alg arc4_alg = { !! 52 static struct skcipher_alg arc4_alg = { 50 .co.base.cra_name = !! 53 /* 51 .co.base.cra_driver_name = !! 54 * For legacy reasons, this is named "ecb(arc4)", not "arc4". 52 .co.base.cra_priority = !! 55 * Nevertheless it's actually a stream cipher, not a block cipher. 53 .co.base.cra_blocksize = !! 56 */ 54 .co.base.cra_ctxsize = !! 57 .base.cra_name = "ecb(arc4)", 55 .co.base.cra_alignmask = !! 58 .base.cra_driver_name = "ecb(arc4)-generic", 56 .co.base.cra_module = !! 59 .base.cra_priority = 100, 57 .co.min_keysize = !! 60 .base.cra_blocksize = ARC4_BLOCK_SIZE, 58 .co.max_keysize = !! 61 .base.cra_ctxsize = sizeof(struct arc4_ctx), 59 .co.statesize = !! 62 .base.cra_module = THIS_MODULE, 60 .setkey = !! 63 .min_keysize = ARC4_MIN_KEY_SIZE, 61 .encrypt = !! 64 .max_keysize = ARC4_MAX_KEY_SIZE, 62 .decrypt = !! 65 .setkey = crypto_arc4_setkey, 63 .init = !! 66 .encrypt = crypto_arc4_crypt, >> 67 .decrypt = crypto_arc4_crypt, >> 68 .init = crypto_arc4_init, 64 }; 69 }; 65 70 66 static int __init arc4_init(void) 71 static int __init arc4_init(void) 67 { 72 { 68 return crypto_register_lskcipher(&arc4 !! 73 return crypto_register_skcipher(&arc4_alg); 69 } 74 } 70 75 71 static void __exit arc4_exit(void) 76 static void __exit arc4_exit(void) 72 { 77 { 73 crypto_unregister_lskcipher(&arc4_alg) !! 78 crypto_unregister_skcipher(&arc4_alg); 74 } 79 } 75 80 76 subsys_initcall(arc4_init); 81 subsys_initcall(arc4_init); 77 module_exit(arc4_exit); 82 module_exit(arc4_exit); 78 83 79 MODULE_LICENSE("GPL"); 84 MODULE_LICENSE("GPL"); 80 MODULE_DESCRIPTION("ARC4 Cipher Algorithm"); 85 MODULE_DESCRIPTION("ARC4 Cipher Algorithm"); 81 MODULE_AUTHOR("Jon Oberheide <jon@oberheide.or 86 MODULE_AUTHOR("Jon Oberheide <jon@oberheide.org>"); 82 MODULE_ALIAS_CRYPTO("ecb(arc4)"); 87 MODULE_ALIAS_CRYPTO("ecb(arc4)"); 83 88
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.