afs: Provide a splice-read wrapper
[linux-block.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
ce6dd368 10#include <crypto/algapi.h>
bd30cf53 11#include <crypto/arc4.h>
426bcb50
EB
12#include <crypto/internal/skcipher.h>
13#include <linux/init.h>
9ace6771 14#include <linux/kernel.h>
426bcb50 15#include <linux/module.h>
9ace6771 16#include <linux/sched.h>
1da177e4 17
611a23c2
AB
18static int crypto_arc4_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
19 unsigned int key_len)
426bcb50 20{
611a23c2 21 struct arc4_ctx *ctx = crypto_skcipher_ctx(tfm);
1da177e4 22
dc51f257 23 return arc4_setkey(ctx, in_key, key_len);
ce6dd368
JK
24}
25
611a23c2 26static int crypto_arc4_crypt(struct skcipher_request *req)
ce6dd368 27{
426bcb50
EB
28 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
29 struct arc4_ctx *ctx = crypto_skcipher_ctx(tfm);
30 struct skcipher_walk walk;
ce6dd368
JK
31 int err;
32
426bcb50 33 err = skcipher_walk_virt(&walk, req, false);
ce6dd368
JK
34
35 while (walk.nbytes > 0) {
426bcb50
EB
36 arc4_crypt(ctx, walk.dst.virt.addr, walk.src.virt.addr,
37 walk.nbytes);
38 err = skcipher_walk_done(&walk, 0);
ce6dd368
JK
39 }
40
41 return err;
42}
43
9ace6771
AB
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
611a23c2
AB
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 */
426bcb50 57 .base.cra_name = "ecb(arc4)",
d6ebf528 58 .base.cra_driver_name = "ecb(arc4)-generic",
426bcb50
EB
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,
611a23c2
AB
65 .setkey = crypto_arc4_setkey,
66 .encrypt = crypto_arc4_crypt,
67 .decrypt = crypto_arc4_crypt,
9ace6771 68 .init = crypto_arc4_init,
426bcb50 69};
1da177e4
LT
70
71static int __init arc4_init(void)
72{
611a23c2 73 return crypto_register_skcipher(&arc4_alg);
1da177e4
LT
74}
75
1da177e4
LT
76static void __exit arc4_exit(void)
77{
611a23c2 78 crypto_unregister_skcipher(&arc4_alg);
1da177e4
LT
79}
80
c4741b23 81subsys_initcall(arc4_init);
1da177e4
LT
82module_exit(arc4_exit);
83
84MODULE_LICENSE("GPL");
85MODULE_DESCRIPTION("ARC4 Cipher Algorithm");
86MODULE_AUTHOR("Jon Oberheide <jon@oberheide.org>");
611a23c2 87MODULE_ALIAS_CRYPTO("ecb(arc4)");