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
9065static 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
10470static 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
11075subsys_initcall (arc4_init );
@@ -113,4 +78,4 @@ module_exit(arc4_exit);
11378MODULE_LICENSE ("GPL" );
11479MODULE_DESCRIPTION ("ARC4 Cipher Algorithm" );
11580MODULE_AUTHOR ("Jon Oberheide <jon@oberheide.org>" );
116- MODULE_ALIAS_CRYPTO ("arc4" );
81+ MODULE_ALIAS_CRYPTO ("ecb( arc4) " );
0 commit comments