.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Cryptographic API. |
---|
3 | 4 | * |
---|
.. | .. |
---|
9 | 10 | * The null cipher is compliant with RFC2410. |
---|
10 | 11 | * |
---|
11 | 12 | * 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 | | - * |
---|
18 | 13 | */ |
---|
19 | 14 | |
---|
20 | 15 | #include <crypto/null.h> |
---|
.. | .. |
---|
26 | 21 | #include <linux/string.h> |
---|
27 | 22 | |
---|
28 | 23 | 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; |
---|
30 | 25 | static int crypto_default_null_skcipher_refcnt; |
---|
31 | 26 | |
---|
32 | 27 | static int null_compress(struct crypto_tfm *tfm, const u8 *src, |
---|
.. | .. |
---|
65 | 60 | unsigned int keylen) |
---|
66 | 61 | { return 0; } |
---|
67 | 62 | |
---|
| 63 | +static int null_skcipher_setkey(struct crypto_skcipher *tfm, const u8 *key, |
---|
| 64 | + unsigned int keylen) |
---|
| 65 | +{ return 0; } |
---|
| 66 | + |
---|
68 | 67 | static int null_setkey(struct crypto_tfm *tfm, const u8 *key, |
---|
69 | 68 | unsigned int keylen) |
---|
70 | 69 | { return 0; } |
---|
.. | .. |
---|
74 | 73 | memcpy(dst, src, NULL_BLOCK_SIZE); |
---|
75 | 74 | } |
---|
76 | 75 | |
---|
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) |
---|
80 | 77 | { |
---|
81 | | - struct blkcipher_walk walk; |
---|
| 78 | + struct skcipher_walk walk; |
---|
82 | 79 | int err; |
---|
83 | 80 | |
---|
84 | | - blkcipher_walk_init(&walk, dst, src, nbytes); |
---|
85 | | - err = blkcipher_walk_virt(desc, &walk); |
---|
| 81 | + err = skcipher_walk_virt(&walk, req, false); |
---|
86 | 82 | |
---|
87 | 83 | while (walk.nbytes) { |
---|
88 | 84 | if (walk.src.virt.addr != walk.dst.virt.addr) |
---|
89 | 85 | memcpy(walk.dst.virt.addr, walk.src.virt.addr, |
---|
90 | 86 | walk.nbytes); |
---|
91 | | - err = blkcipher_walk_done(desc, &walk, 0); |
---|
| 87 | + err = skcipher_walk_done(&walk, 0); |
---|
92 | 88 | } |
---|
93 | 89 | |
---|
94 | 90 | return err; |
---|
.. | .. |
---|
104 | 100 | .final = null_final, |
---|
105 | 101 | .base = { |
---|
106 | 102 | .cra_name = "digest_null", |
---|
| 103 | + .cra_driver_name = "digest_null-generic", |
---|
107 | 104 | .cra_blocksize = NULL_BLOCK_SIZE, |
---|
108 | 105 | .cra_module = THIS_MODULE, |
---|
109 | 106 | } |
---|
110 | 107 | }; |
---|
111 | 108 | |
---|
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[] = { { |
---|
113 | 125 | .cra_name = "cipher_null", |
---|
| 126 | + .cra_driver_name = "cipher_null-generic", |
---|
114 | 127 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, |
---|
115 | 128 | .cra_blocksize = NULL_BLOCK_SIZE, |
---|
116 | 129 | .cra_ctxsize = 0, |
---|
.. | .. |
---|
122 | 135 | .cia_encrypt = null_crypt, |
---|
123 | 136 | .cia_decrypt = null_crypt } } |
---|
124 | 137 | }, { |
---|
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 | | -}, { |
---|
141 | 138 | .cra_name = "compress_null", |
---|
| 139 | + .cra_driver_name = "compress_null-generic", |
---|
142 | 140 | .cra_flags = CRYPTO_ALG_TYPE_COMPRESS, |
---|
143 | 141 | .cra_blocksize = NULL_BLOCK_SIZE, |
---|
144 | 142 | .cra_ctxsize = 0, |
---|
.. | .. |
---|
152 | 150 | MODULE_ALIAS_CRYPTO("digest_null"); |
---|
153 | 151 | MODULE_ALIAS_CRYPTO("cipher_null"); |
---|
154 | 152 | |
---|
155 | | -struct crypto_skcipher *crypto_get_default_null_skcipher(void) |
---|
| 153 | +struct crypto_sync_skcipher *crypto_get_default_null_skcipher(void) |
---|
156 | 154 | { |
---|
157 | | - struct crypto_skcipher *tfm; |
---|
| 155 | + struct crypto_sync_skcipher *tfm; |
---|
158 | 156 | |
---|
159 | 157 | mutex_lock(&crypto_default_null_skcipher_lock); |
---|
160 | 158 | tfm = crypto_default_null_skcipher; |
---|
161 | 159 | |
---|
162 | 160 | 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); |
---|
165 | 162 | if (IS_ERR(tfm)) |
---|
166 | 163 | goto unlock; |
---|
167 | 164 | |
---|
.. | .. |
---|
181 | 178 | { |
---|
182 | 179 | mutex_lock(&crypto_default_null_skcipher_lock); |
---|
183 | 180 | if (!--crypto_default_null_skcipher_refcnt) { |
---|
184 | | - crypto_free_skcipher(crypto_default_null_skcipher); |
---|
| 181 | + crypto_free_sync_skcipher(crypto_default_null_skcipher); |
---|
185 | 182 | crypto_default_null_skcipher = NULL; |
---|
186 | 183 | } |
---|
187 | 184 | mutex_unlock(&crypto_default_null_skcipher_lock); |
---|
.. | .. |
---|
200 | 197 | if (ret < 0) |
---|
201 | 198 | goto out_unregister_algs; |
---|
202 | 199 | |
---|
| 200 | + ret = crypto_register_skcipher(&skcipher_null); |
---|
| 201 | + if (ret < 0) |
---|
| 202 | + goto out_unregister_shash; |
---|
| 203 | + |
---|
203 | 204 | return 0; |
---|
204 | 205 | |
---|
| 206 | +out_unregister_shash: |
---|
| 207 | + crypto_unregister_shash(&digest_null); |
---|
205 | 208 | out_unregister_algs: |
---|
206 | 209 | crypto_unregister_algs(null_algs, ARRAY_SIZE(null_algs)); |
---|
207 | 210 | out: |
---|
.. | .. |
---|
210 | 213 | |
---|
211 | 214 | static void __exit crypto_null_mod_fini(void) |
---|
212 | 215 | { |
---|
213 | | - crypto_unregister_shash(&digest_null); |
---|
214 | 216 | crypto_unregister_algs(null_algs, ARRAY_SIZE(null_algs)); |
---|
| 217 | + crypto_unregister_shash(&digest_null); |
---|
| 218 | + crypto_unregister_skcipher(&skcipher_null); |
---|
215 | 219 | } |
---|
216 | 220 | |
---|
217 | | -module_init(crypto_null_mod_init); |
---|
| 221 | +subsys_initcall(crypto_null_mod_init); |
---|
218 | 222 | module_exit(crypto_null_mod_fini); |
---|
219 | 223 | |
---|
220 | 224 | MODULE_LICENSE("GPL"); |
---|