summaryrefslogtreecommitdiffstats
path: root/crypto/cts.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2016-07-12 01:17:48 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2016-07-18 05:35:44 -0400
commit0605c41cc53ca13775d202de0de33864a46162ba (patch)
treea80cf9f3d4bfcfa2e3c083ae2646631eb3e60e4b /crypto/cts.c
parent499a66e6b689b13d1a4108bec5d7dcdc829a27a8 (diff)
crypto: cts - Convert to skcipher
This patch converts cts over to the skcipher interface. It also optimises the implementation to use one CBC operation for all but the last block, which is then processed separately. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/cts.c')
-rw-r--r--crypto/cts.c495
1 files changed, 285 insertions, 210 deletions
diff --git a/crypto/cts.c b/crypto/cts.c
index e467ec0acf9f..51976187b2bf 100644
--- a/crypto/cts.c
+++ b/crypto/cts.c
@@ -40,7 +40,7 @@
40 * rfc3962 includes errata information in its Appendix A. 40 * rfc3962 includes errata information in its Appendix A.
41 */ 41 */
42 42
43#include <crypto/algapi.h> 43#include <crypto/internal/skcipher.h>
44#include <linux/err.h> 44#include <linux/err.h>
45#include <linux/init.h> 45#include <linux/init.h>
46#include <linux/kernel.h> 46#include <linux/kernel.h>
@@ -51,289 +51,364 @@
51#include <linux/slab.h> 51#include <linux/slab.h>
52 52
53struct crypto_cts_ctx { 53struct crypto_cts_ctx {
54 struct crypto_blkcipher *child; 54 struct crypto_skcipher *child;
55}; 55};
56 56
57static int crypto_cts_setkey(struct crypto_tfm *parent, const u8 *key, 57struct crypto_cts_reqctx {
58 unsigned int keylen) 58 struct scatterlist sg[2];
59 unsigned offset;
60 struct skcipher_request subreq;
61};
62
63static inline u8 *crypto_cts_reqctx_space(struct skcipher_request *req)
59{ 64{
60 struct crypto_cts_ctx *ctx = crypto_tfm_ctx(parent); 65 struct crypto_cts_reqctx *rctx = skcipher_request_ctx(req);
61 struct crypto_blkcipher *child = ctx->child; 66 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
62 int err; 67 struct crypto_cts_ctx *ctx = crypto_skcipher_ctx(tfm);
68 struct crypto_skcipher *child = ctx->child;
63 69
64 crypto_blkcipher_clear_flags(child, CRYPTO_TFM_REQ_MASK); 70 return PTR_ALIGN((u8 *)(rctx + 1) + crypto_skcipher_reqsize(child),
65 crypto_blkcipher_set_flags(child, crypto_tfm_get_flags(parent) & 71 crypto_skcipher_alignmask(tfm) + 1);
66 CRYPTO_TFM_REQ_MASK);
67 err = crypto_blkcipher_setkey(child, key, keylen);
68 crypto_tfm_set_flags(parent, crypto_blkcipher_get_flags(child) &
69 CRYPTO_TFM_RES_MASK);
70 return err;
71} 72}
72 73
73static int cts_cbc_encrypt(struct crypto_cts_ctx *ctx, 74static int crypto_cts_setkey(struct crypto_skcipher *parent, const u8 *key,
74 struct blkcipher_desc *desc, 75 unsigned int keylen)
75 struct scatterlist *dst,
76 struct scatterlist *src,
77 unsigned int offset,
78 unsigned int nbytes)
79{ 76{
80 int bsize = crypto_blkcipher_blocksize(desc->tfm); 77 struct crypto_cts_ctx *ctx = crypto_skcipher_ctx(parent);
81 u8 tmp[bsize], tmp2[bsize]; 78 struct crypto_skcipher *child = ctx->child;
82 struct blkcipher_desc lcldesc;
83 struct scatterlist sgsrc[1], sgdst[1];
84 int lastn = nbytes - bsize;
85 u8 iv[bsize];
86 u8 s[bsize * 2], d[bsize * 2];
87 int err; 79 int err;
88 80
89 if (lastn < 0) 81 crypto_skcipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
90 return -EINVAL; 82 crypto_skcipher_set_flags(child, crypto_skcipher_get_flags(parent) &
83 CRYPTO_TFM_REQ_MASK);
84 err = crypto_skcipher_setkey(child, key, keylen);
85 crypto_skcipher_set_flags(parent, crypto_skcipher_get_flags(child) &
86 CRYPTO_TFM_RES_MASK);
87 return err;
88}
91 89
92 sg_init_table(sgsrc, 1); 90static void cts_cbc_crypt_done(struct crypto_async_request *areq, int err)
93 sg_init_table(sgdst, 1); 91{
92 struct skcipher_request *req = areq->data;
94 93
95 memset(s, 0, sizeof(s)); 94 if (err == -EINPROGRESS)
96 scatterwalk_map_and_copy(s, src, offset, nbytes, 0); 95 return;
97 96
98 memcpy(iv, desc->info, bsize); 97 skcipher_request_complete(req, err);
98}
99 99
100 lcldesc.tfm = ctx->child; 100static int cts_cbc_encrypt(struct skcipher_request *req)
101 lcldesc.info = iv; 101{
102 lcldesc.flags = desc->flags; 102 struct crypto_cts_reqctx *rctx = skcipher_request_ctx(req);
103 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
104 struct skcipher_request *subreq = &rctx->subreq;
105 int bsize = crypto_skcipher_blocksize(tfm);
106 u8 d[bsize * 2] __attribute__ ((aligned(__alignof__(u32))));
107 struct scatterlist *sg;
108 unsigned int offset;
109 int lastn;
110
111 offset = rctx->offset;
112 lastn = req->cryptlen - offset;
113
114 sg = scatterwalk_ffwd(rctx->sg, req->dst, offset - bsize);
115 scatterwalk_map_and_copy(d + bsize, sg, 0, bsize, 0);
116
117 memset(d, 0, bsize);
118 scatterwalk_map_and_copy(d, req->src, offset, lastn, 0);
119
120 scatterwalk_map_and_copy(d, sg, 0, bsize + lastn, 1);
121 memzero_explicit(d, sizeof(d));
122
123 skcipher_request_set_callback(subreq, req->base.flags &
124 CRYPTO_TFM_REQ_MAY_BACKLOG,
125 cts_cbc_crypt_done, req);
126 skcipher_request_set_crypt(subreq, sg, sg, bsize, req->iv);
127 return crypto_skcipher_encrypt(subreq);
128}
103 129
104 sg_set_buf(&sgsrc[0], s, bsize); 130static void crypto_cts_encrypt_done(struct crypto_async_request *areq, int err)
105 sg_set_buf(&sgdst[0], tmp, bsize); 131{
106 err = crypto_blkcipher_encrypt_iv(&lcldesc, sgdst, sgsrc, bsize); 132 struct skcipher_request *req = areq->data;
107 133
108 memcpy(d + bsize, tmp, lastn); 134 if (err)
135 goto out;
109 136
110 lcldesc.info = tmp; 137 err = cts_cbc_encrypt(req);
138 if (err == -EINPROGRESS ||
139 (err == -EBUSY && req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG))
140 return;
111 141
112 sg_set_buf(&sgsrc[0], s + bsize, bsize); 142out:
113 sg_set_buf(&sgdst[0], tmp2, bsize); 143 skcipher_request_complete(req, err);
114 err = crypto_blkcipher_encrypt_iv(&lcldesc, sgdst, sgsrc, bsize); 144}
115 145
116 memcpy(d, tmp2, bsize); 146static int crypto_cts_encrypt(struct skcipher_request *req)
147{
148 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
149 struct crypto_cts_reqctx *rctx = skcipher_request_ctx(req);
150 struct crypto_cts_ctx *ctx = crypto_skcipher_ctx(tfm);
151 struct skcipher_request *subreq = &rctx->subreq;
152 int bsize = crypto_skcipher_blocksize(tfm);
153 unsigned int nbytes = req->cryptlen;
154 int cbc_blocks = (nbytes + bsize - 1) / bsize - 1;
155 unsigned int offset;
156
157 skcipher_request_set_tfm(subreq, ctx->child);
158
159 if (cbc_blocks <= 0) {
160 skcipher_request_set_callback(subreq, req->base.flags,
161 req->base.complete,
162 req->base.data);
163 skcipher_request_set_crypt(subreq, req->src, req->dst, nbytes,
164 req->iv);
165 return crypto_skcipher_encrypt(subreq);
166 }
117 167
118 scatterwalk_map_and_copy(d, dst, offset, nbytes, 1); 168 offset = cbc_blocks * bsize;
169 rctx->offset = offset;
119 170
120 memcpy(desc->info, tmp2, bsize); 171 skcipher_request_set_callback(subreq, req->base.flags,
172 crypto_cts_encrypt_done, req);
173 skcipher_request_set_crypt(subreq, req->src, req->dst,
174 offset, req->iv);
121 175
122 return err; 176 return crypto_skcipher_encrypt(subreq) ?:
177 cts_cbc_encrypt(req);
123} 178}
124 179
125static int crypto_cts_encrypt(struct blkcipher_desc *desc, 180static int cts_cbc_decrypt(struct skcipher_request *req)
126 struct scatterlist *dst, struct scatterlist *src,
127 unsigned int nbytes)
128{ 181{
129 struct crypto_cts_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); 182 struct crypto_cts_reqctx *rctx = skcipher_request_ctx(req);
130 int bsize = crypto_blkcipher_blocksize(desc->tfm); 183 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
131 int tot_blocks = (nbytes + bsize - 1) / bsize; 184 struct skcipher_request *subreq = &rctx->subreq;
132 int cbc_blocks = tot_blocks > 2 ? tot_blocks - 2 : 0; 185 int bsize = crypto_skcipher_blocksize(tfm);
133 struct blkcipher_desc lcldesc; 186 u8 d[bsize * 2] __attribute__ ((aligned(__alignof__(u32))));
134 int err; 187 struct scatterlist *sg;
188 unsigned int offset;
189 u8 *space;
190 int lastn;
191
192 offset = rctx->offset;
193 lastn = req->cryptlen - offset;
194
195 sg = scatterwalk_ffwd(rctx->sg, req->dst, offset - bsize);
196
197 /* 1. Decrypt Cn-1 (s) to create Dn */
198 scatterwalk_map_and_copy(d + bsize, sg, 0, bsize, 0);
199 space = crypto_cts_reqctx_space(req);
200 crypto_xor(d + bsize, space, bsize);
201 /* 2. Pad Cn with zeros at the end to create C of length BB */
202 memset(d, 0, bsize);
203 scatterwalk_map_and_copy(d, req->src, offset, lastn, 0);
204 /* 3. Exclusive-or Dn with C to create Xn */
205 /* 4. Select the first Ln bytes of Xn to create Pn */
206 crypto_xor(d + bsize, d, lastn);
207
208 /* 5. Append the tail (BB - Ln) bytes of Xn to Cn to create En */
209 memcpy(d + lastn, d + bsize + lastn, bsize - lastn);
210 /* 6. Decrypt En to create Pn-1 */
135 211
136 lcldesc.tfm = ctx->child; 212 scatterwalk_map_and_copy(d, sg, 0, bsize + lastn, 1);
137 lcldesc.info = desc->info; 213 memzero_explicit(d, sizeof(d));
138 lcldesc.flags = desc->flags;
139
140 if (tot_blocks == 1) {
141 err = crypto_blkcipher_encrypt_iv(&lcldesc, dst, src, bsize);
142 } else if (nbytes <= bsize * 2) {
143 err = cts_cbc_encrypt(ctx, desc, dst, src, 0, nbytes);
144 } else {
145 /* do normal function for tot_blocks - 2 */
146 err = crypto_blkcipher_encrypt_iv(&lcldesc, dst, src,
147 cbc_blocks * bsize);
148 if (err == 0) {
149 /* do cts for final two blocks */
150 err = cts_cbc_encrypt(ctx, desc, dst, src,
151 cbc_blocks * bsize,
152 nbytes - (cbc_blocks * bsize));
153 }
154 }
155 214
156 return err; 215 skcipher_request_set_callback(subreq, req->base.flags &
216 CRYPTO_TFM_REQ_MAY_BACKLOG,
217 cts_cbc_crypt_done, req);
218
219 skcipher_request_set_crypt(subreq, sg, sg, bsize, space);
220 return crypto_skcipher_decrypt(subreq);
157} 221}
158 222
159static int cts_cbc_decrypt(struct crypto_cts_ctx *ctx, 223static void crypto_cts_decrypt_done(struct crypto_async_request *areq, int err)
160 struct blkcipher_desc *desc,
161 struct scatterlist *dst,
162 struct scatterlist *src,
163 unsigned int offset,
164 unsigned int nbytes)
165{ 224{
166 int bsize = crypto_blkcipher_blocksize(desc->tfm); 225 struct skcipher_request *req = areq->data;
167 u8 tmp[bsize];
168 struct blkcipher_desc lcldesc;
169 struct scatterlist sgsrc[1], sgdst[1];
170 int lastn = nbytes - bsize;
171 u8 iv[bsize];
172 u8 s[bsize * 2], d[bsize * 2];
173 int err;
174
175 if (lastn < 0)
176 return -EINVAL;
177 226
178 sg_init_table(sgsrc, 1); 227 if (err)
179 sg_init_table(sgdst, 1); 228 goto out;
180 229
181 scatterwalk_map_and_copy(s, src, offset, nbytes, 0); 230 err = cts_cbc_decrypt(req);
231 if (err == -EINPROGRESS ||
232 (err == -EBUSY && req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG))
233 return;
182 234
183 lcldesc.tfm = ctx->child; 235out:
184 lcldesc.info = iv; 236 skcipher_request_complete(req, err);
185 lcldesc.flags = desc->flags; 237}
186 238
187 /* 1. Decrypt Cn-1 (s) to create Dn (tmp)*/ 239static int crypto_cts_decrypt(struct skcipher_request *req)
188 memset(iv, 0, sizeof(iv)); 240{
189 sg_set_buf(&sgsrc[0], s, bsize); 241 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
190 sg_set_buf(&sgdst[0], tmp, bsize); 242 struct crypto_cts_reqctx *rctx = skcipher_request_ctx(req);
191 err = crypto_blkcipher_decrypt_iv(&lcldesc, sgdst, sgsrc, bsize); 243 struct crypto_cts_ctx *ctx = crypto_skcipher_ctx(tfm);
192 if (err) 244 struct skcipher_request *subreq = &rctx->subreq;
193 return err; 245 int bsize = crypto_skcipher_blocksize(tfm);
194 /* 2. Pad Cn with zeros at the end to create C of length BB */ 246 unsigned int nbytes = req->cryptlen;
195 memset(iv, 0, sizeof(iv)); 247 int cbc_blocks = (nbytes + bsize - 1) / bsize - 1;
196 memcpy(iv, s + bsize, lastn); 248 unsigned int offset;
197 /* 3. Exclusive-or Dn (tmp) with C (iv) to create Xn (tmp) */ 249 u8 *space;
198 crypto_xor(tmp, iv, bsize); 250
199 /* 4. Select the first Ln bytes of Xn (tmp) to create Pn */ 251 skcipher_request_set_tfm(subreq, ctx->child);
200 memcpy(d + bsize, tmp, lastn); 252
201 253 if (cbc_blocks <= 0) {
202 /* 5. Append the tail (BB - Ln) bytes of Xn (tmp) to Cn to create En */ 254 skcipher_request_set_callback(subreq, req->base.flags,
203 memcpy(s + bsize + lastn, tmp + lastn, bsize - lastn); 255 req->base.complete,
204 /* 6. Decrypt En to create Pn-1 */ 256 req->base.data);
205 memzero_explicit(iv, sizeof(iv)); 257 skcipher_request_set_crypt(subreq, req->src, req->dst, nbytes,
258 req->iv);
259 return crypto_skcipher_decrypt(subreq);
260 }
206 261
207 sg_set_buf(&sgsrc[0], s + bsize, bsize); 262 skcipher_request_set_callback(subreq, req->base.flags,
208 sg_set_buf(&sgdst[0], d, bsize); 263 crypto_cts_decrypt_done, req);
209 err = crypto_blkcipher_decrypt_iv(&lcldesc, sgdst, sgsrc, bsize);
210 264
211 /* XOR with previous block */ 265 space = crypto_cts_reqctx_space(req);
212 crypto_xor(d, desc->info, bsize);
213 266
214 scatterwalk_map_and_copy(d, dst, offset, nbytes, 1); 267 offset = cbc_blocks * bsize;
268 rctx->offset = offset;
215 269
216 memcpy(desc->info, s, bsize); 270 if (cbc_blocks <= 1)
217 return err; 271 memcpy(space, req->iv, bsize);
218} 272 else
273 scatterwalk_map_and_copy(space, req->src, offset - 2 * bsize,
274 bsize, 0);
219 275
220static int crypto_cts_decrypt(struct blkcipher_desc *desc, 276 skcipher_request_set_crypt(subreq, req->src, req->dst,
221 struct scatterlist *dst, struct scatterlist *src, 277 offset, req->iv);
222 unsigned int nbytes)
223{
224 struct crypto_cts_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
225 int bsize = crypto_blkcipher_blocksize(desc->tfm);
226 int tot_blocks = (nbytes + bsize - 1) / bsize;
227 int cbc_blocks = tot_blocks > 2 ? tot_blocks - 2 : 0;
228 struct blkcipher_desc lcldesc;
229 int err;
230 278
231 lcldesc.tfm = ctx->child; 279 return crypto_skcipher_decrypt(subreq) ?:
232 lcldesc.info = desc->info; 280 cts_cbc_decrypt(req);
233 lcldesc.flags = desc->flags;
234
235 if (tot_blocks == 1) {
236 err = crypto_blkcipher_decrypt_iv(&lcldesc, dst, src, bsize);
237 } else if (nbytes <= bsize * 2) {
238 err = cts_cbc_decrypt(ctx, desc, dst, src, 0, nbytes);
239 } else {
240 /* do normal function for tot_blocks - 2 */
241 err = crypto_blkcipher_decrypt_iv(&lcldesc, dst, src,
242 cbc_blocks * bsize);
243 if (err == 0) {
244 /* do cts for final two blocks */
245 err = cts_cbc_decrypt(ctx, desc, dst, src,
246 cbc_blocks * bsize,
247 nbytes - (cbc_blocks * bsize));
248 }
249 }
250 return err;
251} 281}
252 282
253static int crypto_cts_init_tfm(struct crypto_tfm *tfm) 283static int crypto_cts_init_tfm(struct crypto_skcipher *tfm)
254{ 284{
255 struct crypto_instance *inst = (void *)tfm->__crt_alg; 285 struct skcipher_instance *inst = skcipher_alg_instance(tfm);
256 struct crypto_spawn *spawn = crypto_instance_ctx(inst); 286 struct crypto_skcipher_spawn *spawn = skcipher_instance_ctx(inst);
257 struct crypto_cts_ctx *ctx = crypto_tfm_ctx(tfm); 287 struct crypto_cts_ctx *ctx = crypto_skcipher_ctx(tfm);
258 struct crypto_blkcipher *cipher; 288 struct crypto_skcipher *cipher;
259 289 unsigned reqsize;
260 cipher = crypto_spawn_blkcipher(spawn); 290 unsigned bsize;
291 unsigned align;
292
293 cipher = crypto_spawn_skcipher2(spawn);
261 if (IS_ERR(cipher)) 294 if (IS_ERR(cipher))
262 return PTR_ERR(cipher); 295 return PTR_ERR(cipher);
263 296
264 ctx->child = cipher; 297 ctx->child = cipher;
298
299 align = crypto_skcipher_alignmask(tfm);
300 bsize = crypto_skcipher_blocksize(cipher);
301 reqsize = ALIGN(sizeof(struct crypto_cts_reqctx) +
302 crypto_skcipher_reqsize(cipher),
303 crypto_tfm_ctx_alignment()) +
304 (align & ~(crypto_tfm_ctx_alignment() - 1)) + bsize;
305
306 crypto_skcipher_set_reqsize(tfm, reqsize);
307
265 return 0; 308 return 0;
266} 309}
267 310
268static void crypto_cts_exit_tfm(struct crypto_tfm *tfm) 311static void crypto_cts_exit_tfm(struct crypto_skcipher *tfm)
269{ 312{
270 struct crypto_cts_ctx *ctx = crypto_tfm_ctx(tfm); 313 struct crypto_cts_ctx *ctx = crypto_skcipher_ctx(tfm);
271 crypto_free_blkcipher(ctx->child); 314
315 crypto_free_skcipher(ctx->child);
272} 316}
273 317
274static struct crypto_instance *crypto_cts_alloc(struct rtattr **tb) 318static void crypto_cts_free(struct skcipher_instance *inst)
275{ 319{
276 struct crypto_instance *inst; 320 crypto_drop_skcipher(skcipher_instance_ctx(inst));
277 struct crypto_alg *alg; 321 kfree(inst);
322}
323
324static int crypto_cts_create(struct crypto_template *tmpl, struct rtattr **tb)
325{
326 struct crypto_skcipher_spawn *spawn;
327 struct skcipher_instance *inst;
328 struct crypto_attr_type *algt;
329 struct skcipher_alg *alg;
330 const char *cipher_name;
278 int err; 331 int err;
279 332
280 err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_BLKCIPHER); 333 algt = crypto_get_attr_type(tb);
334 if (IS_ERR(algt))
335 return PTR_ERR(algt);
336
337 if ((algt->type ^ CRYPTO_ALG_TYPE_SKCIPHER) & algt->mask)
338 return -EINVAL;
339
340 cipher_name = crypto_attr_alg_name(tb[1]);
341 if (IS_ERR(cipher_name))
342 return PTR_ERR(cipher_name);
343
344 inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
345 if (!inst)
346 return -ENOMEM;
347
348 spawn = skcipher_instance_ctx(inst);
349
350 crypto_set_skcipher_spawn(spawn, skcipher_crypto_instance(inst));
351 err = crypto_grab_skcipher2(spawn, cipher_name, 0,
352 crypto_requires_sync(algt->type,
353 algt->mask));
281 if (err) 354 if (err)
282 return ERR_PTR(err); 355 goto err_free_inst;
283 356
284 alg = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_BLKCIPHER, 357 alg = crypto_spawn_skcipher_alg(spawn);
285 CRYPTO_ALG_TYPE_MASK);
286 if (IS_ERR(alg))
287 return ERR_CAST(alg);
288 358
289 inst = ERR_PTR(-EINVAL); 359 err = -EINVAL;
290 if (!is_power_of_2(alg->cra_blocksize)) 360 if (crypto_skcipher_alg_ivsize(alg) != alg->base.cra_blocksize)
291 goto out_put_alg; 361 goto err_drop_spawn;
292 362
293 if (strncmp(alg->cra_name, "cbc(", 4)) 363 if (strncmp(alg->base.cra_name, "cbc(", 4))
294 goto out_put_alg; 364 goto err_drop_spawn;
295 365
296 inst = crypto_alloc_instance("cts", alg); 366 err = crypto_inst_setname(skcipher_crypto_instance(inst), "cts",
297 if (IS_ERR(inst)) 367 &alg->base);
298 goto out_put_alg; 368 if (err)
369 goto err_drop_spawn;
299 370
300 inst->alg.cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER; 371 inst->alg.base.cra_flags = alg->base.cra_flags & CRYPTO_ALG_ASYNC;
301 inst->alg.cra_priority = alg->cra_priority; 372 inst->alg.base.cra_priority = alg->base.cra_priority;
302 inst->alg.cra_blocksize = alg->cra_blocksize; 373 inst->alg.base.cra_blocksize = alg->base.cra_blocksize;
303 inst->alg.cra_alignmask = alg->cra_alignmask; 374 inst->alg.base.cra_alignmask = alg->base.cra_alignmask;
304 inst->alg.cra_type = &crypto_blkcipher_type;
305 375
306 /* We access the data as u32s when xoring. */ 376 /* We access the data as u32s when xoring. */
307 inst->alg.cra_alignmask |= __alignof__(u32) - 1; 377 inst->alg.base.cra_alignmask |= __alignof__(u32) - 1;
308 378
309 inst->alg.cra_blkcipher.ivsize = alg->cra_blocksize; 379 inst->alg.ivsize = alg->base.cra_blocksize;
310 inst->alg.cra_blkcipher.min_keysize = alg->cra_blkcipher.min_keysize; 380 inst->alg.chunksize = crypto_skcipher_alg_chunksize(alg);
311 inst->alg.cra_blkcipher.max_keysize = alg->cra_blkcipher.max_keysize; 381 inst->alg.min_keysize = crypto_skcipher_alg_min_keysize(alg);
382 inst->alg.max_keysize = crypto_skcipher_alg_max_keysize(alg);
312 383
313 inst->alg.cra_ctxsize = sizeof(struct crypto_cts_ctx); 384 inst->alg.base.cra_ctxsize = sizeof(struct crypto_cts_ctx);
314 385
315 inst->alg.cra_init = crypto_cts_init_tfm; 386 inst->alg.init = crypto_cts_init_tfm;
316 inst->alg.cra_exit = crypto_cts_exit_tfm; 387 inst->alg.exit = crypto_cts_exit_tfm;
317 388
318 inst->alg.cra_blkcipher.setkey = crypto_cts_setkey; 389 inst->alg.setkey = crypto_cts_setkey;
319 inst->alg.cra_blkcipher.encrypt = crypto_cts_encrypt; 390 inst->alg.encrypt = crypto_cts_encrypt;
320 inst->alg.cra_blkcipher.decrypt = crypto_cts_decrypt; 391 inst->alg.decrypt = crypto_cts_decrypt;
321 392
322out_put_alg: 393 inst->free = crypto_cts_free;
323 crypto_mod_put(alg);
324 return inst;
325}
326 394
327static void crypto_cts_free(struct crypto_instance *inst) 395 err = skcipher_register_instance(tmpl, inst);
328{ 396 if (err)
329 crypto_drop_spawn(crypto_instance_ctx(inst)); 397 goto err_drop_spawn;
398
399out:
400 return err;
401
402err_drop_spawn:
403 crypto_drop_skcipher(spawn);
404err_free_inst:
330 kfree(inst); 405 kfree(inst);
406 goto out;
331} 407}
332 408
333static struct crypto_template crypto_cts_tmpl = { 409static struct crypto_template crypto_cts_tmpl = {
334 .name = "cts", 410 .name = "cts",
335 .alloc = crypto_cts_alloc, 411 .create = crypto_cts_create,
336 .free = crypto_cts_free,
337 .module = THIS_MODULE, 412 .module = THIS_MODULE,
338}; 413};
339 414