Blame view

crypto/cts.c 12 KB
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  /*
   * CTS: Cipher Text Stealing mode
   *
   * COPYRIGHT (c) 2008
   * The Regents of the University of Michigan
   * ALL RIGHTS RESERVED
   *
   * Permission is granted to use, copy, create derivative works
   * and redistribute this software and such derivative works
   * for any purpose, so long as the name of The University of
   * Michigan is not used in any advertising or publicity
   * pertaining to the use of distribution of this software
   * without specific, written prior authorization.  If the
   * above copyright notice or any other identification of the
   * University of Michigan is included in any copy of any
   * portion of this software, then the disclaimer below must
   * also be included.
   *
   * THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION
   * FROM THE UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY
   * PURPOSE, AND WITHOUT WARRANTY BY THE UNIVERSITY OF
   * MICHIGAN OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
   * WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
   * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
   * REGENTS OF THE UNIVERSITY OF MICHIGAN SHALL NOT BE LIABLE
   * FOR ANY DAMAGES, INCLUDING SPECIAL, INDIRECT, INCIDENTAL, OR
   * CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM ARISING
   * OUT OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN
   * IF IT HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGES.
   */
  
  /* Derived from various:
   *	Copyright (c) 2006 Herbert Xu <herbert@gondor.apana.org.au>
   */
  
  /*
   * This is the Cipher Text Stealing mode as described by
   * Section 8 of rfc2040 and referenced by rfc3962.
   * rfc3962 includes errata information in its Appendix A.
   */
6650c4de6   Salvatore Mesoraca   crypto: remove se...
42
  #include <crypto/algapi.h>
0605c41cc   Herbert Xu   crypto: cts - Con...
43
  #include <crypto/internal/skcipher.h>
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
44
45
46
47
48
49
50
51
  #include <linux/err.h>
  #include <linux/init.h>
  #include <linux/kernel.h>
  #include <linux/log2.h>
  #include <linux/module.h>
  #include <linux/scatterlist.h>
  #include <crypto/scatterwalk.h>
  #include <linux/slab.h>
d8c34b949   Gideon Israel Dsouza   crypto: Replaced ...
52
  #include <linux/compiler.h>
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
53
54
  
  struct crypto_cts_ctx {
0605c41cc   Herbert Xu   crypto: cts - Con...
55
  	struct crypto_skcipher *child;
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
56
  };
0605c41cc   Herbert Xu   crypto: cts - Con...
57
58
59
60
61
62
63
  struct crypto_cts_reqctx {
  	struct scatterlist sg[2];
  	unsigned offset;
  	struct skcipher_request subreq;
  };
  
  static inline u8 *crypto_cts_reqctx_space(struct skcipher_request *req)
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
64
  {
0605c41cc   Herbert Xu   crypto: cts - Con...
65
66
67
68
  	struct crypto_cts_reqctx *rctx = skcipher_request_ctx(req);
  	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
  	struct crypto_cts_ctx *ctx = crypto_skcipher_ctx(tfm);
  	struct crypto_skcipher *child = ctx->child;
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
69

0605c41cc   Herbert Xu   crypto: cts - Con...
70
71
  	return PTR_ALIGN((u8 *)(rctx + 1) + crypto_skcipher_reqsize(child),
  			 crypto_skcipher_alignmask(tfm) + 1);
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
72
  }
0605c41cc   Herbert Xu   crypto: cts - Con...
73
74
  static int crypto_cts_setkey(struct crypto_skcipher *parent, const u8 *key,
  			     unsigned int keylen)
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
75
  {
0605c41cc   Herbert Xu   crypto: cts - Con...
76
77
  	struct crypto_cts_ctx *ctx = crypto_skcipher_ctx(parent);
  	struct crypto_skcipher *child = ctx->child;
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
78
  	int err;
0605c41cc   Herbert Xu   crypto: cts - Con...
79
80
81
82
83
84
85
86
  	crypto_skcipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
  	crypto_skcipher_set_flags(child, crypto_skcipher_get_flags(parent) &
  					 CRYPTO_TFM_REQ_MASK);
  	err = crypto_skcipher_setkey(child, key, keylen);
  	crypto_skcipher_set_flags(parent, crypto_skcipher_get_flags(child) &
  					  CRYPTO_TFM_RES_MASK);
  	return err;
  }
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
87

0605c41cc   Herbert Xu   crypto: cts - Con...
88
89
90
  static void cts_cbc_crypt_done(struct crypto_async_request *areq, int err)
  {
  	struct skcipher_request *req = areq->data;
c4913c7b7   Alexey Dobriyan   [CRYPTO] cts: Ini...
91

0605c41cc   Herbert Xu   crypto: cts - Con...
92
93
  	if (err == -EINPROGRESS)
  		return;
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
94

0605c41cc   Herbert Xu   crypto: cts - Con...
95
96
  	skcipher_request_complete(req, err);
  }
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
97

0605c41cc   Herbert Xu   crypto: cts - Con...
98
99
100
101
102
103
  static int cts_cbc_encrypt(struct skcipher_request *req)
  {
  	struct crypto_cts_reqctx *rctx = skcipher_request_ctx(req);
  	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
  	struct skcipher_request *subreq = &rctx->subreq;
  	int bsize = crypto_skcipher_blocksize(tfm);
6650c4de6   Salvatore Mesoraca   crypto: remove se...
104
  	u8 d[MAX_CIPHER_BLOCKSIZE * 2] __aligned(__alignof__(u32));
0605c41cc   Herbert Xu   crypto: cts - Con...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
  	struct scatterlist *sg;
  	unsigned int offset;
  	int lastn;
  
  	offset = rctx->offset;
  	lastn = req->cryptlen - offset;
  
  	sg = scatterwalk_ffwd(rctx->sg, req->dst, offset - bsize);
  	scatterwalk_map_and_copy(d + bsize, sg, 0, bsize, 0);
  
  	memset(d, 0, bsize);
  	scatterwalk_map_and_copy(d, req->src, offset, lastn, 0);
  
  	scatterwalk_map_and_copy(d, sg, 0, bsize + lastn, 1);
  	memzero_explicit(d, sizeof(d));
  
  	skcipher_request_set_callback(subreq, req->base.flags &
  					      CRYPTO_TFM_REQ_MAY_BACKLOG,
  				      cts_cbc_crypt_done, req);
  	skcipher_request_set_crypt(subreq, sg, sg, bsize, req->iv);
  	return crypto_skcipher_encrypt(subreq);
  }
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
127

0605c41cc   Herbert Xu   crypto: cts - Con...
128
129
130
  static void crypto_cts_encrypt_done(struct crypto_async_request *areq, int err)
  {
  	struct skcipher_request *req = areq->data;
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
131

0605c41cc   Herbert Xu   crypto: cts - Con...
132
133
  	if (err)
  		goto out;
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
134

0605c41cc   Herbert Xu   crypto: cts - Con...
135
  	err = cts_cbc_encrypt(req);
4e5b0ad58   Gilad Ben-Yossef   crypto: remove re...
136
  	if (err == -EINPROGRESS || err == -EBUSY)
0605c41cc   Herbert Xu   crypto: cts - Con...
137
  		return;
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
138

0605c41cc   Herbert Xu   crypto: cts - Con...
139
140
141
  out:
  	skcipher_request_complete(req, err);
  }
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
142

0605c41cc   Herbert Xu   crypto: cts - Con...
143
144
145
146
147
148
149
150
  static int crypto_cts_encrypt(struct skcipher_request *req)
  {
  	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
  	struct crypto_cts_reqctx *rctx = skcipher_request_ctx(req);
  	struct crypto_cts_ctx *ctx = crypto_skcipher_ctx(tfm);
  	struct skcipher_request *subreq = &rctx->subreq;
  	int bsize = crypto_skcipher_blocksize(tfm);
  	unsigned int nbytes = req->cryptlen;
0605c41cc   Herbert Xu   crypto: cts - Con...
151
152
153
  	unsigned int offset;
  
  	skcipher_request_set_tfm(subreq, ctx->child);
c31a87198   Eric Biggers   crypto: cts - don...
154
155
156
157
  	if (nbytes < bsize)
  		return -EINVAL;
  
  	if (nbytes == bsize) {
0605c41cc   Herbert Xu   crypto: cts - Con...
158
159
160
161
162
163
164
  		skcipher_request_set_callback(subreq, req->base.flags,
  					      req->base.complete,
  					      req->base.data);
  		skcipher_request_set_crypt(subreq, req->src, req->dst, nbytes,
  					   req->iv);
  		return crypto_skcipher_encrypt(subreq);
  	}
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
165

c31a87198   Eric Biggers   crypto: cts - don...
166
  	offset = rounddown(nbytes - 1, bsize);
0605c41cc   Herbert Xu   crypto: cts - Con...
167
  	rctx->offset = offset;
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
168

0605c41cc   Herbert Xu   crypto: cts - Con...
169
170
171
172
  	skcipher_request_set_callback(subreq, req->base.flags,
  				      crypto_cts_encrypt_done, req);
  	skcipher_request_set_crypt(subreq, req->src, req->dst,
  				   offset, req->iv);
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
173

0605c41cc   Herbert Xu   crypto: cts - Con...
174
175
  	return crypto_skcipher_encrypt(subreq) ?:
  	       cts_cbc_encrypt(req);
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
176
  }
0605c41cc   Herbert Xu   crypto: cts - Con...
177
  static int cts_cbc_decrypt(struct skcipher_request *req)
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
178
  {
0605c41cc   Herbert Xu   crypto: cts - Con...
179
180
181
182
  	struct crypto_cts_reqctx *rctx = skcipher_request_ctx(req);
  	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
  	struct skcipher_request *subreq = &rctx->subreq;
  	int bsize = crypto_skcipher_blocksize(tfm);
6650c4de6   Salvatore Mesoraca   crypto: remove se...
183
  	u8 d[MAX_CIPHER_BLOCKSIZE * 2] __aligned(__alignof__(u32));
0605c41cc   Herbert Xu   crypto: cts - Con...
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
  	struct scatterlist *sg;
  	unsigned int offset;
  	u8 *space;
  	int lastn;
  
  	offset = rctx->offset;
  	lastn = req->cryptlen - offset;
  
  	sg = scatterwalk_ffwd(rctx->sg, req->dst, offset - bsize);
  
  	/* 1. Decrypt Cn-1 (s) to create Dn */
  	scatterwalk_map_and_copy(d + bsize, sg, 0, bsize, 0);
  	space = crypto_cts_reqctx_space(req);
  	crypto_xor(d + bsize, space, bsize);
  	/* 2. Pad Cn with zeros at the end to create C of length BB */
  	memset(d, 0, bsize);
  	scatterwalk_map_and_copy(d, req->src, offset, lastn, 0);
  	/* 3. Exclusive-or Dn with C to create Xn */
  	/* 4. Select the first Ln bytes of Xn to create Pn */
  	crypto_xor(d + bsize, d, lastn);
  
  	/* 5. Append the tail (BB - Ln) bytes of Xn to Cn to create En */
  	memcpy(d + lastn, d + bsize + lastn, bsize - lastn);
  	/* 6. Decrypt En to create Pn-1 */
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
208

0605c41cc   Herbert Xu   crypto: cts - Con...
209
210
  	scatterwalk_map_and_copy(d, sg, 0, bsize + lastn, 1);
  	memzero_explicit(d, sizeof(d));
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
211

0605c41cc   Herbert Xu   crypto: cts - Con...
212
213
214
215
216
217
  	skcipher_request_set_callback(subreq, req->base.flags &
  					      CRYPTO_TFM_REQ_MAY_BACKLOG,
  				      cts_cbc_crypt_done, req);
  
  	skcipher_request_set_crypt(subreq, sg, sg, bsize, space);
  	return crypto_skcipher_decrypt(subreq);
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
218
  }
0605c41cc   Herbert Xu   crypto: cts - Con...
219
  static void crypto_cts_decrypt_done(struct crypto_async_request *areq, int err)
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
220
  {
0605c41cc   Herbert Xu   crypto: cts - Con...
221
  	struct skcipher_request *req = areq->data;
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
222

0605c41cc   Herbert Xu   crypto: cts - Con...
223
224
  	if (err)
  		goto out;
c4913c7b7   Alexey Dobriyan   [CRYPTO] cts: Ini...
225

0605c41cc   Herbert Xu   crypto: cts - Con...
226
  	err = cts_cbc_decrypt(req);
4e5b0ad58   Gilad Ben-Yossef   crypto: remove re...
227
  	if (err == -EINPROGRESS || err == -EBUSY)
0605c41cc   Herbert Xu   crypto: cts - Con...
228
  		return;
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
229

0605c41cc   Herbert Xu   crypto: cts - Con...
230
231
232
  out:
  	skcipher_request_complete(req, err);
  }
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
233

0605c41cc   Herbert Xu   crypto: cts - Con...
234
235
236
237
238
239
240
241
  static int crypto_cts_decrypt(struct skcipher_request *req)
  {
  	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
  	struct crypto_cts_reqctx *rctx = skcipher_request_ctx(req);
  	struct crypto_cts_ctx *ctx = crypto_skcipher_ctx(tfm);
  	struct skcipher_request *subreq = &rctx->subreq;
  	int bsize = crypto_skcipher_blocksize(tfm);
  	unsigned int nbytes = req->cryptlen;
0605c41cc   Herbert Xu   crypto: cts - Con...
242
243
244
245
  	unsigned int offset;
  	u8 *space;
  
  	skcipher_request_set_tfm(subreq, ctx->child);
c31a87198   Eric Biggers   crypto: cts - don...
246
247
248
249
  	if (nbytes < bsize)
  		return -EINVAL;
  
  	if (nbytes == bsize) {
0605c41cc   Herbert Xu   crypto: cts - Con...
250
251
252
253
254
255
256
  		skcipher_request_set_callback(subreq, req->base.flags,
  					      req->base.complete,
  					      req->base.data);
  		skcipher_request_set_crypt(subreq, req->src, req->dst, nbytes,
  					   req->iv);
  		return crypto_skcipher_decrypt(subreq);
  	}
7185ad267   Daniel Borkmann   crypto: memzero_e...
257

0605c41cc   Herbert Xu   crypto: cts - Con...
258
259
  	skcipher_request_set_callback(subreq, req->base.flags,
  				      crypto_cts_decrypt_done, req);
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
260

0605c41cc   Herbert Xu   crypto: cts - Con...
261
  	space = crypto_cts_reqctx_space(req);
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
262

c31a87198   Eric Biggers   crypto: cts - don...
263
  	offset = rounddown(nbytes - 1, bsize);
0605c41cc   Herbert Xu   crypto: cts - Con...
264
  	rctx->offset = offset;
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
265

c31a87198   Eric Biggers   crypto: cts - don...
266
  	if (offset <= bsize)
0605c41cc   Herbert Xu   crypto: cts - Con...
267
268
269
270
  		memcpy(space, req->iv, bsize);
  	else
  		scatterwalk_map_and_copy(space, req->src, offset - 2 * bsize,
  					 bsize, 0);
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
271

0605c41cc   Herbert Xu   crypto: cts - Con...
272
273
  	skcipher_request_set_crypt(subreq, req->src, req->dst,
  				   offset, req->iv);
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
274

0605c41cc   Herbert Xu   crypto: cts - Con...
275
276
  	return crypto_skcipher_decrypt(subreq) ?:
  	       cts_cbc_decrypt(req);
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
277
  }
0605c41cc   Herbert Xu   crypto: cts - Con...
278
  static int crypto_cts_init_tfm(struct crypto_skcipher *tfm)
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
279
  {
0605c41cc   Herbert Xu   crypto: cts - Con...
280
281
282
283
284
285
286
  	struct skcipher_instance *inst = skcipher_alg_instance(tfm);
  	struct crypto_skcipher_spawn *spawn = skcipher_instance_ctx(inst);
  	struct crypto_cts_ctx *ctx = crypto_skcipher_ctx(tfm);
  	struct crypto_skcipher *cipher;
  	unsigned reqsize;
  	unsigned bsize;
  	unsigned align;
60425a8ba   Eric Biggers   crypto: skcipher ...
287
  	cipher = crypto_spawn_skcipher(spawn);
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
288
289
290
291
  	if (IS_ERR(cipher))
  		return PTR_ERR(cipher);
  
  	ctx->child = cipher;
0605c41cc   Herbert Xu   crypto: cts - Con...
292
293
294
295
296
297
298
299
300
  
  	align = crypto_skcipher_alignmask(tfm);
  	bsize = crypto_skcipher_blocksize(cipher);
  	reqsize = ALIGN(sizeof(struct crypto_cts_reqctx) +
  			crypto_skcipher_reqsize(cipher),
  			crypto_tfm_ctx_alignment()) +
  		  (align & ~(crypto_tfm_ctx_alignment() - 1)) + bsize;
  
  	crypto_skcipher_set_reqsize(tfm, reqsize);
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
301
302
  	return 0;
  }
0605c41cc   Herbert Xu   crypto: cts - Con...
303
  static void crypto_cts_exit_tfm(struct crypto_skcipher *tfm)
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
304
  {
0605c41cc   Herbert Xu   crypto: cts - Con...
305
306
307
  	struct crypto_cts_ctx *ctx = crypto_skcipher_ctx(tfm);
  
  	crypto_free_skcipher(ctx->child);
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
308
  }
0605c41cc   Herbert Xu   crypto: cts - Con...
309
  static void crypto_cts_free(struct skcipher_instance *inst)
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
310
  {
0605c41cc   Herbert Xu   crypto: cts - Con...
311
312
313
314
315
316
317
318
319
320
321
  	crypto_drop_skcipher(skcipher_instance_ctx(inst));
  	kfree(inst);
  }
  
  static int crypto_cts_create(struct crypto_template *tmpl, struct rtattr **tb)
  {
  	struct crypto_skcipher_spawn *spawn;
  	struct skcipher_instance *inst;
  	struct crypto_attr_type *algt;
  	struct skcipher_alg *alg;
  	const char *cipher_name;
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
322
  	int err;
0605c41cc   Herbert Xu   crypto: cts - Con...
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
  	algt = crypto_get_attr_type(tb);
  	if (IS_ERR(algt))
  		return PTR_ERR(algt);
  
  	if ((algt->type ^ CRYPTO_ALG_TYPE_SKCIPHER) & algt->mask)
  		return -EINVAL;
  
  	cipher_name = crypto_attr_alg_name(tb[1]);
  	if (IS_ERR(cipher_name))
  		return PTR_ERR(cipher_name);
  
  	inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
  	if (!inst)
  		return -ENOMEM;
  
  	spawn = skcipher_instance_ctx(inst);
  
  	crypto_set_skcipher_spawn(spawn, skcipher_crypto_instance(inst));
a35528eca   Eric Biggers   crypto: skcipher ...
341
342
343
  	err = crypto_grab_skcipher(spawn, cipher_name, 0,
  				   crypto_requires_sync(algt->type,
  							algt->mask));
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
344
  	if (err)
0605c41cc   Herbert Xu   crypto: cts - Con...
345
  		goto err_free_inst;
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
346

0605c41cc   Herbert Xu   crypto: cts - Con...
347
  	alg = crypto_spawn_skcipher_alg(spawn);
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
348

0605c41cc   Herbert Xu   crypto: cts - Con...
349
350
351
  	err = -EINVAL;
  	if (crypto_skcipher_alg_ivsize(alg) != alg->base.cra_blocksize)
  		goto err_drop_spawn;
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
352

0605c41cc   Herbert Xu   crypto: cts - Con...
353
354
  	if (strncmp(alg->base.cra_name, "cbc(", 4))
  		goto err_drop_spawn;
988dc0174   Herbert Xu   crypto: cts - Wee...
355

0605c41cc   Herbert Xu   crypto: cts - Con...
356
357
358
359
  	err = crypto_inst_setname(skcipher_crypto_instance(inst), "cts",
  				  &alg->base);
  	if (err)
  		goto err_drop_spawn;
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
360

0605c41cc   Herbert Xu   crypto: cts - Con...
361
362
363
364
  	inst->alg.base.cra_flags = alg->base.cra_flags & CRYPTO_ALG_ASYNC;
  	inst->alg.base.cra_priority = alg->base.cra_priority;
  	inst->alg.base.cra_blocksize = alg->base.cra_blocksize;
  	inst->alg.base.cra_alignmask = alg->base.cra_alignmask;
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
365

0605c41cc   Herbert Xu   crypto: cts - Con...
366
367
368
369
  	inst->alg.ivsize = alg->base.cra_blocksize;
  	inst->alg.chunksize = crypto_skcipher_alg_chunksize(alg);
  	inst->alg.min_keysize = crypto_skcipher_alg_min_keysize(alg);
  	inst->alg.max_keysize = crypto_skcipher_alg_max_keysize(alg);
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
370

0605c41cc   Herbert Xu   crypto: cts - Con...
371
  	inst->alg.base.cra_ctxsize = sizeof(struct crypto_cts_ctx);
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
372

0605c41cc   Herbert Xu   crypto: cts - Con...
373
374
  	inst->alg.init = crypto_cts_init_tfm;
  	inst->alg.exit = crypto_cts_exit_tfm;
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
375

0605c41cc   Herbert Xu   crypto: cts - Con...
376
377
378
  	inst->alg.setkey = crypto_cts_setkey;
  	inst->alg.encrypt = crypto_cts_encrypt;
  	inst->alg.decrypt = crypto_cts_decrypt;
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
379

0605c41cc   Herbert Xu   crypto: cts - Con...
380
  	inst->free = crypto_cts_free;
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
381

0605c41cc   Herbert Xu   crypto: cts - Con...
382
383
384
385
386
387
388
389
390
391
  	err = skcipher_register_instance(tmpl, inst);
  	if (err)
  		goto err_drop_spawn;
  
  out:
  	return err;
  
  err_drop_spawn:
  	crypto_drop_skcipher(spawn);
  err_free_inst:
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
392
  	kfree(inst);
0605c41cc   Herbert Xu   crypto: cts - Con...
393
  	goto out;
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
394
395
396
397
  }
  
  static struct crypto_template crypto_cts_tmpl = {
  	.name = "cts",
0605c41cc   Herbert Xu   crypto: cts - Con...
398
  	.create = crypto_cts_create,
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
399
400
401
402
403
404
405
406
407
408
409
410
  	.module = THIS_MODULE,
  };
  
  static int __init crypto_cts_module_init(void)
  {
  	return crypto_register_template(&crypto_cts_tmpl);
  }
  
  static void __exit crypto_cts_module_exit(void)
  {
  	crypto_unregister_template(&crypto_cts_tmpl);
  }
c4741b230   Eric Biggers   crypto: run initc...
411
  subsys_initcall(crypto_cts_module_init);
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
412
413
414
415
  module_exit(crypto_cts_module_exit);
  
  MODULE_LICENSE("Dual BSD/GPL");
  MODULE_DESCRIPTION("CTS-CBC CipherText Stealing for CBC");
4943ba16b   Kees Cook   crypto: include c...
416
  MODULE_ALIAS_CRYPTO("cts");