GNU Linux-libre 4.19.281-gnu1
[releases.git] / arch / s390 / crypto / des_s390.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Cryptographic API.
4  *
5  * s390 implementation of the DES Cipher Algorithm.
6  *
7  * Copyright IBM Corp. 2003, 2011
8  * Author(s): Thomas Spatzier
9  *            Jan Glauber (jan.glauber@de.ibm.com)
10  */
11
12 #include <linux/init.h>
13 #include <linux/module.h>
14 #include <linux/cpufeature.h>
15 #include <linux/crypto.h>
16 #include <linux/fips.h>
17 #include <linux/mutex.h>
18 #include <crypto/algapi.h>
19 #include <crypto/des.h>
20 #include <asm/cpacf.h>
21
22 #define DES3_KEY_SIZE   (3 * DES_KEY_SIZE)
23
24 static u8 *ctrblk;
25 static DEFINE_MUTEX(ctrblk_lock);
26
27 static cpacf_mask_t km_functions, kmc_functions, kmctr_functions;
28
29 struct s390_des_ctx {
30         u8 iv[DES_BLOCK_SIZE];
31         u8 key[DES3_KEY_SIZE];
32 };
33
34 static int des_setkey(struct crypto_tfm *tfm, const u8 *key,
35                       unsigned int key_len)
36 {
37         struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
38         u32 tmp[DES_EXPKEY_WORDS];
39
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         }
46
47         memcpy(ctx->key, key, key_len);
48         return 0;
49 }
50
51 static void des_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
52 {
53         struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
54
55         cpacf_km(CPACF_KM_DEA, ctx->key, out, in, DES_BLOCK_SIZE);
56 }
57
58 static void des_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
59 {
60         struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
61
62         cpacf_km(CPACF_KM_DEA | CPACF_DECRYPT,
63                  ctx->key, out, in, DES_BLOCK_SIZE);
64 }
65
66 static struct crypto_alg des_alg = {
67         .cra_name               =       "des",
68         .cra_driver_name        =       "des-s390",
69         .cra_priority           =       300,
70         .cra_flags              =       CRYPTO_ALG_TYPE_CIPHER,
71         .cra_blocksize          =       DES_BLOCK_SIZE,
72         .cra_ctxsize            =       sizeof(struct s390_des_ctx),
73         .cra_module             =       THIS_MODULE,
74         .cra_u                  =       {
75                 .cipher = {
76                         .cia_min_keysize        =       DES_KEY_SIZE,
77                         .cia_max_keysize        =       DES_KEY_SIZE,
78                         .cia_setkey             =       des_setkey,
79                         .cia_encrypt            =       des_encrypt,
80                         .cia_decrypt            =       des_decrypt,
81                 }
82         }
83 };
84
85 static int ecb_desall_crypt(struct blkcipher_desc *desc, unsigned long fc,
86                             struct blkcipher_walk *walk)
87 {
88         struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
89         unsigned int nbytes, n;
90         int ret;
91
92         ret = blkcipher_walk_virt(desc, walk);
93         while ((nbytes = walk->nbytes) >= DES_BLOCK_SIZE) {
94                 /* only use complete blocks */
95                 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);
99         }
100         return ret;
101 }
102
103 static int cbc_desall_crypt(struct blkcipher_desc *desc, unsigned long fc,
104                             struct blkcipher_walk *walk)
105 {
106         struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
107         unsigned int nbytes, n;
108         int ret;
109         struct {
110                 u8 iv[DES_BLOCK_SIZE];
111                 u8 key[DES3_KEY_SIZE];
112         } param;
113
114         ret = blkcipher_walk_virt(desc, walk);
115         memcpy(param.iv, walk->iv, DES_BLOCK_SIZE);
116         memcpy(param.key, ctx->key, DES3_KEY_SIZE);
117         while ((nbytes = walk->nbytes) >= DES_BLOCK_SIZE) {
118                 /* only use complete blocks */
119                 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);
123         }
124         memcpy(walk->iv, param.iv, DES_BLOCK_SIZE);
125         return ret;
126 }
127
128 static int ecb_des_encrypt(struct blkcipher_desc *desc,
129                            struct scatterlist *dst, struct scatterlist *src,
130                            unsigned int nbytes)
131 {
132         struct blkcipher_walk walk;
133
134         blkcipher_walk_init(&walk, dst, src, nbytes);
135         return ecb_desall_crypt(desc, CPACF_KM_DEA, &walk);
136 }
137
138 static int ecb_des_decrypt(struct blkcipher_desc *desc,
139                            struct scatterlist *dst, struct scatterlist *src,
140                            unsigned int nbytes)
141 {
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);
146 }
147
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         }
166 };
167
168 static int cbc_des_encrypt(struct blkcipher_desc *desc,
169                            struct scatterlist *dst, struct scatterlist *src,
170                            unsigned int nbytes)
171 {
172         struct blkcipher_walk walk;
173
174         blkcipher_walk_init(&walk, dst, src, nbytes);
175         return cbc_desall_crypt(desc, CPACF_KMC_DEA, &walk);
176 }
177
178 static int cbc_des_decrypt(struct blkcipher_desc *desc,
179                            struct scatterlist *dst, struct scatterlist *src,
180                            unsigned int nbytes)
181 {
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);
186 }
187
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         }
207 };
208
209 /*
210  * RFC2451:
211  *
212  *   For DES-EDE3, there is no known need to reject weak or
213  *   complementation keys.  Any weakness is obviated by the use of
214  *   multiple keys.
215  *
216  *   However, if the first two or last two independent 64-bit keys are
217  *   equal (k1 == k2 or k2 == k3), then the DES3 operation is simply the
218  *   same as DES.  Implementers MUST reject keys that exhibit this
219  *   property.
220  *
221  *   In fips mode additinally check for all 3 keys are unique.
222  *
223  */
224 static int des3_setkey(struct crypto_tfm *tfm, const u8 *key,
225                        unsigned int key_len)
226 {
227         struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
228
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         }
246
247         memcpy(ctx->key, key, key_len);
248         return 0;
249 }
250
251 static void des3_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
252 {
253         struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
254
255         cpacf_km(CPACF_KM_TDEA_192, ctx->key, dst, src, DES_BLOCK_SIZE);
256 }
257
258 static void des3_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
259 {
260         struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
261
262         cpacf_km(CPACF_KM_TDEA_192 | CPACF_DECRYPT,
263                  ctx->key, dst, src, DES_BLOCK_SIZE);
264 }
265
266 static struct crypto_alg des3_alg = {
267         .cra_name               =       "des3_ede",
268         .cra_driver_name        =       "des3_ede-s390",
269         .cra_priority           =       300,
270         .cra_flags              =       CRYPTO_ALG_TYPE_CIPHER,
271         .cra_blocksize          =       DES_BLOCK_SIZE,
272         .cra_ctxsize            =       sizeof(struct s390_des_ctx),
273         .cra_module             =       THIS_MODULE,
274         .cra_u                  =       {
275                 .cipher = {
276                         .cia_min_keysize        =       DES3_KEY_SIZE,
277                         .cia_max_keysize        =       DES3_KEY_SIZE,
278                         .cia_setkey             =       des3_setkey,
279                         .cia_encrypt            =       des3_encrypt,
280                         .cia_decrypt            =       des3_decrypt,
281                 }
282         }
283 };
284
285 static int ecb_des3_encrypt(struct blkcipher_desc *desc,
286                             struct scatterlist *dst, struct scatterlist *src,
287                             unsigned int nbytes)
288 {
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);
293 }
294
295 static int ecb_des3_decrypt(struct blkcipher_desc *desc,
296                             struct scatterlist *dst, struct scatterlist *src,
297                             unsigned int nbytes)
298 {
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);
304 }
305
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         }
324 };
325
326 static int cbc_des3_encrypt(struct blkcipher_desc *desc,
327                             struct scatterlist *dst, struct scatterlist *src,
328                             unsigned int nbytes)
329 {
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);
334 }
335
336 static int cbc_des3_decrypt(struct blkcipher_desc *desc,
337                             struct scatterlist *dst, struct scatterlist *src,
338                             unsigned int nbytes)
339 {
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);
345 }
346
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         }
366 };
367
368 static unsigned int __ctrblk_init(u8 *ctrptr, u8 *iv, unsigned int nbytes)
369 {
370         unsigned int i, n;
371
372         /* align to block size, max. PAGE_SIZE */
373         n = (nbytes > PAGE_SIZE) ? PAGE_SIZE : nbytes & ~(DES_BLOCK_SIZE - 1);
374         memcpy(ctrptr, iv, DES_BLOCK_SIZE);
375         for (i = (n / DES_BLOCK_SIZE) - 1; i > 0; i--) {
376                 memcpy(ctrptr + DES_BLOCK_SIZE, ctrptr, DES_BLOCK_SIZE);
377                 crypto_inc(ctrptr + DES_BLOCK_SIZE, DES_BLOCK_SIZE);
378                 ctrptr += DES_BLOCK_SIZE;
379         }
380         return n;
381 }
382
383 static int ctr_desall_crypt(struct blkcipher_desc *desc, unsigned long fc,
384                             struct blkcipher_walk *walk)
385 {
386         struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
387         u8 buf[DES_BLOCK_SIZE], *ctrptr;
388         unsigned int n, nbytes;
389         int ret, locked;
390
391         locked = mutex_trylock(&ctrblk_lock);
392
393         ret = blkcipher_walk_virt_block(desc, walk, DES_BLOCK_SIZE);
394         while ((nbytes = walk->nbytes) >= DES_BLOCK_SIZE) {
395                 n = DES_BLOCK_SIZE;
396                 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);
401                 if (ctrptr == ctrblk)
402                         memcpy(walk->iv, ctrptr + n - DES_BLOCK_SIZE,
403                                 DES_BLOCK_SIZE);
404                 crypto_inc(walk->iv, DES_BLOCK_SIZE);
405                 ret = blkcipher_walk_done(desc, walk, nbytes - n);
406         }
407         if (locked)
408                 mutex_unlock(&ctrblk_lock);
409         /* final block may be < DES_BLOCK_SIZE, copy only nbytes */
410         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);
416         }
417         return ret;
418 }
419
420 static int ctr_des_encrypt(struct blkcipher_desc *desc,
421                            struct scatterlist *dst, struct scatterlist *src,
422                            unsigned int nbytes)
423 {
424         struct blkcipher_walk walk;
425
426         blkcipher_walk_init(&walk, dst, src, nbytes);
427         return ctr_desall_crypt(desc, CPACF_KMCTR_DEA, &walk);
428 }
429
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         }
459 };
460
461 static int ctr_des3_encrypt(struct blkcipher_desc *desc,
462                             struct scatterlist *dst, struct scatterlist *src,
463                             unsigned int nbytes)
464 {
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);
469 }
470
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         }
501 };
502
503 static struct crypto_alg *des_s390_algs_ptr[8];
504 static int des_s390_algs_num;
505
506 static int des_s390_register_alg(struct crypto_alg *alg)
507 {
508         int ret;
509
510         ret = crypto_register_alg(alg);
511         if (!ret)
512                 des_s390_algs_ptr[des_s390_algs_num++] = alg;
513         return ret;
514 }
515
516 static void des_s390_exit(void)
517 {
518         while (des_s390_algs_num--)
519                 crypto_unregister_alg(des_s390_algs_ptr[des_s390_algs_num]);
520         if (ctrblk)
521                 free_page((unsigned long) ctrblk);
522 }
523
524 static int __init des_s390_init(void)
525 {
526         int ret;
527
528         /* Query available functions for KM, KMC and KMCTR */
529         cpacf_query(CPACF_KM, &km_functions);
530         cpacf_query(CPACF_KMC, &kmc_functions);
531         cpacf_query(CPACF_KMCTR, &kmctr_functions);
532
533         if (cpacf_test_func(&km_functions, CPACF_KM_DEA)) {
534                 ret = des_s390_register_alg(&des_alg);
535                 if (ret)
536                         goto out_err;
537                 ret = des_s390_register_alg(&ecb_des_alg);
538                 if (ret)
539                         goto out_err;
540         }
541         if (cpacf_test_func(&kmc_functions, CPACF_KMC_DEA)) {
542                 ret = des_s390_register_alg(&cbc_des_alg);
543                 if (ret)
544                         goto out_err;
545         }
546         if (cpacf_test_func(&km_functions, CPACF_KM_TDEA_192)) {
547                 ret = des_s390_register_alg(&des3_alg);
548                 if (ret)
549                         goto out_err;
550                 ret = des_s390_register_alg(&ecb_des3_alg);
551                 if (ret)
552                         goto out_err;
553         }
554         if (cpacf_test_func(&kmc_functions, CPACF_KMC_TDEA_192)) {
555                 ret = des_s390_register_alg(&cbc_des3_alg);
556                 if (ret)
557                         goto out_err;
558         }
559
560         if (cpacf_test_func(&kmctr_functions, CPACF_KMCTR_DEA) ||
561             cpacf_test_func(&kmctr_functions, CPACF_KMCTR_TDEA_192)) {
562                 ctrblk = (u8 *) __get_free_page(GFP_KERNEL);
563                 if (!ctrblk) {
564                         ret = -ENOMEM;
565                         goto out_err;
566                 }
567         }
568
569         if (cpacf_test_func(&kmctr_functions, CPACF_KMCTR_DEA)) {
570                 ret = des_s390_register_alg(&ctr_des_alg);
571                 if (ret)
572                         goto out_err;
573         }
574         if (cpacf_test_func(&kmctr_functions, CPACF_KMCTR_TDEA_192)) {
575                 ret = des_s390_register_alg(&ctr_des3_alg);
576                 if (ret)
577                         goto out_err;
578         }
579
580         return 0;
581 out_err:
582         des_s390_exit();
583         return ret;
584 }
585
586 module_cpu_feature_match(MSA, des_s390_init);
587 module_exit(des_s390_exit);
588
589 MODULE_ALIAS_CRYPTO("des");
590 MODULE_ALIAS_CRYPTO("des3_ede");
591
592 MODULE_LICENSE("GPL");
593 MODULE_DESCRIPTION("DES & Triple DES EDE Cipher Algorithms");