1 // SPDX-License-Identifier: GPL-2.0
5 * s390 implementation of the AES Cipher Algorithm with protected keys.
8 * Copyright IBM Corp. 2017, 2023
9 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
10 * Harald Freudenberger <freude@de.ibm.com>
13 #define KMSG_COMPONENT "paes_s390"
14 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
16 #include <crypto/aes.h>
17 #include <crypto/algapi.h>
18 #include <linux/bug.h>
19 #include <linux/err.h>
20 #include <linux/module.h>
21 #include <linux/cpufeature.h>
22 #include <linux/init.h>
23 #include <linux/mutex.h>
24 #include <linux/spinlock.h>
25 #include <linux/delay.h>
26 #include <crypto/internal/skcipher.h>
27 #include <crypto/xts.h>
28 #include <asm/cpacf.h>
32 * Key blobs smaller/bigger than these defines are rejected
33 * by the common code even before the individual setkey function
34 * is called. As paes can handle different kinds of key blobs
35 * and padding is also possible, the limits need to be generous.
37 #define PAES_MIN_KEYSIZE 16
38 #define PAES_MAX_KEYSIZE MAXEP11AESKEYBLOBSIZE
41 static DEFINE_MUTEX(ctrblk_lock);
43 static cpacf_mask_t km_functions, kmc_functions, kmctr_functions;
47 * Small keys will be stored in the keybuf. Larger keys are
48 * stored in extra allocated memory. In both cases does
49 * key point to the memory where the key is stored.
50 * The code distinguishes by checking keylen against
51 * sizeof(keybuf). See the two following helper functions.
58 static inline int _key_to_kb(struct key_blob *kb,
62 struct clearkey_header {
75 /* clear key value, prepare pkey clear key token in keybuf */
76 memset(kb->keybuf, 0, sizeof(kb->keybuf));
77 h = (struct clearkey_header *) kb->keybuf;
78 h->version = 0x02; /* TOKVER_CLEAR_KEY */
79 h->keytype = (keylen - 8) >> 3;
81 memcpy(kb->keybuf + sizeof(*h), key, keylen);
82 kb->keylen = sizeof(*h) + keylen;
86 /* other key material, let pkey handle this */
87 if (keylen <= sizeof(kb->keybuf))
90 kb->key = kmalloc(keylen, GFP_KERNEL);
94 memcpy(kb->key, key, keylen);
102 static inline void _free_kb_keybuf(struct key_blob *kb)
104 if (kb->key && kb->key != kb->keybuf
105 && kb->keylen > sizeof(kb->keybuf)) {
106 kfree_sensitive(kb->key);
111 struct s390_paes_ctx {
113 struct pkey_protkey pk;
118 struct s390_pxts_ctx {
119 struct key_blob kb[2];
120 struct pkey_protkey pk[2];
125 static inline int __paes_keyblob2pkey(struct key_blob *kb,
126 struct pkey_protkey *pk)
130 /* try three times in case of failure */
131 for (i = 0; i < 3; i++) {
132 if (i > 0 && ret == -EAGAIN && in_task())
133 if (msleep_interruptible(1000))
135 ret = pkey_keyblob2pkey(kb->key, kb->keylen,
136 pk->protkey, &pk->len, &pk->type);
144 static inline int __paes_convert_key(struct s390_paes_ctx *ctx)
147 struct pkey_protkey pkey;
149 pkey.len = sizeof(pkey.protkey);
150 ret = __paes_keyblob2pkey(&ctx->kb, &pkey);
154 spin_lock_bh(&ctx->pk_lock);
155 memcpy(&ctx->pk, &pkey, sizeof(pkey));
156 spin_unlock_bh(&ctx->pk_lock);
161 static int ecb_paes_init(struct crypto_skcipher *tfm)
163 struct s390_paes_ctx *ctx = crypto_skcipher_ctx(tfm);
166 spin_lock_init(&ctx->pk_lock);
171 static void ecb_paes_exit(struct crypto_skcipher *tfm)
173 struct s390_paes_ctx *ctx = crypto_skcipher_ctx(tfm);
175 _free_kb_keybuf(&ctx->kb);
178 static inline int __ecb_paes_set_key(struct s390_paes_ctx *ctx)
183 rc = __paes_convert_key(ctx);
187 /* Pick the correct function code based on the protected key type */
188 fc = (ctx->pk.type == PKEY_KEYTYPE_AES_128) ? CPACF_KM_PAES_128 :
189 (ctx->pk.type == PKEY_KEYTYPE_AES_192) ? CPACF_KM_PAES_192 :
190 (ctx->pk.type == PKEY_KEYTYPE_AES_256) ? CPACF_KM_PAES_256 : 0;
192 /* Check if the function code is available */
193 ctx->fc = (fc && cpacf_test_func(&km_functions, fc)) ? fc : 0;
195 return ctx->fc ? 0 : -EINVAL;
198 static int ecb_paes_set_key(struct crypto_skcipher *tfm, const u8 *in_key,
199 unsigned int key_len)
202 struct s390_paes_ctx *ctx = crypto_skcipher_ctx(tfm);
204 _free_kb_keybuf(&ctx->kb);
205 rc = _key_to_kb(&ctx->kb, in_key, key_len);
209 return __ecb_paes_set_key(ctx);
212 static int ecb_paes_crypt(struct skcipher_request *req, unsigned long modifier)
214 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
215 struct s390_paes_ctx *ctx = crypto_skcipher_ctx(tfm);
216 struct skcipher_walk walk;
217 unsigned int nbytes, n, k;
220 u8 key[MAXPROTKEYSIZE];
223 ret = skcipher_walk_virt(&walk, req, false);
227 spin_lock_bh(&ctx->pk_lock);
228 memcpy(param.key, ctx->pk.protkey, MAXPROTKEYSIZE);
229 spin_unlock_bh(&ctx->pk_lock);
231 while ((nbytes = walk.nbytes) != 0) {
232 /* only use complete blocks */
233 n = nbytes & ~(AES_BLOCK_SIZE - 1);
234 k = cpacf_km(ctx->fc | modifier, ¶m,
235 walk.dst.virt.addr, walk.src.virt.addr, n);
237 ret = skcipher_walk_done(&walk, nbytes - k);
239 if (__paes_convert_key(ctx))
240 return skcipher_walk_done(&walk, -EIO);
241 spin_lock_bh(&ctx->pk_lock);
242 memcpy(param.key, ctx->pk.protkey, MAXPROTKEYSIZE);
243 spin_unlock_bh(&ctx->pk_lock);
249 static int ecb_paes_encrypt(struct skcipher_request *req)
251 return ecb_paes_crypt(req, 0);
254 static int ecb_paes_decrypt(struct skcipher_request *req)
256 return ecb_paes_crypt(req, CPACF_DECRYPT);
259 static struct skcipher_alg ecb_paes_alg = {
260 .base.cra_name = "ecb(paes)",
261 .base.cra_driver_name = "ecb-paes-s390",
262 .base.cra_priority = 401, /* combo: aes + ecb + 1 */
263 .base.cra_blocksize = AES_BLOCK_SIZE,
264 .base.cra_ctxsize = sizeof(struct s390_paes_ctx),
265 .base.cra_module = THIS_MODULE,
266 .base.cra_list = LIST_HEAD_INIT(ecb_paes_alg.base.cra_list),
267 .init = ecb_paes_init,
268 .exit = ecb_paes_exit,
269 .min_keysize = PAES_MIN_KEYSIZE,
270 .max_keysize = PAES_MAX_KEYSIZE,
271 .setkey = ecb_paes_set_key,
272 .encrypt = ecb_paes_encrypt,
273 .decrypt = ecb_paes_decrypt,
276 static int cbc_paes_init(struct crypto_skcipher *tfm)
278 struct s390_paes_ctx *ctx = crypto_skcipher_ctx(tfm);
281 spin_lock_init(&ctx->pk_lock);
286 static void cbc_paes_exit(struct crypto_skcipher *tfm)
288 struct s390_paes_ctx *ctx = crypto_skcipher_ctx(tfm);
290 _free_kb_keybuf(&ctx->kb);
293 static inline int __cbc_paes_set_key(struct s390_paes_ctx *ctx)
298 rc = __paes_convert_key(ctx);
302 /* Pick the correct function code based on the protected key type */
303 fc = (ctx->pk.type == PKEY_KEYTYPE_AES_128) ? CPACF_KMC_PAES_128 :
304 (ctx->pk.type == PKEY_KEYTYPE_AES_192) ? CPACF_KMC_PAES_192 :
305 (ctx->pk.type == PKEY_KEYTYPE_AES_256) ? CPACF_KMC_PAES_256 : 0;
307 /* Check if the function code is available */
308 ctx->fc = (fc && cpacf_test_func(&kmc_functions, fc)) ? fc : 0;
310 return ctx->fc ? 0 : -EINVAL;
313 static int cbc_paes_set_key(struct crypto_skcipher *tfm, const u8 *in_key,
314 unsigned int key_len)
317 struct s390_paes_ctx *ctx = crypto_skcipher_ctx(tfm);
319 _free_kb_keybuf(&ctx->kb);
320 rc = _key_to_kb(&ctx->kb, in_key, key_len);
324 return __cbc_paes_set_key(ctx);
327 static int cbc_paes_crypt(struct skcipher_request *req, unsigned long modifier)
329 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
330 struct s390_paes_ctx *ctx = crypto_skcipher_ctx(tfm);
331 struct skcipher_walk walk;
332 unsigned int nbytes, n, k;
335 u8 iv[AES_BLOCK_SIZE];
336 u8 key[MAXPROTKEYSIZE];
339 ret = skcipher_walk_virt(&walk, req, false);
343 memcpy(param.iv, walk.iv, AES_BLOCK_SIZE);
344 spin_lock_bh(&ctx->pk_lock);
345 memcpy(param.key, ctx->pk.protkey, MAXPROTKEYSIZE);
346 spin_unlock_bh(&ctx->pk_lock);
348 while ((nbytes = walk.nbytes) != 0) {
349 /* only use complete blocks */
350 n = nbytes & ~(AES_BLOCK_SIZE - 1);
351 k = cpacf_kmc(ctx->fc | modifier, ¶m,
352 walk.dst.virt.addr, walk.src.virt.addr, n);
354 memcpy(walk.iv, param.iv, AES_BLOCK_SIZE);
355 ret = skcipher_walk_done(&walk, nbytes - k);
358 if (__paes_convert_key(ctx))
359 return skcipher_walk_done(&walk, -EIO);
360 spin_lock_bh(&ctx->pk_lock);
361 memcpy(param.key, ctx->pk.protkey, MAXPROTKEYSIZE);
362 spin_unlock_bh(&ctx->pk_lock);
368 static int cbc_paes_encrypt(struct skcipher_request *req)
370 return cbc_paes_crypt(req, 0);
373 static int cbc_paes_decrypt(struct skcipher_request *req)
375 return cbc_paes_crypt(req, CPACF_DECRYPT);
378 static struct skcipher_alg cbc_paes_alg = {
379 .base.cra_name = "cbc(paes)",
380 .base.cra_driver_name = "cbc-paes-s390",
381 .base.cra_priority = 402, /* ecb-paes-s390 + 1 */
382 .base.cra_blocksize = AES_BLOCK_SIZE,
383 .base.cra_ctxsize = sizeof(struct s390_paes_ctx),
384 .base.cra_module = THIS_MODULE,
385 .base.cra_list = LIST_HEAD_INIT(cbc_paes_alg.base.cra_list),
386 .init = cbc_paes_init,
387 .exit = cbc_paes_exit,
388 .min_keysize = PAES_MIN_KEYSIZE,
389 .max_keysize = PAES_MAX_KEYSIZE,
390 .ivsize = AES_BLOCK_SIZE,
391 .setkey = cbc_paes_set_key,
392 .encrypt = cbc_paes_encrypt,
393 .decrypt = cbc_paes_decrypt,
396 static int xts_paes_init(struct crypto_skcipher *tfm)
398 struct s390_pxts_ctx *ctx = crypto_skcipher_ctx(tfm);
400 ctx->kb[0].key = NULL;
401 ctx->kb[1].key = NULL;
402 spin_lock_init(&ctx->pk_lock);
407 static void xts_paes_exit(struct crypto_skcipher *tfm)
409 struct s390_pxts_ctx *ctx = crypto_skcipher_ctx(tfm);
411 _free_kb_keybuf(&ctx->kb[0]);
412 _free_kb_keybuf(&ctx->kb[1]);
415 static inline int __xts_paes_convert_key(struct s390_pxts_ctx *ctx)
417 struct pkey_protkey pkey0, pkey1;
419 pkey0.len = sizeof(pkey0.protkey);
420 pkey1.len = sizeof(pkey1.protkey);
422 if (__paes_keyblob2pkey(&ctx->kb[0], &pkey0) ||
423 __paes_keyblob2pkey(&ctx->kb[1], &pkey1))
426 spin_lock_bh(&ctx->pk_lock);
427 memcpy(&ctx->pk[0], &pkey0, sizeof(pkey0));
428 memcpy(&ctx->pk[1], &pkey1, sizeof(pkey1));
429 spin_unlock_bh(&ctx->pk_lock);
434 static inline int __xts_paes_set_key(struct s390_pxts_ctx *ctx)
438 if (__xts_paes_convert_key(ctx))
441 if (ctx->pk[0].type != ctx->pk[1].type)
444 /* Pick the correct function code based on the protected key type */
445 fc = (ctx->pk[0].type == PKEY_KEYTYPE_AES_128) ? CPACF_KM_PXTS_128 :
446 (ctx->pk[0].type == PKEY_KEYTYPE_AES_256) ?
447 CPACF_KM_PXTS_256 : 0;
449 /* Check if the function code is available */
450 ctx->fc = (fc && cpacf_test_func(&km_functions, fc)) ? fc : 0;
452 return ctx->fc ? 0 : -EINVAL;
455 static int xts_paes_set_key(struct crypto_skcipher *tfm, const u8 *in_key,
456 unsigned int xts_key_len)
459 struct s390_pxts_ctx *ctx = crypto_skcipher_ctx(tfm);
460 u8 ckey[2 * AES_MAX_KEY_SIZE];
461 unsigned int ckey_len, key_len;
466 key_len = xts_key_len / 2;
468 _free_kb_keybuf(&ctx->kb[0]);
469 _free_kb_keybuf(&ctx->kb[1]);
470 rc = _key_to_kb(&ctx->kb[0], in_key, key_len);
473 rc = _key_to_kb(&ctx->kb[1], in_key + key_len, key_len);
477 rc = __xts_paes_set_key(ctx);
482 * xts_verify_key verifies the key length is not odd and makes
483 * sure that the two keys are not the same. This can be done
484 * on the two protected keys as well
486 ckey_len = (ctx->pk[0].type == PKEY_KEYTYPE_AES_128) ?
487 AES_KEYSIZE_128 : AES_KEYSIZE_256;
488 memcpy(ckey, ctx->pk[0].protkey, ckey_len);
489 memcpy(ckey + ckey_len, ctx->pk[1].protkey, ckey_len);
490 return xts_verify_key(tfm, ckey, 2*ckey_len);
493 static int xts_paes_crypt(struct skcipher_request *req, unsigned long modifier)
495 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
496 struct s390_pxts_ctx *ctx = crypto_skcipher_ctx(tfm);
497 struct skcipher_walk walk;
498 unsigned int keylen, offset, nbytes, n, k;
501 u8 key[MAXPROTKEYSIZE]; /* key + verification pattern */
508 u8 key[MAXPROTKEYSIZE]; /* key + verification pattern */
512 ret = skcipher_walk_virt(&walk, req, false);
516 keylen = (ctx->pk[0].type == PKEY_KEYTYPE_AES_128) ? 48 : 64;
517 offset = (ctx->pk[0].type == PKEY_KEYTYPE_AES_128) ? 16 : 0;
519 memset(&pcc_param, 0, sizeof(pcc_param));
520 memcpy(pcc_param.tweak, walk.iv, sizeof(pcc_param.tweak));
521 spin_lock_bh(&ctx->pk_lock);
522 memcpy(pcc_param.key + offset, ctx->pk[1].protkey, keylen);
523 memcpy(xts_param.key + offset, ctx->pk[0].protkey, keylen);
524 spin_unlock_bh(&ctx->pk_lock);
525 cpacf_pcc(ctx->fc, pcc_param.key + offset);
526 memcpy(xts_param.init, pcc_param.xts, 16);
528 while ((nbytes = walk.nbytes) != 0) {
529 /* only use complete blocks */
530 n = nbytes & ~(AES_BLOCK_SIZE - 1);
531 k = cpacf_km(ctx->fc | modifier, xts_param.key + offset,
532 walk.dst.virt.addr, walk.src.virt.addr, n);
534 ret = skcipher_walk_done(&walk, nbytes - k);
536 if (__xts_paes_convert_key(ctx))
537 return skcipher_walk_done(&walk, -EIO);
538 spin_lock_bh(&ctx->pk_lock);
539 memcpy(xts_param.key + offset,
540 ctx->pk[0].protkey, keylen);
541 spin_unlock_bh(&ctx->pk_lock);
548 static int xts_paes_encrypt(struct skcipher_request *req)
550 return xts_paes_crypt(req, 0);
553 static int xts_paes_decrypt(struct skcipher_request *req)
555 return xts_paes_crypt(req, CPACF_DECRYPT);
558 static struct skcipher_alg xts_paes_alg = {
559 .base.cra_name = "xts(paes)",
560 .base.cra_driver_name = "xts-paes-s390",
561 .base.cra_priority = 402, /* ecb-paes-s390 + 1 */
562 .base.cra_blocksize = AES_BLOCK_SIZE,
563 .base.cra_ctxsize = sizeof(struct s390_pxts_ctx),
564 .base.cra_module = THIS_MODULE,
565 .base.cra_list = LIST_HEAD_INIT(xts_paes_alg.base.cra_list),
566 .init = xts_paes_init,
567 .exit = xts_paes_exit,
568 .min_keysize = 2 * PAES_MIN_KEYSIZE,
569 .max_keysize = 2 * PAES_MAX_KEYSIZE,
570 .ivsize = AES_BLOCK_SIZE,
571 .setkey = xts_paes_set_key,
572 .encrypt = xts_paes_encrypt,
573 .decrypt = xts_paes_decrypt,
576 static int ctr_paes_init(struct crypto_skcipher *tfm)
578 struct s390_paes_ctx *ctx = crypto_skcipher_ctx(tfm);
581 spin_lock_init(&ctx->pk_lock);
586 static void ctr_paes_exit(struct crypto_skcipher *tfm)
588 struct s390_paes_ctx *ctx = crypto_skcipher_ctx(tfm);
590 _free_kb_keybuf(&ctx->kb);
593 static inline int __ctr_paes_set_key(struct s390_paes_ctx *ctx)
598 rc = __paes_convert_key(ctx);
602 /* Pick the correct function code based on the protected key type */
603 fc = (ctx->pk.type == PKEY_KEYTYPE_AES_128) ? CPACF_KMCTR_PAES_128 :
604 (ctx->pk.type == PKEY_KEYTYPE_AES_192) ? CPACF_KMCTR_PAES_192 :
605 (ctx->pk.type == PKEY_KEYTYPE_AES_256) ?
606 CPACF_KMCTR_PAES_256 : 0;
608 /* Check if the function code is available */
609 ctx->fc = (fc && cpacf_test_func(&kmctr_functions, fc)) ? fc : 0;
611 return ctx->fc ? 0 : -EINVAL;
614 static int ctr_paes_set_key(struct crypto_skcipher *tfm, const u8 *in_key,
615 unsigned int key_len)
618 struct s390_paes_ctx *ctx = crypto_skcipher_ctx(tfm);
620 _free_kb_keybuf(&ctx->kb);
621 rc = _key_to_kb(&ctx->kb, in_key, key_len);
625 return __ctr_paes_set_key(ctx);
628 static unsigned int __ctrblk_init(u8 *ctrptr, u8 *iv, unsigned int nbytes)
632 /* only use complete blocks, max. PAGE_SIZE */
633 memcpy(ctrptr, iv, AES_BLOCK_SIZE);
634 n = (nbytes > PAGE_SIZE) ? PAGE_SIZE : nbytes & ~(AES_BLOCK_SIZE - 1);
635 for (i = (n / AES_BLOCK_SIZE) - 1; i > 0; i--) {
636 memcpy(ctrptr + AES_BLOCK_SIZE, ctrptr, AES_BLOCK_SIZE);
637 crypto_inc(ctrptr + AES_BLOCK_SIZE, AES_BLOCK_SIZE);
638 ctrptr += AES_BLOCK_SIZE;
643 static int ctr_paes_crypt(struct skcipher_request *req)
645 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
646 struct s390_paes_ctx *ctx = crypto_skcipher_ctx(tfm);
647 u8 buf[AES_BLOCK_SIZE], *ctrptr;
648 struct skcipher_walk walk;
649 unsigned int nbytes, n, k;
652 u8 key[MAXPROTKEYSIZE];
655 ret = skcipher_walk_virt(&walk, req, false);
659 spin_lock_bh(&ctx->pk_lock);
660 memcpy(param.key, ctx->pk.protkey, MAXPROTKEYSIZE);
661 spin_unlock_bh(&ctx->pk_lock);
663 locked = mutex_trylock(&ctrblk_lock);
665 while ((nbytes = walk.nbytes) >= AES_BLOCK_SIZE) {
667 if (nbytes >= 2*AES_BLOCK_SIZE && locked)
668 n = __ctrblk_init(ctrblk, walk.iv, nbytes);
669 ctrptr = (n > AES_BLOCK_SIZE) ? ctrblk : walk.iv;
670 k = cpacf_kmctr(ctx->fc, ¶m, walk.dst.virt.addr,
671 walk.src.virt.addr, n, ctrptr);
673 if (ctrptr == ctrblk)
674 memcpy(walk.iv, ctrptr + k - AES_BLOCK_SIZE,
676 crypto_inc(walk.iv, AES_BLOCK_SIZE);
677 ret = skcipher_walk_done(&walk, nbytes - k);
680 if (__paes_convert_key(ctx)) {
682 mutex_unlock(&ctrblk_lock);
683 return skcipher_walk_done(&walk, -EIO);
685 spin_lock_bh(&ctx->pk_lock);
686 memcpy(param.key, ctx->pk.protkey, MAXPROTKEYSIZE);
687 spin_unlock_bh(&ctx->pk_lock);
691 mutex_unlock(&ctrblk_lock);
693 * final block may be < AES_BLOCK_SIZE, copy only nbytes
697 if (cpacf_kmctr(ctx->fc, ¶m, buf,
698 walk.src.virt.addr, AES_BLOCK_SIZE,
699 walk.iv) == AES_BLOCK_SIZE)
701 if (__paes_convert_key(ctx))
702 return skcipher_walk_done(&walk, -EIO);
703 spin_lock_bh(&ctx->pk_lock);
704 memcpy(param.key, ctx->pk.protkey, MAXPROTKEYSIZE);
705 spin_unlock_bh(&ctx->pk_lock);
707 memcpy(walk.dst.virt.addr, buf, nbytes);
708 crypto_inc(walk.iv, AES_BLOCK_SIZE);
709 ret = skcipher_walk_done(&walk, nbytes);
715 static struct skcipher_alg ctr_paes_alg = {
716 .base.cra_name = "ctr(paes)",
717 .base.cra_driver_name = "ctr-paes-s390",
718 .base.cra_priority = 402, /* ecb-paes-s390 + 1 */
719 .base.cra_blocksize = 1,
720 .base.cra_ctxsize = sizeof(struct s390_paes_ctx),
721 .base.cra_module = THIS_MODULE,
722 .base.cra_list = LIST_HEAD_INIT(ctr_paes_alg.base.cra_list),
723 .init = ctr_paes_init,
724 .exit = ctr_paes_exit,
725 .min_keysize = PAES_MIN_KEYSIZE,
726 .max_keysize = PAES_MAX_KEYSIZE,
727 .ivsize = AES_BLOCK_SIZE,
728 .setkey = ctr_paes_set_key,
729 .encrypt = ctr_paes_crypt,
730 .decrypt = ctr_paes_crypt,
731 .chunksize = AES_BLOCK_SIZE,
734 static inline void __crypto_unregister_skcipher(struct skcipher_alg *alg)
736 if (!list_empty(&alg->base.cra_list))
737 crypto_unregister_skcipher(alg);
740 static void paes_s390_fini(void)
742 __crypto_unregister_skcipher(&ctr_paes_alg);
743 __crypto_unregister_skcipher(&xts_paes_alg);
744 __crypto_unregister_skcipher(&cbc_paes_alg);
745 __crypto_unregister_skcipher(&ecb_paes_alg);
747 free_page((unsigned long) ctrblk);
750 static int __init paes_s390_init(void)
754 /* Query available functions for KM, KMC and KMCTR */
755 cpacf_query(CPACF_KM, &km_functions);
756 cpacf_query(CPACF_KMC, &kmc_functions);
757 cpacf_query(CPACF_KMCTR, &kmctr_functions);
759 if (cpacf_test_func(&km_functions, CPACF_KM_PAES_128) ||
760 cpacf_test_func(&km_functions, CPACF_KM_PAES_192) ||
761 cpacf_test_func(&km_functions, CPACF_KM_PAES_256)) {
762 ret = crypto_register_skcipher(&ecb_paes_alg);
767 if (cpacf_test_func(&kmc_functions, CPACF_KMC_PAES_128) ||
768 cpacf_test_func(&kmc_functions, CPACF_KMC_PAES_192) ||
769 cpacf_test_func(&kmc_functions, CPACF_KMC_PAES_256)) {
770 ret = crypto_register_skcipher(&cbc_paes_alg);
775 if (cpacf_test_func(&km_functions, CPACF_KM_PXTS_128) ||
776 cpacf_test_func(&km_functions, CPACF_KM_PXTS_256)) {
777 ret = crypto_register_skcipher(&xts_paes_alg);
782 if (cpacf_test_func(&kmctr_functions, CPACF_KMCTR_PAES_128) ||
783 cpacf_test_func(&kmctr_functions, CPACF_KMCTR_PAES_192) ||
784 cpacf_test_func(&kmctr_functions, CPACF_KMCTR_PAES_256)) {
785 ctrblk = (u8 *) __get_free_page(GFP_KERNEL);
790 ret = crypto_register_skcipher(&ctr_paes_alg);
801 module_init(paes_s390_init);
802 module_exit(paes_s390_fini);
804 MODULE_ALIAS_CRYPTO("paes");
806 MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm with protected keys");
807 MODULE_LICENSE("GPL");