Skip to content

Commit 611a23c

Browse files
Ard Biesheuvelherbertx
authored andcommitted
crypto: arc4 - remove cipher implementation
There are no remaining users of the cipher implementation, and there are no meaningful ways in which the arc4 cipher can be combined with templates other than ECB (and the way we do provide that combination is highly dubious to begin with). So let's drop the arc4 cipher altogether, and only keep the ecb(arc4) skcipher, which is used in various places in the kernel. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 4be2970 commit 611a23c

File tree

2 files changed

+16
-50
lines changed

2 files changed

+16
-50
lines changed

crypto/arc4.c

Lines changed: 15 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,15 @@
1818
#include <linux/init.h>
1919
#include <linux/module.h>
2020

21-
static int arc4_set_key(struct crypto_tfm *tfm, const u8 *in_key,
22-
unsigned int key_len)
21+
static int crypto_arc4_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
22+
unsigned int key_len)
2323
{
24-
struct arc4_ctx *ctx = crypto_tfm_ctx(tfm);
24+
struct arc4_ctx *ctx = crypto_skcipher_ctx(tfm);
2525

2626
return arc4_setkey(ctx, in_key, key_len);
2727
}
2828

29-
static int arc4_set_key_skcipher(struct crypto_skcipher *tfm, const u8 *in_key,
30-
unsigned int key_len)
31-
{
32-
return arc4_set_key(&tfm->base, in_key, key_len);
33-
}
34-
35-
static void arc4_crypt_one(struct crypto_tfm *tfm, u8 *out, const u8 *in)
36-
{
37-
arc4_crypt(crypto_tfm_ctx(tfm), out, in, 1);
38-
}
39-
40-
static int ecb_arc4_crypt(struct skcipher_request *req)
29+
static int crypto_arc4_crypt(struct skcipher_request *req)
4130
{
4231
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
4332
struct arc4_ctx *ctx = crypto_skcipher_ctx(tfm);
@@ -55,25 +44,11 @@ static int ecb_arc4_crypt(struct skcipher_request *req)
5544
return err;
5645
}
5746

58-
static struct crypto_alg arc4_cipher = {
59-
.cra_name = "arc4",
60-
.cra_driver_name = "arc4-generic",
61-
.cra_flags = CRYPTO_ALG_TYPE_CIPHER,
62-
.cra_blocksize = ARC4_BLOCK_SIZE,
63-
.cra_ctxsize = sizeof(struct arc4_ctx),
64-
.cra_module = THIS_MODULE,
65-
.cra_u = {
66-
.cipher = {
67-
.cia_min_keysize = ARC4_MIN_KEY_SIZE,
68-
.cia_max_keysize = ARC4_MAX_KEY_SIZE,
69-
.cia_setkey = arc4_set_key,
70-
.cia_encrypt = arc4_crypt_one,
71-
.cia_decrypt = arc4_crypt_one,
72-
},
73-
},
74-
};
75-
76-
static struct skcipher_alg arc4_skcipher = {
47+
static struct skcipher_alg arc4_alg = {
48+
/*
49+
* For legacy reasons, this is named "ecb(arc4)", not "arc4".
50+
* Nevertheless it's actually a stream cipher, not a block cipher.
51+
*/
7752
.base.cra_name = "ecb(arc4)",
7853
.base.cra_driver_name = "ecb(arc4)-generic",
7954
.base.cra_priority = 100,
@@ -82,29 +57,19 @@ static struct skcipher_alg arc4_skcipher = {
8257
.base.cra_module = THIS_MODULE,
8358
.min_keysize = ARC4_MIN_KEY_SIZE,
8459
.max_keysize = ARC4_MAX_KEY_SIZE,
85-
.setkey = arc4_set_key_skcipher,
86-
.encrypt = ecb_arc4_crypt,
87-
.decrypt = ecb_arc4_crypt,
60+
.setkey = crypto_arc4_setkey,
61+
.encrypt = crypto_arc4_crypt,
62+
.decrypt = crypto_arc4_crypt,
8863
};
8964

9065
static int __init arc4_init(void)
9166
{
92-
int err;
93-
94-
err = crypto_register_alg(&arc4_cipher);
95-
if (err)
96-
return err;
97-
98-
err = crypto_register_skcipher(&arc4_skcipher);
99-
if (err)
100-
crypto_unregister_alg(&arc4_cipher);
101-
return err;
67+
return crypto_register_skcipher(&arc4_alg);
10268
}
10369

10470
static void __exit arc4_exit(void)
10571
{
106-
crypto_unregister_alg(&arc4_cipher);
107-
crypto_unregister_skcipher(&arc4_skcipher);
72+
crypto_unregister_skcipher(&arc4_alg);
10873
}
10974

11075
subsys_initcall(arc4_init);
@@ -113,4 +78,4 @@ module_exit(arc4_exit);
11378
MODULE_LICENSE("GPL");
11479
MODULE_DESCRIPTION("ARC4 Cipher Algorithm");
11580
MODULE_AUTHOR("Jon Oberheide <jon@oberheide.org>");
116-
MODULE_ALIAS_CRYPTO("arc4");
81+
MODULE_ALIAS_CRYPTO("ecb(arc4)");

crypto/testmgr.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4404,6 +4404,7 @@ static const struct alg_test_desc alg_test_descs[] = {
44044404
}
44054405
}, {
44064406
.alg = "ecb(arc4)",
4407+
.generic_driver = "ecb(arc4)-generic",
44074408
.test = alg_test_skcipher,
44084409
.suite = {
44094410
.cipher = __VECS(arc4_tv_template)

0 commit comments

Comments
 (0)