seqiv.c (75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37) seqiv.c (0f8f6d86d415f9d88dc0f7847f11d0c52dba1965)
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * seqiv: Sequence Number IV Generator
4 *
5 * This generator generates an IV based on a sequence number by xoring it
6 * with a salt. This algorithm is mainly useful for CTR and similar modes.
7 *
8 * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>

--- 4 unchanged lines hidden (view full) ---

13#include <crypto/skcipher.h>
14#include <linux/err.h>
15#include <linux/init.h>
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/slab.h>
19#include <linux/string.h>
20
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * seqiv: Sequence Number IV Generator
4 *
5 * This generator generates an IV based on a sequence number by xoring it
6 * with a salt. This algorithm is mainly useful for CTR and similar modes.
7 *
8 * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>

--- 4 unchanged lines hidden (view full) ---

13#include <crypto/skcipher.h>
14#include <linux/err.h>
15#include <linux/init.h>
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/slab.h>
19#include <linux/string.h>
20
21static void seqiv_free(struct crypto_instance *inst);
22
23static void seqiv_aead_encrypt_complete2(struct aead_request *req, int err)
24{
25 struct aead_request *subreq = aead_request_ctx(req);
26 struct crypto_aead *geniv;
27
28 if (err == -EINPROGRESS)
29 return;
30

--- 123 unchanged lines hidden (view full) ---

154
155 inst->alg.init = aead_init_geniv;
156 inst->alg.exit = aead_exit_geniv;
157
158 inst->alg.base.cra_ctxsize = sizeof(struct aead_geniv_ctx);
159 inst->alg.base.cra_ctxsize += inst->alg.ivsize;
160
161 err = aead_register_instance(tmpl, inst);
21static void seqiv_aead_encrypt_complete2(struct aead_request *req, int err)
22{
23 struct aead_request *subreq = aead_request_ctx(req);
24 struct crypto_aead *geniv;
25
26 if (err == -EINPROGRESS)
27 return;
28

--- 123 unchanged lines hidden (view full) ---

152
153 inst->alg.init = aead_init_geniv;
154 inst->alg.exit = aead_exit_geniv;
155
156 inst->alg.base.cra_ctxsize = sizeof(struct aead_geniv_ctx);
157 inst->alg.base.cra_ctxsize += inst->alg.ivsize;
158
159 err = aead_register_instance(tmpl, inst);
162 if (err)
163 goto free_inst;
164
165out:
166 return err;
167
160 if (err) {
168free_inst:
161free_inst:
169 aead_geniv_free(inst);
170 goto out;
162 inst->free(inst);
163 }
164 return err;
171}
172
173static int seqiv_create(struct crypto_template *tmpl, struct rtattr **tb)
174{
175 struct crypto_attr_type *algt;
176
177 algt = crypto_get_attr_type(tb);
178 if (IS_ERR(algt))
179 return PTR_ERR(algt);
180
181 if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & CRYPTO_ALG_TYPE_MASK)
182 return -EINVAL;
183
184 return seqiv_aead_create(tmpl, tb);
185}
186
165}
166
167static int seqiv_create(struct crypto_template *tmpl, struct rtattr **tb)
168{
169 struct crypto_attr_type *algt;
170
171 algt = crypto_get_attr_type(tb);
172 if (IS_ERR(algt))
173 return PTR_ERR(algt);
174
175 if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & CRYPTO_ALG_TYPE_MASK)
176 return -EINVAL;
177
178 return seqiv_aead_create(tmpl, tb);
179}
180
187static void seqiv_free(struct crypto_instance *inst)
188{
189 aead_geniv_free(aead_instance(inst));
190}
191
192static struct crypto_template seqiv_tmpl = {
193 .name = "seqiv",
194 .create = seqiv_create,
181static struct crypto_template seqiv_tmpl = {
182 .name = "seqiv",
183 .create = seqiv_create,
195 .free = seqiv_free,
196 .module = THIS_MODULE,
197};
198
199static int __init seqiv_module_init(void)
200{
201 return crypto_register_template(&seqiv_tmpl);
202}
203
204static void __exit seqiv_module_exit(void)
205{
206 crypto_unregister_template(&seqiv_tmpl);
207}
208
209subsys_initcall(seqiv_module_init);
210module_exit(seqiv_module_exit);
211
212MODULE_LICENSE("GPL");
213MODULE_DESCRIPTION("Sequence Number IV Generator");
214MODULE_ALIAS_CRYPTO("seqiv");
184 .module = THIS_MODULE,
185};
186
187static int __init seqiv_module_init(void)
188{
189 return crypto_register_template(&seqiv_tmpl);
190}
191
192static void __exit seqiv_module_exit(void)
193{
194 crypto_unregister_template(&seqiv_tmpl);
195}
196
197subsys_initcall(seqiv_module_init);
198module_exit(seqiv_module_exit);
199
200MODULE_LICENSE("GPL");
201MODULE_DESCRIPTION("Sequence Number IV Generator");
202MODULE_ALIAS_CRYPTO("seqiv");