hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/crypto/crypto_null.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Cryptographic API.
34 *
....@@ -9,12 +10,6 @@
910 * The null cipher is compliant with RFC2410.
1011 *
1112 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
12
- *
13
- * This program is free software; you can redistribute it and/or modify
14
- * it under the terms of the GNU General Public License as published by
15
- * the Free Software Foundation; either version 2 of the License, or
16
- * (at your option) any later version.
17
- *
1813 */
1914
2015 #include <crypto/null.h>
....@@ -26,7 +21,7 @@
2621 #include <linux/string.h>
2722
2823 static DEFINE_MUTEX(crypto_default_null_skcipher_lock);
29
-static struct crypto_skcipher *crypto_default_null_skcipher;
24
+static struct crypto_sync_skcipher *crypto_default_null_skcipher;
3025 static int crypto_default_null_skcipher_refcnt;
3126
3227 static int null_compress(struct crypto_tfm *tfm, const u8 *src,
....@@ -65,6 +60,10 @@
6560 unsigned int keylen)
6661 { return 0; }
6762
63
+static int null_skcipher_setkey(struct crypto_skcipher *tfm, const u8 *key,
64
+ unsigned int keylen)
65
+{ return 0; }
66
+
6867 static int null_setkey(struct crypto_tfm *tfm, const u8 *key,
6968 unsigned int keylen)
7069 { return 0; }
....@@ -74,21 +73,18 @@
7473 memcpy(dst, src, NULL_BLOCK_SIZE);
7574 }
7675
77
-static int skcipher_null_crypt(struct blkcipher_desc *desc,
78
- struct scatterlist *dst,
79
- struct scatterlist *src, unsigned int nbytes)
76
+static int null_skcipher_crypt(struct skcipher_request *req)
8077 {
81
- struct blkcipher_walk walk;
78
+ struct skcipher_walk walk;
8279 int err;
8380
84
- blkcipher_walk_init(&walk, dst, src, nbytes);
85
- err = blkcipher_walk_virt(desc, &walk);
81
+ err = skcipher_walk_virt(&walk, req, false);
8682
8783 while (walk.nbytes) {
8884 if (walk.src.virt.addr != walk.dst.virt.addr)
8985 memcpy(walk.dst.virt.addr, walk.src.virt.addr,
9086 walk.nbytes);
91
- err = blkcipher_walk_done(desc, &walk, 0);
87
+ err = skcipher_walk_done(&walk, 0);
9288 }
9389
9490 return err;
....@@ -104,13 +100,30 @@
104100 .final = null_final,
105101 .base = {
106102 .cra_name = "digest_null",
103
+ .cra_driver_name = "digest_null-generic",
107104 .cra_blocksize = NULL_BLOCK_SIZE,
108105 .cra_module = THIS_MODULE,
109106 }
110107 };
111108
112
-static struct crypto_alg null_algs[3] = { {
109
+static struct skcipher_alg skcipher_null = {
110
+ .base.cra_name = "ecb(cipher_null)",
111
+ .base.cra_driver_name = "ecb-cipher_null",
112
+ .base.cra_priority = 100,
113
+ .base.cra_blocksize = NULL_BLOCK_SIZE,
114
+ .base.cra_ctxsize = 0,
115
+ .base.cra_module = THIS_MODULE,
116
+ .min_keysize = NULL_KEY_SIZE,
117
+ .max_keysize = NULL_KEY_SIZE,
118
+ .ivsize = NULL_IV_SIZE,
119
+ .setkey = null_skcipher_setkey,
120
+ .encrypt = null_skcipher_crypt,
121
+ .decrypt = null_skcipher_crypt,
122
+};
123
+
124
+static struct crypto_alg null_algs[] = { {
113125 .cra_name = "cipher_null",
126
+ .cra_driver_name = "cipher_null-generic",
114127 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
115128 .cra_blocksize = NULL_BLOCK_SIZE,
116129 .cra_ctxsize = 0,
....@@ -122,23 +135,8 @@
122135 .cia_encrypt = null_crypt,
123136 .cia_decrypt = null_crypt } }
124137 }, {
125
- .cra_name = "ecb(cipher_null)",
126
- .cra_driver_name = "ecb-cipher_null",
127
- .cra_priority = 100,
128
- .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
129
- .cra_blocksize = NULL_BLOCK_SIZE,
130
- .cra_type = &crypto_blkcipher_type,
131
- .cra_ctxsize = 0,
132
- .cra_module = THIS_MODULE,
133
- .cra_u = { .blkcipher = {
134
- .min_keysize = NULL_KEY_SIZE,
135
- .max_keysize = NULL_KEY_SIZE,
136
- .ivsize = NULL_IV_SIZE,
137
- .setkey = null_setkey,
138
- .encrypt = skcipher_null_crypt,
139
- .decrypt = skcipher_null_crypt } }
140
-}, {
141138 .cra_name = "compress_null",
139
+ .cra_driver_name = "compress_null-generic",
142140 .cra_flags = CRYPTO_ALG_TYPE_COMPRESS,
143141 .cra_blocksize = NULL_BLOCK_SIZE,
144142 .cra_ctxsize = 0,
....@@ -152,16 +150,15 @@
152150 MODULE_ALIAS_CRYPTO("digest_null");
153151 MODULE_ALIAS_CRYPTO("cipher_null");
154152
155
-struct crypto_skcipher *crypto_get_default_null_skcipher(void)
153
+struct crypto_sync_skcipher *crypto_get_default_null_skcipher(void)
156154 {
157
- struct crypto_skcipher *tfm;
155
+ struct crypto_sync_skcipher *tfm;
158156
159157 mutex_lock(&crypto_default_null_skcipher_lock);
160158 tfm = crypto_default_null_skcipher;
161159
162160 if (!tfm) {
163
- tfm = crypto_alloc_skcipher("ecb(cipher_null)",
164
- 0, CRYPTO_ALG_ASYNC);
161
+ tfm = crypto_alloc_sync_skcipher("ecb(cipher_null)", 0, 0);
165162 if (IS_ERR(tfm))
166163 goto unlock;
167164
....@@ -181,7 +178,7 @@
181178 {
182179 mutex_lock(&crypto_default_null_skcipher_lock);
183180 if (!--crypto_default_null_skcipher_refcnt) {
184
- crypto_free_skcipher(crypto_default_null_skcipher);
181
+ crypto_free_sync_skcipher(crypto_default_null_skcipher);
185182 crypto_default_null_skcipher = NULL;
186183 }
187184 mutex_unlock(&crypto_default_null_skcipher_lock);
....@@ -200,8 +197,14 @@
200197 if (ret < 0)
201198 goto out_unregister_algs;
202199
200
+ ret = crypto_register_skcipher(&skcipher_null);
201
+ if (ret < 0)
202
+ goto out_unregister_shash;
203
+
203204 return 0;
204205
206
+out_unregister_shash:
207
+ crypto_unregister_shash(&digest_null);
205208 out_unregister_algs:
206209 crypto_unregister_algs(null_algs, ARRAY_SIZE(null_algs));
207210 out:
....@@ -210,11 +213,12 @@
210213
211214 static void __exit crypto_null_mod_fini(void)
212215 {
213
- crypto_unregister_shash(&digest_null);
214216 crypto_unregister_algs(null_algs, ARRAY_SIZE(null_algs));
217
+ crypto_unregister_shash(&digest_null);
218
+ crypto_unregister_skcipher(&skcipher_null);
215219 }
216220
217
-module_init(crypto_null_mod_init);
221
+subsys_initcall(crypto_null_mod_init);
218222 module_exit(crypto_null_mod_fini);
219223
220224 MODULE_LICENSE("GPL");