Linux Audio

Check our new training course

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