hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/arch/s390/crypto/des_s390.c
....@@ -16,7 +16,8 @@
1616 #include <linux/fips.h>
1717 #include <linux/mutex.h>
1818 #include <crypto/algapi.h>
19
-#include <crypto/des.h>
19
+#include <crypto/internal/des.h>
20
+#include <crypto/internal/skcipher.h>
2021 #include <asm/cpacf.h>
2122
2223 #define DES3_KEY_SIZE (3 * DES_KEY_SIZE)
....@@ -35,27 +36,30 @@
3536 unsigned int key_len)
3637 {
3738 struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
38
- u32 tmp[DES_EXPKEY_WORDS];
39
+ int err;
3940
40
- /* check for weak keys */
41
- if (!des_ekey(tmp, key) &&
42
- (tfm->crt_flags & CRYPTO_TFM_REQ_WEAK_KEY)) {
43
- tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY;
44
- return -EINVAL;
45
- }
41
+ err = crypto_des_verify_key(tfm, key);
42
+ if (err)
43
+ return err;
4644
4745 memcpy(ctx->key, key, key_len);
4846 return 0;
4947 }
5048
51
-static void des_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
49
+static int des_setkey_skcipher(struct crypto_skcipher *tfm, const u8 *key,
50
+ unsigned int key_len)
51
+{
52
+ return des_setkey(crypto_skcipher_tfm(tfm), key, key_len);
53
+}
54
+
55
+static void s390_des_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
5256 {
5357 struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
5458
5559 cpacf_km(CPACF_KM_DEA, ctx->key, out, in, DES_BLOCK_SIZE);
5660 }
5761
58
-static void des_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
62
+static void s390_des_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
5963 {
6064 struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
6165
....@@ -76,34 +80,36 @@
7680 .cia_min_keysize = DES_KEY_SIZE,
7781 .cia_max_keysize = DES_KEY_SIZE,
7882 .cia_setkey = des_setkey,
79
- .cia_encrypt = des_encrypt,
80
- .cia_decrypt = des_decrypt,
83
+ .cia_encrypt = s390_des_encrypt,
84
+ .cia_decrypt = s390_des_decrypt,
8185 }
8286 }
8387 };
8488
85
-static int ecb_desall_crypt(struct blkcipher_desc *desc, unsigned long fc,
86
- struct blkcipher_walk *walk)
89
+static int ecb_desall_crypt(struct skcipher_request *req, unsigned long fc)
8790 {
88
- struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
91
+ struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
92
+ struct s390_des_ctx *ctx = crypto_skcipher_ctx(tfm);
93
+ struct skcipher_walk walk;
8994 unsigned int nbytes, n;
9095 int ret;
9196
92
- ret = blkcipher_walk_virt(desc, walk);
93
- while ((nbytes = walk->nbytes) >= DES_BLOCK_SIZE) {
97
+ ret = skcipher_walk_virt(&walk, req, false);
98
+ while ((nbytes = walk.nbytes) != 0) {
9499 /* only use complete blocks */
95100 n = nbytes & ~(DES_BLOCK_SIZE - 1);
96
- cpacf_km(fc, ctx->key, walk->dst.virt.addr,
97
- walk->src.virt.addr, n);
98
- ret = blkcipher_walk_done(desc, walk, nbytes - n);
101
+ cpacf_km(fc, ctx->key, walk.dst.virt.addr,
102
+ walk.src.virt.addr, n);
103
+ ret = skcipher_walk_done(&walk, nbytes - n);
99104 }
100105 return ret;
101106 }
102107
103
-static int cbc_desall_crypt(struct blkcipher_desc *desc, unsigned long fc,
104
- struct blkcipher_walk *walk)
108
+static int cbc_desall_crypt(struct skcipher_request *req, unsigned long fc)
105109 {
106
- struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
110
+ struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
111
+ struct s390_des_ctx *ctx = crypto_skcipher_ctx(tfm);
112
+ struct skcipher_walk walk;
107113 unsigned int nbytes, n;
108114 int ret;
109115 struct {
....@@ -111,99 +117,69 @@
111117 u8 key[DES3_KEY_SIZE];
112118 } param;
113119
114
- ret = blkcipher_walk_virt(desc, walk);
115
- memcpy(param.iv, walk->iv, DES_BLOCK_SIZE);
120
+ ret = skcipher_walk_virt(&walk, req, false);
121
+ if (ret)
122
+ return ret;
123
+ memcpy(param.iv, walk.iv, DES_BLOCK_SIZE);
116124 memcpy(param.key, ctx->key, DES3_KEY_SIZE);
117
- while ((nbytes = walk->nbytes) >= DES_BLOCK_SIZE) {
125
+ while ((nbytes = walk.nbytes) != 0) {
118126 /* only use complete blocks */
119127 n = nbytes & ~(DES_BLOCK_SIZE - 1);
120
- cpacf_kmc(fc, &param, walk->dst.virt.addr,
121
- walk->src.virt.addr, n);
122
- ret = blkcipher_walk_done(desc, walk, nbytes - n);
128
+ cpacf_kmc(fc, &param, walk.dst.virt.addr,
129
+ walk.src.virt.addr, n);
130
+ memcpy(walk.iv, param.iv, DES_BLOCK_SIZE);
131
+ ret = skcipher_walk_done(&walk, nbytes - n);
123132 }
124
- memcpy(walk->iv, param.iv, DES_BLOCK_SIZE);
125133 return ret;
126134 }
127135
128
-static int ecb_des_encrypt(struct blkcipher_desc *desc,
129
- struct scatterlist *dst, struct scatterlist *src,
130
- unsigned int nbytes)
136
+static int ecb_des_encrypt(struct skcipher_request *req)
131137 {
132
- struct blkcipher_walk walk;
133
-
134
- blkcipher_walk_init(&walk, dst, src, nbytes);
135
- return ecb_desall_crypt(desc, CPACF_KM_DEA, &walk);
138
+ return ecb_desall_crypt(req, CPACF_KM_DEA);
136139 }
137140
138
-static int ecb_des_decrypt(struct blkcipher_desc *desc,
139
- struct scatterlist *dst, struct scatterlist *src,
140
- unsigned int nbytes)
141
+static int ecb_des_decrypt(struct skcipher_request *req)
141142 {
142
- struct blkcipher_walk walk;
143
-
144
- blkcipher_walk_init(&walk, dst, src, nbytes);
145
- return ecb_desall_crypt(desc, CPACF_KM_DEA | CPACF_DECRYPT, &walk);
143
+ return ecb_desall_crypt(req, CPACF_KM_DEA | CPACF_DECRYPT);
146144 }
147145
148
-static struct crypto_alg ecb_des_alg = {
149
- .cra_name = "ecb(des)",
150
- .cra_driver_name = "ecb-des-s390",
151
- .cra_priority = 400, /* combo: des + ecb */
152
- .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
153
- .cra_blocksize = DES_BLOCK_SIZE,
154
- .cra_ctxsize = sizeof(struct s390_des_ctx),
155
- .cra_type = &crypto_blkcipher_type,
156
- .cra_module = THIS_MODULE,
157
- .cra_u = {
158
- .blkcipher = {
159
- .min_keysize = DES_KEY_SIZE,
160
- .max_keysize = DES_KEY_SIZE,
161
- .setkey = des_setkey,
162
- .encrypt = ecb_des_encrypt,
163
- .decrypt = ecb_des_decrypt,
164
- }
165
- }
146
+static struct skcipher_alg ecb_des_alg = {
147
+ .base.cra_name = "ecb(des)",
148
+ .base.cra_driver_name = "ecb-des-s390",
149
+ .base.cra_priority = 400, /* combo: des + ecb */
150
+ .base.cra_blocksize = DES_BLOCK_SIZE,
151
+ .base.cra_ctxsize = sizeof(struct s390_des_ctx),
152
+ .base.cra_module = THIS_MODULE,
153
+ .min_keysize = DES_KEY_SIZE,
154
+ .max_keysize = DES_KEY_SIZE,
155
+ .setkey = des_setkey_skcipher,
156
+ .encrypt = ecb_des_encrypt,
157
+ .decrypt = ecb_des_decrypt,
166158 };
167159
168
-static int cbc_des_encrypt(struct blkcipher_desc *desc,
169
- struct scatterlist *dst, struct scatterlist *src,
170
- unsigned int nbytes)
160
+static int cbc_des_encrypt(struct skcipher_request *req)
171161 {
172
- struct blkcipher_walk walk;
173
-
174
- blkcipher_walk_init(&walk, dst, src, nbytes);
175
- return cbc_desall_crypt(desc, CPACF_KMC_DEA, &walk);
162
+ return cbc_desall_crypt(req, CPACF_KMC_DEA);
176163 }
177164
178
-static int cbc_des_decrypt(struct blkcipher_desc *desc,
179
- struct scatterlist *dst, struct scatterlist *src,
180
- unsigned int nbytes)
165
+static int cbc_des_decrypt(struct skcipher_request *req)
181166 {
182
- struct blkcipher_walk walk;
183
-
184
- blkcipher_walk_init(&walk, dst, src, nbytes);
185
- return cbc_desall_crypt(desc, CPACF_KMC_DEA | CPACF_DECRYPT, &walk);
167
+ return cbc_desall_crypt(req, CPACF_KMC_DEA | CPACF_DECRYPT);
186168 }
187169
188
-static struct crypto_alg cbc_des_alg = {
189
- .cra_name = "cbc(des)",
190
- .cra_driver_name = "cbc-des-s390",
191
- .cra_priority = 400, /* combo: des + cbc */
192
- .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
193
- .cra_blocksize = DES_BLOCK_SIZE,
194
- .cra_ctxsize = sizeof(struct s390_des_ctx),
195
- .cra_type = &crypto_blkcipher_type,
196
- .cra_module = THIS_MODULE,
197
- .cra_u = {
198
- .blkcipher = {
199
- .min_keysize = DES_KEY_SIZE,
200
- .max_keysize = DES_KEY_SIZE,
201
- .ivsize = DES_BLOCK_SIZE,
202
- .setkey = des_setkey,
203
- .encrypt = cbc_des_encrypt,
204
- .decrypt = cbc_des_decrypt,
205
- }
206
- }
170
+static struct skcipher_alg cbc_des_alg = {
171
+ .base.cra_name = "cbc(des)",
172
+ .base.cra_driver_name = "cbc-des-s390",
173
+ .base.cra_priority = 400, /* combo: des + cbc */
174
+ .base.cra_blocksize = DES_BLOCK_SIZE,
175
+ .base.cra_ctxsize = sizeof(struct s390_des_ctx),
176
+ .base.cra_module = THIS_MODULE,
177
+ .min_keysize = DES_KEY_SIZE,
178
+ .max_keysize = DES_KEY_SIZE,
179
+ .ivsize = DES_BLOCK_SIZE,
180
+ .setkey = des_setkey_skcipher,
181
+ .encrypt = cbc_des_encrypt,
182
+ .decrypt = cbc_des_decrypt,
207183 };
208184
209185 /*
....@@ -225,27 +201,20 @@
225201 unsigned int key_len)
226202 {
227203 struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
204
+ int err;
228205
229
- if (!(crypto_memneq(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) &&
230
- crypto_memneq(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2],
231
- DES_KEY_SIZE)) &&
232
- (tfm->crt_flags & CRYPTO_TFM_REQ_WEAK_KEY)) {
233
- tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY;
234
- return -EINVAL;
235
- }
236
-
237
- /* in fips mode, ensure k1 != k2 and k2 != k3 and k1 != k3 */
238
- if (fips_enabled &&
239
- !(crypto_memneq(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) &&
240
- crypto_memneq(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2],
241
- DES_KEY_SIZE) &&
242
- crypto_memneq(key, &key[DES_KEY_SIZE * 2], DES_KEY_SIZE))) {
243
- tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY;
244
- return -EINVAL;
245
- }
206
+ err = crypto_des3_ede_verify_key(tfm, key);
207
+ if (err)
208
+ return err;
246209
247210 memcpy(ctx->key, key, key_len);
248211 return 0;
212
+}
213
+
214
+static int des3_setkey_skcipher(struct crypto_skcipher *tfm, const u8 *key,
215
+ unsigned int key_len)
216
+{
217
+ return des3_setkey(crypto_skcipher_tfm(tfm), key, key_len);
249218 }
250219
251220 static void des3_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
....@@ -282,87 +251,53 @@
282251 }
283252 };
284253
285
-static int ecb_des3_encrypt(struct blkcipher_desc *desc,
286
- struct scatterlist *dst, struct scatterlist *src,
287
- unsigned int nbytes)
254
+static int ecb_des3_encrypt(struct skcipher_request *req)
288255 {
289
- struct blkcipher_walk walk;
290
-
291
- blkcipher_walk_init(&walk, dst, src, nbytes);
292
- return ecb_desall_crypt(desc, CPACF_KM_TDEA_192, &walk);
256
+ return ecb_desall_crypt(req, CPACF_KM_TDEA_192);
293257 }
294258
295
-static int ecb_des3_decrypt(struct blkcipher_desc *desc,
296
- struct scatterlist *dst, struct scatterlist *src,
297
- unsigned int nbytes)
259
+static int ecb_des3_decrypt(struct skcipher_request *req)
298260 {
299
- struct blkcipher_walk walk;
300
-
301
- blkcipher_walk_init(&walk, dst, src, nbytes);
302
- return ecb_desall_crypt(desc, CPACF_KM_TDEA_192 | CPACF_DECRYPT,
303
- &walk);
261
+ return ecb_desall_crypt(req, CPACF_KM_TDEA_192 | CPACF_DECRYPT);
304262 }
305263
306
-static struct crypto_alg ecb_des3_alg = {
307
- .cra_name = "ecb(des3_ede)",
308
- .cra_driver_name = "ecb-des3_ede-s390",
309
- .cra_priority = 400, /* combo: des3 + ecb */
310
- .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
311
- .cra_blocksize = DES_BLOCK_SIZE,
312
- .cra_ctxsize = sizeof(struct s390_des_ctx),
313
- .cra_type = &crypto_blkcipher_type,
314
- .cra_module = THIS_MODULE,
315
- .cra_u = {
316
- .blkcipher = {
317
- .min_keysize = DES3_KEY_SIZE,
318
- .max_keysize = DES3_KEY_SIZE,
319
- .setkey = des3_setkey,
320
- .encrypt = ecb_des3_encrypt,
321
- .decrypt = ecb_des3_decrypt,
322
- }
323
- }
264
+static struct skcipher_alg ecb_des3_alg = {
265
+ .base.cra_name = "ecb(des3_ede)",
266
+ .base.cra_driver_name = "ecb-des3_ede-s390",
267
+ .base.cra_priority = 400, /* combo: des3 + ecb */
268
+ .base.cra_blocksize = DES_BLOCK_SIZE,
269
+ .base.cra_ctxsize = sizeof(struct s390_des_ctx),
270
+ .base.cra_module = THIS_MODULE,
271
+ .min_keysize = DES3_KEY_SIZE,
272
+ .max_keysize = DES3_KEY_SIZE,
273
+ .setkey = des3_setkey_skcipher,
274
+ .encrypt = ecb_des3_encrypt,
275
+ .decrypt = ecb_des3_decrypt,
324276 };
325277
326
-static int cbc_des3_encrypt(struct blkcipher_desc *desc,
327
- struct scatterlist *dst, struct scatterlist *src,
328
- unsigned int nbytes)
278
+static int cbc_des3_encrypt(struct skcipher_request *req)
329279 {
330
- struct blkcipher_walk walk;
331
-
332
- blkcipher_walk_init(&walk, dst, src, nbytes);
333
- return cbc_desall_crypt(desc, CPACF_KMC_TDEA_192, &walk);
280
+ return cbc_desall_crypt(req, CPACF_KMC_TDEA_192);
334281 }
335282
336
-static int cbc_des3_decrypt(struct blkcipher_desc *desc,
337
- struct scatterlist *dst, struct scatterlist *src,
338
- unsigned int nbytes)
283
+static int cbc_des3_decrypt(struct skcipher_request *req)
339284 {
340
- struct blkcipher_walk walk;
341
-
342
- blkcipher_walk_init(&walk, dst, src, nbytes);
343
- return cbc_desall_crypt(desc, CPACF_KMC_TDEA_192 | CPACF_DECRYPT,
344
- &walk);
285
+ return cbc_desall_crypt(req, CPACF_KMC_TDEA_192 | CPACF_DECRYPT);
345286 }
346287
347
-static struct crypto_alg cbc_des3_alg = {
348
- .cra_name = "cbc(des3_ede)",
349
- .cra_driver_name = "cbc-des3_ede-s390",
350
- .cra_priority = 400, /* combo: des3 + cbc */
351
- .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
352
- .cra_blocksize = DES_BLOCK_SIZE,
353
- .cra_ctxsize = sizeof(struct s390_des_ctx),
354
- .cra_type = &crypto_blkcipher_type,
355
- .cra_module = THIS_MODULE,
356
- .cra_u = {
357
- .blkcipher = {
358
- .min_keysize = DES3_KEY_SIZE,
359
- .max_keysize = DES3_KEY_SIZE,
360
- .ivsize = DES_BLOCK_SIZE,
361
- .setkey = des3_setkey,
362
- .encrypt = cbc_des3_encrypt,
363
- .decrypt = cbc_des3_decrypt,
364
- }
365
- }
288
+static struct skcipher_alg cbc_des3_alg = {
289
+ .base.cra_name = "cbc(des3_ede)",
290
+ .base.cra_driver_name = "cbc-des3_ede-s390",
291
+ .base.cra_priority = 400, /* combo: des3 + cbc */
292
+ .base.cra_blocksize = DES_BLOCK_SIZE,
293
+ .base.cra_ctxsize = sizeof(struct s390_des_ctx),
294
+ .base.cra_module = THIS_MODULE,
295
+ .min_keysize = DES3_KEY_SIZE,
296
+ .max_keysize = DES3_KEY_SIZE,
297
+ .ivsize = DES_BLOCK_SIZE,
298
+ .setkey = des3_setkey_skcipher,
299
+ .encrypt = cbc_des3_encrypt,
300
+ .decrypt = cbc_des3_decrypt,
366301 };
367302
368303 static unsigned int __ctrblk_init(u8 *ctrptr, u8 *iv, unsigned int nbytes)
....@@ -380,128 +315,90 @@
380315 return n;
381316 }
382317
383
-static int ctr_desall_crypt(struct blkcipher_desc *desc, unsigned long fc,
384
- struct blkcipher_walk *walk)
318
+static int ctr_desall_crypt(struct skcipher_request *req, unsigned long fc)
385319 {
386
- struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
320
+ struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
321
+ struct s390_des_ctx *ctx = crypto_skcipher_ctx(tfm);
387322 u8 buf[DES_BLOCK_SIZE], *ctrptr;
323
+ struct skcipher_walk walk;
388324 unsigned int n, nbytes;
389325 int ret, locked;
390326
391327 locked = mutex_trylock(&ctrblk_lock);
392328
393
- ret = blkcipher_walk_virt_block(desc, walk, DES_BLOCK_SIZE);
394
- while ((nbytes = walk->nbytes) >= DES_BLOCK_SIZE) {
329
+ ret = skcipher_walk_virt(&walk, req, false);
330
+ while ((nbytes = walk.nbytes) >= DES_BLOCK_SIZE) {
395331 n = DES_BLOCK_SIZE;
396332 if (nbytes >= 2*DES_BLOCK_SIZE && locked)
397
- n = __ctrblk_init(ctrblk, walk->iv, nbytes);
398
- ctrptr = (n > DES_BLOCK_SIZE) ? ctrblk : walk->iv;
399
- cpacf_kmctr(fc, ctx->key, walk->dst.virt.addr,
400
- walk->src.virt.addr, n, ctrptr);
333
+ n = __ctrblk_init(ctrblk, walk.iv, nbytes);
334
+ ctrptr = (n > DES_BLOCK_SIZE) ? ctrblk : walk.iv;
335
+ cpacf_kmctr(fc, ctx->key, walk.dst.virt.addr,
336
+ walk.src.virt.addr, n, ctrptr);
401337 if (ctrptr == ctrblk)
402
- memcpy(walk->iv, ctrptr + n - DES_BLOCK_SIZE,
338
+ memcpy(walk.iv, ctrptr + n - DES_BLOCK_SIZE,
403339 DES_BLOCK_SIZE);
404
- crypto_inc(walk->iv, DES_BLOCK_SIZE);
405
- ret = blkcipher_walk_done(desc, walk, nbytes - n);
340
+ crypto_inc(walk.iv, DES_BLOCK_SIZE);
341
+ ret = skcipher_walk_done(&walk, nbytes - n);
406342 }
407343 if (locked)
408344 mutex_unlock(&ctrblk_lock);
409345 /* final block may be < DES_BLOCK_SIZE, copy only nbytes */
410346 if (nbytes) {
411
- cpacf_kmctr(fc, ctx->key, buf, walk->src.virt.addr,
412
- DES_BLOCK_SIZE, walk->iv);
413
- memcpy(walk->dst.virt.addr, buf, nbytes);
414
- crypto_inc(walk->iv, DES_BLOCK_SIZE);
415
- ret = blkcipher_walk_done(desc, walk, 0);
347
+ cpacf_kmctr(fc, ctx->key, buf, walk.src.virt.addr,
348
+ DES_BLOCK_SIZE, walk.iv);
349
+ memcpy(walk.dst.virt.addr, buf, nbytes);
350
+ crypto_inc(walk.iv, DES_BLOCK_SIZE);
351
+ ret = skcipher_walk_done(&walk, 0);
416352 }
417353 return ret;
418354 }
419355
420
-static int ctr_des_encrypt(struct blkcipher_desc *desc,
421
- struct scatterlist *dst, struct scatterlist *src,
422
- unsigned int nbytes)
356
+static int ctr_des_crypt(struct skcipher_request *req)
423357 {
424
- struct blkcipher_walk walk;
425
-
426
- blkcipher_walk_init(&walk, dst, src, nbytes);
427
- return ctr_desall_crypt(desc, CPACF_KMCTR_DEA, &walk);
358
+ return ctr_desall_crypt(req, CPACF_KMCTR_DEA);
428359 }
429360
430
-static int ctr_des_decrypt(struct blkcipher_desc *desc,
431
- struct scatterlist *dst, struct scatterlist *src,
432
- unsigned int nbytes)
433
-{
434
- struct blkcipher_walk walk;
435
-
436
- blkcipher_walk_init(&walk, dst, src, nbytes);
437
- return ctr_desall_crypt(desc, CPACF_KMCTR_DEA | CPACF_DECRYPT, &walk);
438
-}
439
-
440
-static struct crypto_alg ctr_des_alg = {
441
- .cra_name = "ctr(des)",
442
- .cra_driver_name = "ctr-des-s390",
443
- .cra_priority = 400, /* combo: des + ctr */
444
- .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
445
- .cra_blocksize = 1,
446
- .cra_ctxsize = sizeof(struct s390_des_ctx),
447
- .cra_type = &crypto_blkcipher_type,
448
- .cra_module = THIS_MODULE,
449
- .cra_u = {
450
- .blkcipher = {
451
- .min_keysize = DES_KEY_SIZE,
452
- .max_keysize = DES_KEY_SIZE,
453
- .ivsize = DES_BLOCK_SIZE,
454
- .setkey = des_setkey,
455
- .encrypt = ctr_des_encrypt,
456
- .decrypt = ctr_des_decrypt,
457
- }
458
- }
361
+static struct skcipher_alg ctr_des_alg = {
362
+ .base.cra_name = "ctr(des)",
363
+ .base.cra_driver_name = "ctr-des-s390",
364
+ .base.cra_priority = 400, /* combo: des + ctr */
365
+ .base.cra_blocksize = 1,
366
+ .base.cra_ctxsize = sizeof(struct s390_des_ctx),
367
+ .base.cra_module = THIS_MODULE,
368
+ .min_keysize = DES_KEY_SIZE,
369
+ .max_keysize = DES_KEY_SIZE,
370
+ .ivsize = DES_BLOCK_SIZE,
371
+ .setkey = des_setkey_skcipher,
372
+ .encrypt = ctr_des_crypt,
373
+ .decrypt = ctr_des_crypt,
374
+ .chunksize = DES_BLOCK_SIZE,
459375 };
460376
461
-static int ctr_des3_encrypt(struct blkcipher_desc *desc,
462
- struct scatterlist *dst, struct scatterlist *src,
463
- unsigned int nbytes)
377
+static int ctr_des3_crypt(struct skcipher_request *req)
464378 {
465
- struct blkcipher_walk walk;
466
-
467
- blkcipher_walk_init(&walk, dst, src, nbytes);
468
- return ctr_desall_crypt(desc, CPACF_KMCTR_TDEA_192, &walk);
379
+ return ctr_desall_crypt(req, CPACF_KMCTR_TDEA_192);
469380 }
470381
471
-static int ctr_des3_decrypt(struct blkcipher_desc *desc,
472
- struct scatterlist *dst, struct scatterlist *src,
473
- unsigned int nbytes)
474
-{
475
- struct blkcipher_walk walk;
476
-
477
- blkcipher_walk_init(&walk, dst, src, nbytes);
478
- return ctr_desall_crypt(desc, CPACF_KMCTR_TDEA_192 | CPACF_DECRYPT,
479
- &walk);
480
-}
481
-
482
-static struct crypto_alg ctr_des3_alg = {
483
- .cra_name = "ctr(des3_ede)",
484
- .cra_driver_name = "ctr-des3_ede-s390",
485
- .cra_priority = 400, /* combo: des3 + ede */
486
- .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
487
- .cra_blocksize = 1,
488
- .cra_ctxsize = sizeof(struct s390_des_ctx),
489
- .cra_type = &crypto_blkcipher_type,
490
- .cra_module = THIS_MODULE,
491
- .cra_u = {
492
- .blkcipher = {
493
- .min_keysize = DES3_KEY_SIZE,
494
- .max_keysize = DES3_KEY_SIZE,
495
- .ivsize = DES_BLOCK_SIZE,
496
- .setkey = des3_setkey,
497
- .encrypt = ctr_des3_encrypt,
498
- .decrypt = ctr_des3_decrypt,
499
- }
500
- }
382
+static struct skcipher_alg ctr_des3_alg = {
383
+ .base.cra_name = "ctr(des3_ede)",
384
+ .base.cra_driver_name = "ctr-des3_ede-s390",
385
+ .base.cra_priority = 400, /* combo: des3 + ede */
386
+ .base.cra_blocksize = 1,
387
+ .base.cra_ctxsize = sizeof(struct s390_des_ctx),
388
+ .base.cra_module = THIS_MODULE,
389
+ .min_keysize = DES3_KEY_SIZE,
390
+ .max_keysize = DES3_KEY_SIZE,
391
+ .ivsize = DES_BLOCK_SIZE,
392
+ .setkey = des3_setkey_skcipher,
393
+ .encrypt = ctr_des3_crypt,
394
+ .decrypt = ctr_des3_crypt,
395
+ .chunksize = DES_BLOCK_SIZE,
501396 };
502397
503
-static struct crypto_alg *des_s390_algs_ptr[8];
398
+static struct crypto_alg *des_s390_algs_ptr[2];
504399 static int des_s390_algs_num;
400
+static struct skcipher_alg *des_s390_skciphers_ptr[6];
401
+static int des_s390_skciphers_num;
505402
506403 static int des_s390_register_alg(struct crypto_alg *alg)
507404 {
....@@ -513,10 +410,22 @@
513410 return ret;
514411 }
515412
413
+static int des_s390_register_skcipher(struct skcipher_alg *alg)
414
+{
415
+ int ret;
416
+
417
+ ret = crypto_register_skcipher(alg);
418
+ if (!ret)
419
+ des_s390_skciphers_ptr[des_s390_skciphers_num++] = alg;
420
+ return ret;
421
+}
422
+
516423 static void des_s390_exit(void)
517424 {
518425 while (des_s390_algs_num--)
519426 crypto_unregister_alg(des_s390_algs_ptr[des_s390_algs_num]);
427
+ while (des_s390_skciphers_num--)
428
+ crypto_unregister_skcipher(des_s390_skciphers_ptr[des_s390_skciphers_num]);
520429 if (ctrblk)
521430 free_page((unsigned long) ctrblk);
522431 }
....@@ -534,12 +443,12 @@
534443 ret = des_s390_register_alg(&des_alg);
535444 if (ret)
536445 goto out_err;
537
- ret = des_s390_register_alg(&ecb_des_alg);
446
+ ret = des_s390_register_skcipher(&ecb_des_alg);
538447 if (ret)
539448 goto out_err;
540449 }
541450 if (cpacf_test_func(&kmc_functions, CPACF_KMC_DEA)) {
542
- ret = des_s390_register_alg(&cbc_des_alg);
451
+ ret = des_s390_register_skcipher(&cbc_des_alg);
543452 if (ret)
544453 goto out_err;
545454 }
....@@ -547,12 +456,12 @@
547456 ret = des_s390_register_alg(&des3_alg);
548457 if (ret)
549458 goto out_err;
550
- ret = des_s390_register_alg(&ecb_des3_alg);
459
+ ret = des_s390_register_skcipher(&ecb_des3_alg);
551460 if (ret)
552461 goto out_err;
553462 }
554463 if (cpacf_test_func(&kmc_functions, CPACF_KMC_TDEA_192)) {
555
- ret = des_s390_register_alg(&cbc_des3_alg);
464
+ ret = des_s390_register_skcipher(&cbc_des3_alg);
556465 if (ret)
557466 goto out_err;
558467 }
....@@ -567,12 +476,12 @@
567476 }
568477
569478 if (cpacf_test_func(&kmctr_functions, CPACF_KMCTR_DEA)) {
570
- ret = des_s390_register_alg(&ctr_des_alg);
479
+ ret = des_s390_register_skcipher(&ctr_des_alg);
571480 if (ret)
572481 goto out_err;
573482 }
574483 if (cpacf_test_func(&kmctr_functions, CPACF_KMCTR_TDEA_192)) {
575
- ret = des_s390_register_alg(&ctr_des3_alg);
484
+ ret = des_s390_register_skcipher(&ctr_des3_alg);
576485 if (ret)
577486 goto out_err;
578487 }