1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * ARC4 Cipher Algorithm
7 * Jon Oberheide <jon@oberheide.org>
10 #include <crypto/algapi.h>
11 #include <crypto/arc4.h>
12 #include <crypto/internal/skcipher.h>
13 #include <linux/init.h>
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/sched.h>
18 static int crypto_arc4_setkey(struct crypto_skcipher
*tfm
, const u8
*in_key
,
21 struct arc4_ctx
*ctx
= crypto_skcipher_ctx(tfm
);
23 return arc4_setkey(ctx
, in_key
, key_len
);
26 static int crypto_arc4_crypt(struct skcipher_request
*req
)
28 struct crypto_skcipher
*tfm
= crypto_skcipher_reqtfm(req
);
29 struct arc4_ctx
*ctx
= crypto_skcipher_ctx(tfm
);
30 struct skcipher_walk walk
;
33 err
= skcipher_walk_virt(&walk
, req
, false);
35 while (walk
.nbytes
> 0) {
36 arc4_crypt(ctx
, walk
.dst
.virt
.addr
, walk
.src
.virt
.addr
,
38 err
= skcipher_walk_done(&walk
, 0);
44 static int crypto_arc4_init(struct crypto_skcipher
*tfm
)
46 pr_warn_ratelimited("\"%s\" (%ld) uses obsolete ecb(arc4) skcipher\n",
47 current
->comm
, (unsigned long)current
->pid
);
52 static struct skcipher_alg arc4_alg
= {
54 * For legacy reasons, this is named "ecb(arc4)", not "arc4".
55 * Nevertheless it's actually a stream cipher, not a block cipher.
57 .base
.cra_name
= "ecb(arc4)",
58 .base
.cra_driver_name
= "ecb(arc4)-generic",
59 .base
.cra_priority
= 100,
60 .base
.cra_blocksize
= ARC4_BLOCK_SIZE
,
61 .base
.cra_ctxsize
= sizeof(struct arc4_ctx
),
62 .base
.cra_module
= THIS_MODULE
,
63 .min_keysize
= ARC4_MIN_KEY_SIZE
,
64 .max_keysize
= ARC4_MAX_KEY_SIZE
,
65 .setkey
= crypto_arc4_setkey
,
66 .encrypt
= crypto_arc4_crypt
,
67 .decrypt
= crypto_arc4_crypt
,
68 .init
= crypto_arc4_init
,
71 static int __init
arc4_init(void)
73 return crypto_register_skcipher(&arc4_alg
);
76 static void __exit
arc4_exit(void)
78 crypto_unregister_skcipher(&arc4_alg
);
81 subsys_initcall(arc4_init
);
82 module_exit(arc4_exit
);
84 MODULE_LICENSE("GPL");
85 MODULE_DESCRIPTION("ARC4 Cipher Algorithm");
86 MODULE_AUTHOR("Jon Oberheide <jon@oberheide.org>");
87 MODULE_ALIAS_CRYPTO("ecb(arc4)");