hc
2024-05-10 61598093bbdd283a7edc367d900f223070ead8d2
kernel/crypto/seqiv.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * seqiv: Sequence Number IV Generator
34 *
....@@ -5,12 +6,6 @@
56 * with a salt. This algorithm is mainly useful for CTR and similar modes.
67 *
78 * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>
8
- *
9
- * This program is free software; you can redistribute it and/or modify it
10
- * under the terms of the GNU General Public License as published by the Free
11
- * Software Foundation; either version 2 of the License, or (at your option)
12
- * any later version.
13
- *
149 */
1510
1611 #include <crypto/internal/geniv.h>
....@@ -23,14 +18,12 @@
2318 #include <linux/slab.h>
2419 #include <linux/string.h>
2520
26
-static void seqiv_free(struct crypto_instance *inst);
27
-
2821 static void seqiv_aead_encrypt_complete2(struct aead_request *req, int err)
2922 {
3023 struct aead_request *subreq = aead_request_ctx(req);
3124 struct crypto_aead *geniv;
3225
33
- if (err == -EINPROGRESS)
26
+ if (err == -EINPROGRESS || err == -EBUSY)
3427 return;
3528
3629 if (err)
....@@ -40,7 +33,7 @@
4033 memcpy(req->iv, subreq->iv, crypto_aead_ivsize(geniv));
4134
4235 out:
43
- kzfree(subreq->iv);
36
+ kfree_sensitive(subreq->iv);
4437 }
4538
4639 static void seqiv_aead_encrypt_complete(struct crypto_async_request *base,
....@@ -73,9 +66,9 @@
7366 info = req->iv;
7467
7568 if (req->src != req->dst) {
76
- SKCIPHER_REQUEST_ON_STACK(nreq, ctx->sknull);
69
+ SYNC_SKCIPHER_REQUEST_ON_STACK(nreq, ctx->sknull);
7770
78
- skcipher_request_set_tfm(nreq, ctx->sknull);
71
+ skcipher_request_set_sync_tfm(nreq, ctx->sknull);
7972 skcipher_request_set_callback(nreq, req->base.flags,
8073 NULL, NULL);
8174 skcipher_request_set_crypt(nreq, req->src, req->dst,
....@@ -89,13 +82,12 @@
8982
9083 if (unlikely(!IS_ALIGNED((unsigned long)info,
9184 crypto_aead_alignmask(geniv) + 1))) {
92
- info = kmalloc(ivsize, req->base.flags &
93
- CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL:
94
- GFP_ATOMIC);
85
+ info = kmemdup(req->iv, ivsize, req->base.flags &
86
+ CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL :
87
+ GFP_ATOMIC);
9588 if (!info)
9689 return -ENOMEM;
9790
98
- memcpy(info, req->iv, ivsize);
9991 compl = seqiv_aead_encrypt_complete;
10092 data = req;
10193 }
....@@ -146,7 +138,7 @@
146138 struct aead_instance *inst;
147139 int err;
148140
149
- inst = aead_geniv_alloc(tmpl, tb, 0, 0);
141
+ inst = aead_geniv_alloc(tmpl, tb);
150142
151143 if (IS_ERR(inst))
152144 return PTR_ERR(inst);
....@@ -165,40 +157,16 @@
165157 inst->alg.base.cra_ctxsize += inst->alg.ivsize;
166158
167159 err = aead_register_instance(tmpl, inst);
168
- if (err)
169
- goto free_inst;
170
-
171
-out:
172
- return err;
173
-
160
+ if (err) {
174161 free_inst:
175
- aead_geniv_free(inst);
176
- goto out;
177
-}
178
-
179
-static int seqiv_create(struct crypto_template *tmpl, struct rtattr **tb)
180
-{
181
- struct crypto_attr_type *algt;
182
-
183
- algt = crypto_get_attr_type(tb);
184
- if (IS_ERR(algt))
185
- return PTR_ERR(algt);
186
-
187
- if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & CRYPTO_ALG_TYPE_MASK)
188
- return -EINVAL;
189
-
190
- return seqiv_aead_create(tmpl, tb);
191
-}
192
-
193
-static void seqiv_free(struct crypto_instance *inst)
194
-{
195
- aead_geniv_free(aead_instance(inst));
162
+ inst->free(inst);
163
+ }
164
+ return err;
196165 }
197166
198167 static struct crypto_template seqiv_tmpl = {
199168 .name = "seqiv",
200
- .create = seqiv_create,
201
- .free = seqiv_free,
169
+ .create = seqiv_aead_create,
202170 .module = THIS_MODULE,
203171 };
204172
....@@ -212,7 +180,7 @@
212180 crypto_unregister_template(&seqiv_tmpl);
213181 }
214182
215
-module_init(seqiv_module_init);
183
+subsys_initcall(seqiv_module_init);
216184 module_exit(seqiv_module_exit);
217185
218186 MODULE_LICENSE("GPL");