Merge branch 'Bonding-fixes-for-Ocelot-switch'
[linux-2.6-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>
14#include <linux/module.h>
1da177e4 15
611a23c2
AB
16static int crypto_arc4_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
17 unsigned int key_len)
426bcb50 18{
611a23c2 19 struct arc4_ctx *ctx = crypto_skcipher_ctx(tfm);
1da177e4 20
dc51f257 21 return arc4_setkey(ctx, in_key, key_len);
ce6dd368
JK
22}
23
611a23c2 24static int crypto_arc4_crypt(struct skcipher_request *req)
ce6dd368 25{
426bcb50
EB
26 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
27 struct arc4_ctx *ctx = crypto_skcipher_ctx(tfm);
28 struct skcipher_walk walk;
ce6dd368
JK
29 int err;
30
426bcb50 31 err = skcipher_walk_virt(&walk, req, false);
ce6dd368
JK
32
33 while (walk.nbytes > 0) {
426bcb50
EB
34 arc4_crypt(ctx, walk.dst.virt.addr, walk.src.virt.addr,
35 walk.nbytes);
36 err = skcipher_walk_done(&walk, 0);
ce6dd368
JK
37 }
38
39 return err;
40}
41
611a23c2
AB
42static struct skcipher_alg arc4_alg = {
43 /*
44 * For legacy reasons, this is named "ecb(arc4)", not "arc4".
45 * Nevertheless it's actually a stream cipher, not a block cipher.
46 */
426bcb50 47 .base.cra_name = "ecb(arc4)",
d6ebf528 48 .base.cra_driver_name = "ecb(arc4)-generic",
426bcb50
EB
49 .base.cra_priority = 100,
50 .base.cra_blocksize = ARC4_BLOCK_SIZE,
51 .base.cra_ctxsize = sizeof(struct arc4_ctx),
52 .base.cra_module = THIS_MODULE,
53 .min_keysize = ARC4_MIN_KEY_SIZE,
54 .max_keysize = ARC4_MAX_KEY_SIZE,
611a23c2
AB
55 .setkey = crypto_arc4_setkey,
56 .encrypt = crypto_arc4_crypt,
57 .decrypt = crypto_arc4_crypt,
426bcb50 58};
1da177e4
LT
59
60static int __init arc4_init(void)
61{
611a23c2 62 return crypto_register_skcipher(&arc4_alg);
1da177e4
LT
63}
64
1da177e4
LT
65static void __exit arc4_exit(void)
66{
611a23c2 67 crypto_unregister_skcipher(&arc4_alg);
1da177e4
LT
68}
69
c4741b23 70subsys_initcall(arc4_init);
1da177e4
LT
71module_exit(arc4_exit);
72
73MODULE_LICENSE("GPL");
74MODULE_DESCRIPTION("ARC4 Cipher Algorithm");
75MODULE_AUTHOR("Jon Oberheide <jon@oberheide.org>");
611a23c2 76MODULE_ALIAS_CRYPTO("ecb(arc4)");