0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <crypto/algapi.h>
0011 #include <crypto/arc4.h>
0012 #include <crypto/internal/skcipher.h>
0013 #include <linux/init.h>
0014 #include <linux/kernel.h>
0015 #include <linux/module.h>
0016 #include <linux/sched.h>
0017
0018 static int crypto_arc4_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
0019 unsigned int key_len)
0020 {
0021 struct arc4_ctx *ctx = crypto_skcipher_ctx(tfm);
0022
0023 return arc4_setkey(ctx, in_key, key_len);
0024 }
0025
0026 static int crypto_arc4_crypt(struct skcipher_request *req)
0027 {
0028 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
0029 struct arc4_ctx *ctx = crypto_skcipher_ctx(tfm);
0030 struct skcipher_walk walk;
0031 int err;
0032
0033 err = skcipher_walk_virt(&walk, req, false);
0034
0035 while (walk.nbytes > 0) {
0036 arc4_crypt(ctx, walk.dst.virt.addr, walk.src.virt.addr,
0037 walk.nbytes);
0038 err = skcipher_walk_done(&walk, 0);
0039 }
0040
0041 return err;
0042 }
0043
0044 static int crypto_arc4_init(struct crypto_skcipher *tfm)
0045 {
0046 pr_warn_ratelimited("\"%s\" (%ld) uses obsolete ecb(arc4) skcipher\n",
0047 current->comm, (unsigned long)current->pid);
0048
0049 return 0;
0050 }
0051
0052 static struct skcipher_alg arc4_alg = {
0053
0054
0055
0056
0057 .base.cra_name = "ecb(arc4)",
0058 .base.cra_driver_name = "ecb(arc4)-generic",
0059 .base.cra_priority = 100,
0060 .base.cra_blocksize = ARC4_BLOCK_SIZE,
0061 .base.cra_ctxsize = sizeof(struct arc4_ctx),
0062 .base.cra_module = THIS_MODULE,
0063 .min_keysize = ARC4_MIN_KEY_SIZE,
0064 .max_keysize = ARC4_MAX_KEY_SIZE,
0065 .setkey = crypto_arc4_setkey,
0066 .encrypt = crypto_arc4_crypt,
0067 .decrypt = crypto_arc4_crypt,
0068 .init = crypto_arc4_init,
0069 };
0070
0071 static int __init arc4_init(void)
0072 {
0073 return crypto_register_skcipher(&arc4_alg);
0074 }
0075
0076 static void __exit arc4_exit(void)
0077 {
0078 crypto_unregister_skcipher(&arc4_alg);
0079 }
0080
0081 subsys_initcall(arc4_init);
0082 module_exit(arc4_exit);
0083
0084 MODULE_LICENSE("GPL");
0085 MODULE_DESCRIPTION("ARC4 Cipher Algorithm");
0086 MODULE_AUTHOR("Jon Oberheide <jon@oberheide.org>");
0087 MODULE_ALIAS_CRYPTO("ecb(arc4)");