]> git.ipfire.org Git - thirdparty/kernel/stable.git/blame - crypto/arc4.c
Merge tag 'kvmarm-fixes-6.8-2' of git://git.kernel.org/pub/scm/linux/kernel/git/kvmar...
[thirdparty/kernel/stable.git] / crypto / arc4.c
CommitLineData
2874c5fd 1// SPDX-License-Identifier: GPL-2.0-or-later
cfa2b54e 2/*
1da177e4
LT
3 * Cryptographic API
4 *
5 * ARC4 Cipher Algorithm
6 *
7 * Jon Oberheide <jon@oberheide.org>
1da177e4 8 */
ce6dd368 9
bd30cf53 10#include <crypto/arc4.h>
426bcb50
EB
11#include <crypto/internal/skcipher.h>
12#include <linux/init.h>
9ace6771 13#include <linux/kernel.h>
426bcb50 14#include <linux/module.h>
9ace6771 15#include <linux/sched.h>
1da177e4 16
47309ea1
HX
17#define ARC4_ALIGN __alignof__(struct arc4_ctx)
18
9a91792d 19static int crypto_arc4_setkey(struct crypto_lskcipher *tfm, const u8 *in_key,
611a23c2 20 unsigned int key_len)
426bcb50 21{
9a91792d 22 struct arc4_ctx *ctx = crypto_lskcipher_ctx(tfm);
1da177e4 23
dc51f257 24 return arc4_setkey(ctx, in_key, key_len);
ce6dd368
JK
25}
26
9a91792d 27static int crypto_arc4_crypt(struct crypto_lskcipher *tfm, const u8 *src,
47309ea1 28 u8 *dst, unsigned nbytes, u8 *siv, u32 flags)
ce6dd368 29{
9a91792d 30 struct arc4_ctx *ctx = crypto_lskcipher_ctx(tfm);
ce6dd368 31
47309ea1
HX
32 if (!(flags & CRYPTO_LSKCIPHER_FLAG_CONT))
33 memcpy(siv, ctx, sizeof(*ctx));
34
35 ctx = (struct arc4_ctx *)siv;
36
9a91792d
HX
37 arc4_crypt(ctx, dst, src, nbytes);
38 return 0;
ce6dd368
JK
39}
40
9a91792d 41static int crypto_arc4_init(struct crypto_lskcipher *tfm)
9ace6771
AB
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
9a91792d
HX
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),
47309ea1 55 .co.base.cra_alignmask = ARC4_ALIGN - 1,
9a91792d
HX
56 .co.base.cra_module = THIS_MODULE,
57 .co.min_keysize = ARC4_MIN_KEY_SIZE,
58 .co.max_keysize = ARC4_MAX_KEY_SIZE,
47309ea1 59 .co.statesize = sizeof(struct arc4_ctx),
9a91792d
HX
60 .setkey = crypto_arc4_setkey,
61 .encrypt = crypto_arc4_crypt,
62 .decrypt = crypto_arc4_crypt,
63 .init = crypto_arc4_init,
426bcb50 64};
1da177e4
LT
65
66static int __init arc4_init(void)
67{
9a91792d 68 return crypto_register_lskcipher(&arc4_alg);
1da177e4
LT
69}
70
1da177e4
LT
71static void __exit arc4_exit(void)
72{
9a91792d 73 crypto_unregister_lskcipher(&arc4_alg);
1da177e4
LT
74}
75
c4741b23 76subsys_initcall(arc4_init);
1da177e4
LT
77module_exit(arc4_exit);
78
79MODULE_LICENSE("GPL");
80MODULE_DESCRIPTION("ARC4 Cipher Algorithm");
81MODULE_AUTHOR("Jon Oberheide <jon@oberheide.org>");
611a23c2 82MODULE_ALIAS_CRYPTO("ecb(arc4)");