summaryrefslogtreecommitdiffstats
path: root/arch/s390
diff options
context:
space:
mode:
authorMartin Schwidefsky <schwidefsky@de.ibm.com>2016-08-15 03:19:16 -0400
committerMartin Schwidefsky <schwidefsky@de.ibm.com>2016-08-29 05:05:05 -0400
commitedc63a3785b48455e05793e848f0174e21f38d09 (patch)
tree156db37176d471ab4ea136188916c3c9b851b3b8 /arch/s390
parent474fd6e80fe529e9adeeb7ea9d4e5d6c4da0b7fe (diff)
s390/crypto: cleanup cpacf function codes
Use a separate define for the decryption modifier bit instead of duplicating the function codes for encryption / decrypton. In addition use an unsigned type for the function code. Reviewed-by: Harald Freudenberger <freude@linux.vnet.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Diffstat (limited to 'arch/s390')
-rw-r--r--arch/s390/crypto/aes_s390.c98
-rw-r--r--arch/s390/crypto/des_s390.c47
-rw-r--r--arch/s390/include/asm/cpacf.h98
3 files changed, 110 insertions, 133 deletions
diff --git a/arch/s390/crypto/aes_s390.c b/arch/s390/crypto/aes_s390.c
index 2ea18b050309..9da54698b87a 100644
--- a/arch/s390/crypto/aes_s390.c
+++ b/arch/s390/crypto/aes_s390.c
@@ -41,9 +41,8 @@ static char keylen_flag;
41 41
42struct s390_aes_ctx { 42struct s390_aes_ctx {
43 u8 key[AES_MAX_KEY_SIZE]; 43 u8 key[AES_MAX_KEY_SIZE];
44 long enc;
45 long dec;
46 int key_len; 44 int key_len;
45 unsigned long fc;
47 union { 46 union {
48 struct crypto_skcipher *blk; 47 struct crypto_skcipher *blk;
49 struct crypto_cipher *cip; 48 struct crypto_cipher *cip;
@@ -61,9 +60,8 @@ struct pcc_param {
61struct s390_xts_ctx { 60struct s390_xts_ctx {
62 u8 key[32]; 61 u8 key[32];
63 u8 pcc_key[32]; 62 u8 pcc_key[32];
64 long enc;
65 long dec;
66 int key_len; 63 int key_len;
64 unsigned long fc;
67 struct crypto_skcipher *fallback; 65 struct crypto_skcipher *fallback;
68}; 66};
69 67
@@ -146,16 +144,16 @@ static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
146 144
147 switch (sctx->key_len) { 145 switch (sctx->key_len) {
148 case 16: 146 case 16:
149 cpacf_km(CPACF_KM_AES_128_ENC, &sctx->key, out, in, 147 cpacf_km(CPACF_KM_AES_128,
150 AES_BLOCK_SIZE); 148 &sctx->key, out, in, AES_BLOCK_SIZE);
151 break; 149 break;
152 case 24: 150 case 24:
153 cpacf_km(CPACF_KM_AES_192_ENC, &sctx->key, out, in, 151 cpacf_km(CPACF_KM_AES_192,
154 AES_BLOCK_SIZE); 152 &sctx->key, out, in, AES_BLOCK_SIZE);
155 break; 153 break;
156 case 32: 154 case 32:
157 cpacf_km(CPACF_KM_AES_256_ENC, &sctx->key, out, in, 155 cpacf_km(CPACF_KM_AES_256,
158 AES_BLOCK_SIZE); 156 &sctx->key, out, in, AES_BLOCK_SIZE);
159 break; 157 break;
160 } 158 }
161} 159}
@@ -171,16 +169,16 @@ static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
171 169
172 switch (sctx->key_len) { 170 switch (sctx->key_len) {
173 case 16: 171 case 16:
174 cpacf_km(CPACF_KM_AES_128_DEC, &sctx->key, out, in, 172 cpacf_km(CPACF_KM_AES_128 | CPACF_DECRYPT,
175 AES_BLOCK_SIZE); 173 &sctx->key, out, in, AES_BLOCK_SIZE);
176 break; 174 break;
177 case 24: 175 case 24:
178 cpacf_km(CPACF_KM_AES_192_DEC, &sctx->key, out, in, 176 cpacf_km(CPACF_KM_AES_192 | CPACF_DECRYPT,
179 AES_BLOCK_SIZE); 177 &sctx->key, out, in, AES_BLOCK_SIZE);
180 break; 178 break;
181 case 32: 179 case 32:
182 cpacf_km(CPACF_KM_AES_256_DEC, &sctx->key, out, in, 180 cpacf_km(CPACF_KM_AES_256 | CPACF_DECRYPT,
183 AES_BLOCK_SIZE); 181 &sctx->key, out, in, AES_BLOCK_SIZE);
184 break; 182 break;
185 } 183 }
186} 184}
@@ -301,16 +299,13 @@ static int ecb_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
301 299
302 switch (key_len) { 300 switch (key_len) {
303 case 16: 301 case 16:
304 sctx->enc = CPACF_KM_AES_128_ENC; 302 sctx->fc = CPACF_KM_AES_128;
305 sctx->dec = CPACF_KM_AES_128_DEC;
306 break; 303 break;
307 case 24: 304 case 24:
308 sctx->enc = CPACF_KM_AES_192_ENC; 305 sctx->fc = CPACF_KM_AES_192;
309 sctx->dec = CPACF_KM_AES_192_DEC;
310 break; 306 break;
311 case 32: 307 case 32:
312 sctx->enc = CPACF_KM_AES_256_ENC; 308 sctx->fc = CPACF_KM_AES_256;
313 sctx->dec = CPACF_KM_AES_256_DEC;
314 break; 309 break;
315 } 310 }
316 311
@@ -351,7 +346,7 @@ static int ecb_aes_encrypt(struct blkcipher_desc *desc,
351 return fallback_blk_enc(desc, dst, src, nbytes); 346 return fallback_blk_enc(desc, dst, src, nbytes);
352 347
353 blkcipher_walk_init(&walk, dst, src, nbytes); 348 blkcipher_walk_init(&walk, dst, src, nbytes);
354 return ecb_aes_crypt(desc, sctx->enc, sctx->key, &walk); 349 return ecb_aes_crypt(desc, sctx->fc, sctx->key, &walk);
355} 350}
356 351
357static int ecb_aes_decrypt(struct blkcipher_desc *desc, 352static int ecb_aes_decrypt(struct blkcipher_desc *desc,
@@ -365,7 +360,7 @@ static int ecb_aes_decrypt(struct blkcipher_desc *desc,
365 return fallback_blk_dec(desc, dst, src, nbytes); 360 return fallback_blk_dec(desc, dst, src, nbytes);
366 361
367 blkcipher_walk_init(&walk, dst, src, nbytes); 362 blkcipher_walk_init(&walk, dst, src, nbytes);
368 return ecb_aes_crypt(desc, sctx->dec, sctx->key, &walk); 363 return ecb_aes_crypt(desc, sctx->fc | CPACF_DECRYPT, sctx->key, &walk);
369} 364}
370 365
371static int fallback_init_blk(struct crypto_tfm *tfm) 366static int fallback_init_blk(struct crypto_tfm *tfm)
@@ -430,16 +425,13 @@ static int cbc_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
430 425
431 switch (key_len) { 426 switch (key_len) {
432 case 16: 427 case 16:
433 sctx->enc = CPACF_KMC_AES_128_ENC; 428 sctx->fc = CPACF_KMC_AES_128;
434 sctx->dec = CPACF_KMC_AES_128_DEC;
435 break; 429 break;
436 case 24: 430 case 24:
437 sctx->enc = CPACF_KMC_AES_192_ENC; 431 sctx->fc = CPACF_KMC_AES_192;
438 sctx->dec = CPACF_KMC_AES_192_DEC;
439 break; 432 break;
440 case 32: 433 case 32:
441 sctx->enc = CPACF_KMC_AES_256_ENC; 434 sctx->fc = CPACF_KMC_AES_256;
442 sctx->dec = CPACF_KMC_AES_256_DEC;
443 break; 435 break;
444 } 436 }
445 437
@@ -492,7 +484,7 @@ static int cbc_aes_encrypt(struct blkcipher_desc *desc,
492 return fallback_blk_enc(desc, dst, src, nbytes); 484 return fallback_blk_enc(desc, dst, src, nbytes);
493 485
494 blkcipher_walk_init(&walk, dst, src, nbytes); 486 blkcipher_walk_init(&walk, dst, src, nbytes);
495 return cbc_aes_crypt(desc, sctx->enc, &walk); 487 return cbc_aes_crypt(desc, sctx->fc, &walk);
496} 488}
497 489
498static int cbc_aes_decrypt(struct blkcipher_desc *desc, 490static int cbc_aes_decrypt(struct blkcipher_desc *desc,
@@ -506,7 +498,7 @@ static int cbc_aes_decrypt(struct blkcipher_desc *desc,
506 return fallback_blk_dec(desc, dst, src, nbytes); 498 return fallback_blk_dec(desc, dst, src, nbytes);
507 499
508 blkcipher_walk_init(&walk, dst, src, nbytes); 500 blkcipher_walk_init(&walk, dst, src, nbytes);
509 return cbc_aes_crypt(desc, sctx->dec, &walk); 501 return cbc_aes_crypt(desc, sctx->fc | CPACF_DECRYPT, &walk);
510} 502}
511 503
512static struct crypto_alg cbc_aes_alg = { 504static struct crypto_alg cbc_aes_alg = {
@@ -603,19 +595,16 @@ static int xts_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
603 595
604 switch (key_len) { 596 switch (key_len) {
605 case 32: 597 case 32:
606 xts_ctx->enc = CPACF_KM_XTS_128_ENC; 598 xts_ctx->fc = CPACF_KM_XTS_128;
607 xts_ctx->dec = CPACF_KM_XTS_128_DEC;
608 memcpy(xts_ctx->key + 16, in_key, 16); 599 memcpy(xts_ctx->key + 16, in_key, 16);
609 memcpy(xts_ctx->pcc_key + 16, in_key + 16, 16); 600 memcpy(xts_ctx->pcc_key + 16, in_key + 16, 16);
610 break; 601 break;
611 case 48: 602 case 48:
612 xts_ctx->enc = 0; 603 xts_ctx->fc = 0;
613 xts_ctx->dec = 0;
614 xts_fallback_setkey(tfm, in_key, key_len); 604 xts_fallback_setkey(tfm, in_key, key_len);
615 break; 605 break;
616 case 64: 606 case 64:
617 xts_ctx->enc = CPACF_KM_XTS_256_ENC; 607 xts_ctx->fc = CPACF_KM_XTS_256;
618 xts_ctx->dec = CPACF_KM_XTS_256_DEC;
619 memcpy(xts_ctx->key, in_key, 32); 608 memcpy(xts_ctx->key, in_key, 32);
620 memcpy(xts_ctx->pcc_key, in_key + 32, 32); 609 memcpy(xts_ctx->pcc_key, in_key + 32, 32);
621 break; 610 break;
@@ -685,7 +674,7 @@ static int xts_aes_encrypt(struct blkcipher_desc *desc,
685 return xts_fallback_encrypt(desc, dst, src, nbytes); 674 return xts_fallback_encrypt(desc, dst, src, nbytes);
686 675
687 blkcipher_walk_init(&walk, dst, src, nbytes); 676 blkcipher_walk_init(&walk, dst, src, nbytes);
688 return xts_aes_crypt(desc, xts_ctx->enc, xts_ctx, &walk); 677 return xts_aes_crypt(desc, xts_ctx->fc, xts_ctx, &walk);
689} 678}
690 679
691static int xts_aes_decrypt(struct blkcipher_desc *desc, 680static int xts_aes_decrypt(struct blkcipher_desc *desc,
@@ -699,7 +688,7 @@ static int xts_aes_decrypt(struct blkcipher_desc *desc,
699 return xts_fallback_decrypt(desc, dst, src, nbytes); 688 return xts_fallback_decrypt(desc, dst, src, nbytes);
700 689
701 blkcipher_walk_init(&walk, dst, src, nbytes); 690 blkcipher_walk_init(&walk, dst, src, nbytes);
702 return xts_aes_crypt(desc, xts_ctx->dec, xts_ctx, &walk); 691 return xts_aes_crypt(desc, xts_ctx->fc | CPACF_DECRYPT, xts_ctx, &walk);
703} 692}
704 693
705static int xts_fallback_init(struct crypto_tfm *tfm) 694static int xts_fallback_init(struct crypto_tfm *tfm)
@@ -759,16 +748,13 @@ static int ctr_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
759 748
760 switch (key_len) { 749 switch (key_len) {
761 case 16: 750 case 16:
762 sctx->enc = CPACF_KMCTR_AES_128_ENC; 751 sctx->fc = CPACF_KMCTR_AES_128;
763 sctx->dec = CPACF_KMCTR_AES_128_DEC;
764 break; 752 break;
765 case 24: 753 case 24:
766 sctx->enc = CPACF_KMCTR_AES_192_ENC; 754 sctx->fc = CPACF_KMCTR_AES_192;
767 sctx->dec = CPACF_KMCTR_AES_192_DEC;
768 break; 755 break;
769 case 32: 756 case 32:
770 sctx->enc = CPACF_KMCTR_AES_256_ENC; 757 sctx->fc = CPACF_KMCTR_AES_256;
771 sctx->dec = CPACF_KMCTR_AES_256_DEC;
772 break; 758 break;
773 } 759 }
774 760
@@ -865,7 +851,7 @@ static int ctr_aes_encrypt(struct blkcipher_desc *desc,
865 struct blkcipher_walk walk; 851 struct blkcipher_walk walk;
866 852
867 blkcipher_walk_init(&walk, dst, src, nbytes); 853 blkcipher_walk_init(&walk, dst, src, nbytes);
868 return ctr_aes_crypt(desc, sctx->enc, sctx, &walk); 854 return ctr_aes_crypt(desc, sctx->fc, sctx, &walk);
869} 855}
870 856
871static int ctr_aes_decrypt(struct blkcipher_desc *desc, 857static int ctr_aes_decrypt(struct blkcipher_desc *desc,
@@ -876,7 +862,7 @@ static int ctr_aes_decrypt(struct blkcipher_desc *desc,
876 struct blkcipher_walk walk; 862 struct blkcipher_walk walk;
877 863
878 blkcipher_walk_init(&walk, dst, src, nbytes); 864 blkcipher_walk_init(&walk, dst, src, nbytes);
879 return ctr_aes_crypt(desc, sctx->dec, sctx, &walk); 865 return ctr_aes_crypt(desc, sctx->fc | CPACF_DECRYPT, sctx, &walk);
880} 866}
881 867
882static struct crypto_alg ctr_aes_alg = { 868static struct crypto_alg ctr_aes_alg = {
@@ -906,11 +892,11 @@ static int __init aes_s390_init(void)
906{ 892{
907 int ret; 893 int ret;
908 894
909 if (cpacf_query(CPACF_KM, CPACF_KM_AES_128_ENC)) 895 if (cpacf_query(CPACF_KM, CPACF_KM_AES_128))
910 keylen_flag |= AES_KEYLEN_128; 896 keylen_flag |= AES_KEYLEN_128;
911 if (cpacf_query(CPACF_KM, CPACF_KM_AES_192_ENC)) 897 if (cpacf_query(CPACF_KM, CPACF_KM_AES_192))
912 keylen_flag |= AES_KEYLEN_192; 898 keylen_flag |= AES_KEYLEN_192;
913 if (cpacf_query(CPACF_KM, CPACF_KM_AES_256_ENC)) 899 if (cpacf_query(CPACF_KM, CPACF_KM_AES_256))
914 keylen_flag |= AES_KEYLEN_256; 900 keylen_flag |= AES_KEYLEN_256;
915 901
916 if (!keylen_flag) 902 if (!keylen_flag)
@@ -933,17 +919,17 @@ static int __init aes_s390_init(void)
933 if (ret) 919 if (ret)
934 goto cbc_aes_err; 920 goto cbc_aes_err;
935 921
936 if (cpacf_query(CPACF_KM, CPACF_KM_XTS_128_ENC) && 922 if (cpacf_query(CPACF_KM, CPACF_KM_XTS_128) &&
937 cpacf_query(CPACF_KM, CPACF_KM_XTS_256_ENC)) { 923 cpacf_query(CPACF_KM, CPACF_KM_XTS_256)) {
938 ret = crypto_register_alg(&xts_aes_alg); 924 ret = crypto_register_alg(&xts_aes_alg);
939 if (ret) 925 if (ret)
940 goto xts_aes_err; 926 goto xts_aes_err;
941 xts_aes_alg_reg = 1; 927 xts_aes_alg_reg = 1;
942 } 928 }
943 929
944 if (cpacf_query(CPACF_KMCTR, CPACF_KMCTR_AES_128_ENC) && 930 if (cpacf_query(CPACF_KMCTR, CPACF_KMCTR_AES_128) &&
945 cpacf_query(CPACF_KMCTR, CPACF_KMCTR_AES_192_ENC) && 931 cpacf_query(CPACF_KMCTR, CPACF_KMCTR_AES_192) &&
946 cpacf_query(CPACF_KMCTR, CPACF_KMCTR_AES_256_ENC)) { 932 cpacf_query(CPACF_KMCTR, CPACF_KMCTR_AES_256)) {
947 ctrblk = (u8 *) __get_free_page(GFP_KERNEL); 933 ctrblk = (u8 *) __get_free_page(GFP_KERNEL);
948 if (!ctrblk) { 934 if (!ctrblk) {
949 ret = -ENOMEM; 935 ret = -ENOMEM;
diff --git a/arch/s390/crypto/des_s390.c b/arch/s390/crypto/des_s390.c
index 697e71a75fc2..fadd474bf8bb 100644
--- a/arch/s390/crypto/des_s390.c
+++ b/arch/s390/crypto/des_s390.c
@@ -53,14 +53,15 @@ static void des_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
53{ 53{
54 struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm); 54 struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
55 55
56 cpacf_km(CPACF_KM_DEA_ENC, ctx->key, out, in, DES_BLOCK_SIZE); 56 cpacf_km(CPACF_KM_DEA, ctx->key, out, in, DES_BLOCK_SIZE);
57} 57}
58 58
59static void des_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) 59static void des_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
60{ 60{
61 struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm); 61 struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
62 62
63 cpacf_km(CPACF_KM_DEA_DEC, ctx->key, out, in, DES_BLOCK_SIZE); 63 cpacf_km(CPACF_KM_DEA | CPACF_DECRYPT,
64 ctx->key, out, in, DES_BLOCK_SIZE);
64} 65}
65 66
66static struct crypto_alg des_alg = { 67static struct crypto_alg des_alg = {
@@ -148,7 +149,7 @@ static int ecb_des_encrypt(struct blkcipher_desc *desc,
148 struct blkcipher_walk walk; 149 struct blkcipher_walk walk;
149 150
150 blkcipher_walk_init(&walk, dst, src, nbytes); 151 blkcipher_walk_init(&walk, dst, src, nbytes);
151 return ecb_desall_crypt(desc, CPACF_KM_DEA_ENC, ctx->key, &walk); 152 return ecb_desall_crypt(desc, CPACF_KM_DEA, ctx->key, &walk);
152} 153}
153 154
154static int ecb_des_decrypt(struct blkcipher_desc *desc, 155static int ecb_des_decrypt(struct blkcipher_desc *desc,
@@ -159,7 +160,8 @@ static int ecb_des_decrypt(struct blkcipher_desc *desc,
159 struct blkcipher_walk walk; 160 struct blkcipher_walk walk;
160 161
161 blkcipher_walk_init(&walk, dst, src, nbytes); 162 blkcipher_walk_init(&walk, dst, src, nbytes);
162 return ecb_desall_crypt(desc, CPACF_KM_DEA_DEC, ctx->key, &walk); 163 return ecb_desall_crypt(desc, CPACF_KM_DEA | CPACF_DECRYPT,
164 ctx->key, &walk);
163} 165}
164 166
165static struct crypto_alg ecb_des_alg = { 167static struct crypto_alg ecb_des_alg = {
@@ -189,7 +191,7 @@ static int cbc_des_encrypt(struct blkcipher_desc *desc,
189 struct blkcipher_walk walk; 191 struct blkcipher_walk walk;
190 192
191 blkcipher_walk_init(&walk, dst, src, nbytes); 193 blkcipher_walk_init(&walk, dst, src, nbytes);
192 return cbc_desall_crypt(desc, CPACF_KMC_DEA_ENC, &walk); 194 return cbc_desall_crypt(desc, CPACF_KMC_DEA, &walk);
193} 195}
194 196
195static int cbc_des_decrypt(struct blkcipher_desc *desc, 197static int cbc_des_decrypt(struct blkcipher_desc *desc,
@@ -199,7 +201,7 @@ static int cbc_des_decrypt(struct blkcipher_desc *desc,
199 struct blkcipher_walk walk; 201 struct blkcipher_walk walk;
200 202
201 blkcipher_walk_init(&walk, dst, src, nbytes); 203 blkcipher_walk_init(&walk, dst, src, nbytes);
202 return cbc_desall_crypt(desc, CPACF_KMC_DEA_DEC, &walk); 204 return cbc_desall_crypt(desc, CPACF_KMC_DEA | CPACF_DECRYPT, &walk);
203} 205}
204 206
205static struct crypto_alg cbc_des_alg = { 207static struct crypto_alg cbc_des_alg = {
@@ -257,14 +259,15 @@ static void des3_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
257{ 259{
258 struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm); 260 struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
259 261
260 cpacf_km(CPACF_KM_TDEA_192_ENC, ctx->key, dst, src, DES_BLOCK_SIZE); 262 cpacf_km(CPACF_KM_TDEA_192, ctx->key, dst, src, DES_BLOCK_SIZE);
261} 263}
262 264
263static void des3_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 265static void des3_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
264{ 266{
265 struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm); 267 struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
266 268
267 cpacf_km(CPACF_KM_TDEA_192_DEC, ctx->key, dst, src, DES_BLOCK_SIZE); 269 cpacf_km(CPACF_KM_TDEA_192 | CPACF_DECRYPT,
270 ctx->key, dst, src, DES_BLOCK_SIZE);
268} 271}
269 272
270static struct crypto_alg des3_alg = { 273static struct crypto_alg des3_alg = {
@@ -294,7 +297,7 @@ static int ecb_des3_encrypt(struct blkcipher_desc *desc,
294 struct blkcipher_walk walk; 297 struct blkcipher_walk walk;
295 298
296 blkcipher_walk_init(&walk, dst, src, nbytes); 299 blkcipher_walk_init(&walk, dst, src, nbytes);
297 return ecb_desall_crypt(desc, CPACF_KM_TDEA_192_ENC, ctx->key, &walk); 300 return ecb_desall_crypt(desc, CPACF_KM_TDEA_192, ctx->key, &walk);
298} 301}
299 302
300static int ecb_des3_decrypt(struct blkcipher_desc *desc, 303static int ecb_des3_decrypt(struct blkcipher_desc *desc,
@@ -305,7 +308,8 @@ static int ecb_des3_decrypt(struct blkcipher_desc *desc,
305 struct blkcipher_walk walk; 308 struct blkcipher_walk walk;
306 309
307 blkcipher_walk_init(&walk, dst, src, nbytes); 310 blkcipher_walk_init(&walk, dst, src, nbytes);
308 return ecb_desall_crypt(desc, CPACF_KM_TDEA_192_DEC, ctx->key, &walk); 311 return ecb_desall_crypt(desc, CPACF_KM_TDEA_192 | CPACF_DECRYPT,
312 ctx->key, &walk);
309} 313}
310 314
311static struct crypto_alg ecb_des3_alg = { 315static struct crypto_alg ecb_des3_alg = {
@@ -335,7 +339,7 @@ static int cbc_des3_encrypt(struct blkcipher_desc *desc,
335 struct blkcipher_walk walk; 339 struct blkcipher_walk walk;
336 340
337 blkcipher_walk_init(&walk, dst, src, nbytes); 341 blkcipher_walk_init(&walk, dst, src, nbytes);
338 return cbc_desall_crypt(desc, CPACF_KMC_TDEA_192_ENC, &walk); 342 return cbc_desall_crypt(desc, CPACF_KMC_TDEA_192, &walk);
339} 343}
340 344
341static int cbc_des3_decrypt(struct blkcipher_desc *desc, 345static int cbc_des3_decrypt(struct blkcipher_desc *desc,
@@ -345,7 +349,8 @@ static int cbc_des3_decrypt(struct blkcipher_desc *desc,
345 struct blkcipher_walk walk; 349 struct blkcipher_walk walk;
346 350
347 blkcipher_walk_init(&walk, dst, src, nbytes); 351 blkcipher_walk_init(&walk, dst, src, nbytes);
348 return cbc_desall_crypt(desc, CPACF_KMC_TDEA_192_DEC, &walk); 352 return cbc_desall_crypt(desc, CPACF_KMC_TDEA_192 | CPACF_DECRYPT,
353 &walk);
349} 354}
350 355
351static struct crypto_alg cbc_des3_alg = { 356static struct crypto_alg cbc_des3_alg = {
@@ -456,7 +461,7 @@ static int ctr_des_encrypt(struct blkcipher_desc *desc,
456 struct blkcipher_walk walk; 461 struct blkcipher_walk walk;
457 462
458 blkcipher_walk_init(&walk, dst, src, nbytes); 463 blkcipher_walk_init(&walk, dst, src, nbytes);
459 return ctr_desall_crypt(desc, CPACF_KMCTR_DEA_ENC, ctx, &walk); 464 return ctr_desall_crypt(desc, CPACF_KMCTR_DEA, ctx, &walk);
460} 465}
461 466
462static int ctr_des_decrypt(struct blkcipher_desc *desc, 467static int ctr_des_decrypt(struct blkcipher_desc *desc,
@@ -467,7 +472,8 @@ static int ctr_des_decrypt(struct blkcipher_desc *desc,
467 struct blkcipher_walk walk; 472 struct blkcipher_walk walk;
468 473
469 blkcipher_walk_init(&walk, dst, src, nbytes); 474 blkcipher_walk_init(&walk, dst, src, nbytes);
470 return ctr_desall_crypt(desc, CPACF_KMCTR_DEA_DEC, ctx, &walk); 475 return ctr_desall_crypt(desc, CPACF_KMCTR_DEA | CPACF_DECRYPT,
476 ctx, &walk);
471} 477}
472 478
473static struct crypto_alg ctr_des_alg = { 479static struct crypto_alg ctr_des_alg = {
@@ -499,7 +505,7 @@ static int ctr_des3_encrypt(struct blkcipher_desc *desc,
499 struct blkcipher_walk walk; 505 struct blkcipher_walk walk;
500 506
501 blkcipher_walk_init(&walk, dst, src, nbytes); 507 blkcipher_walk_init(&walk, dst, src, nbytes);
502 return ctr_desall_crypt(desc, CPACF_KMCTR_TDEA_192_ENC, ctx, &walk); 508 return ctr_desall_crypt(desc, CPACF_KMCTR_TDEA_192, ctx, &walk);
503} 509}
504 510
505static int ctr_des3_decrypt(struct blkcipher_desc *desc, 511static int ctr_des3_decrypt(struct blkcipher_desc *desc,
@@ -510,7 +516,8 @@ static int ctr_des3_decrypt(struct blkcipher_desc *desc,
510 struct blkcipher_walk walk; 516 struct blkcipher_walk walk;
511 517
512 blkcipher_walk_init(&walk, dst, src, nbytes); 518 blkcipher_walk_init(&walk, dst, src, nbytes);
513 return ctr_desall_crypt(desc, CPACF_KMCTR_TDEA_192_DEC, ctx, &walk); 519 return ctr_desall_crypt(desc, CPACF_KMCTR_TDEA_192 | CPACF_DECRYPT,
520 ctx, &walk);
514} 521}
515 522
516static struct crypto_alg ctr_des3_alg = { 523static struct crypto_alg ctr_des3_alg = {
@@ -538,8 +545,8 @@ static int __init des_s390_init(void)
538{ 545{
539 int ret; 546 int ret;
540 547
541 if (!cpacf_query(CPACF_KM, CPACF_KM_DEA_ENC) || 548 if (!cpacf_query(CPACF_KM, CPACF_KM_DEA) ||
542 !cpacf_query(CPACF_KM, CPACF_KM_TDEA_192_ENC)) 549 !cpacf_query(CPACF_KM, CPACF_KM_TDEA_192))
543 return -EOPNOTSUPP; 550 return -EOPNOTSUPP;
544 551
545 ret = crypto_register_alg(&des_alg); 552 ret = crypto_register_alg(&des_alg);
@@ -561,8 +568,8 @@ static int __init des_s390_init(void)
561 if (ret) 568 if (ret)
562 goto cbc_des3_err; 569 goto cbc_des3_err;
563 570
564 if (cpacf_query(CPACF_KMCTR, CPACF_KMCTR_DEA_ENC) && 571 if (cpacf_query(CPACF_KMCTR, CPACF_KMCTR_DEA) &&
565 cpacf_query(CPACF_KMCTR, CPACF_KMCTR_TDEA_192_ENC)) { 572 cpacf_query(CPACF_KMCTR, CPACF_KMCTR_TDEA_192)) {
566 ret = crypto_register_alg(&ctr_des_alg); 573 ret = crypto_register_alg(&ctr_des_alg);
567 if (ret) 574 if (ret)
568 goto ctr_des_err; 575 goto ctr_des_err;
diff --git a/arch/s390/include/asm/cpacf.h b/arch/s390/include/asm/cpacf.h
index d28621de8e0b..ca884198805c 100644
--- a/arch/s390/include/asm/cpacf.h
+++ b/arch/s390/include/asm/cpacf.h
@@ -28,67 +28,51 @@
28#define CPACF_PPNO 0xb93c /* MSA5 */ 28#define CPACF_PPNO 0xb93c /* MSA5 */
29 29
30/* 30/*
31 * Function codes for the KM (CIPHER MESSAGE) 31 * Decryption modifier bit
32 * instruction (0x80 is the decipher modifier bit) 32 */
33#define CPACF_DECRYPT 0x80
34
35/*
36 * Function codes for the KM (CIPHER MESSAGE) instruction
33 */ 37 */
34#define CPACF_KM_QUERY 0x00 38#define CPACF_KM_QUERY 0x00
35#define CPACF_KM_DEA_ENC 0x01 39#define CPACF_KM_DEA 0x01
36#define CPACF_KM_DEA_DEC 0x81 40#define CPACF_KM_TDEA_128 0x02
37#define CPACF_KM_TDEA_128_ENC 0x02 41#define CPACF_KM_TDEA_192 0x03
38#define CPACF_KM_TDEA_128_DEC 0x82 42#define CPACF_KM_AES_128 0x12
39#define CPACF_KM_TDEA_192_ENC 0x03 43#define CPACF_KM_AES_192 0x13
40#define CPACF_KM_TDEA_192_DEC 0x83 44#define CPACF_KM_AES_256 0x14
41#define CPACF_KM_AES_128_ENC 0x12 45#define CPACF_KM_XTS_128 0x32
42#define CPACF_KM_AES_128_DEC 0x92 46#define CPACF_KM_XTS_256 0x34
43#define CPACF_KM_AES_192_ENC 0x13
44#define CPACF_KM_AES_192_DEC 0x93
45#define CPACF_KM_AES_256_ENC 0x14
46#define CPACF_KM_AES_256_DEC 0x94
47#define CPACF_KM_XTS_128_ENC 0x32
48#define CPACF_KM_XTS_128_DEC 0xb2
49#define CPACF_KM_XTS_256_ENC 0x34
50#define CPACF_KM_XTS_256_DEC 0xb4
51 47
52/* 48/*
53 * Function codes for the KMC (CIPHER MESSAGE WITH CHAINING) 49 * Function codes for the KMC (CIPHER MESSAGE WITH CHAINING)
54 * instruction (0x80 is the decipher modifier bit) 50 * instruction
55 */ 51 */
56#define CPACF_KMC_QUERY 0x00 52#define CPACF_KMC_QUERY 0x00
57#define CPACF_KMC_DEA_ENC 0x01 53#define CPACF_KMC_DEA 0x01
58#define CPACF_KMC_DEA_DEC 0x81 54#define CPACF_KMC_TDEA_128 0x02
59#define CPACF_KMC_TDEA_128_ENC 0x02 55#define CPACF_KMC_TDEA_192 0x03
60#define CPACF_KMC_TDEA_128_DEC 0x82 56#define CPACF_KMC_AES_128 0x12
61#define CPACF_KMC_TDEA_192_ENC 0x03 57#define CPACF_KMC_AES_192 0x13
62#define CPACF_KMC_TDEA_192_DEC 0x83 58#define CPACF_KMC_AES_256 0x14
63#define CPACF_KMC_AES_128_ENC 0x12
64#define CPACF_KMC_AES_128_DEC 0x92
65#define CPACF_KMC_AES_192_ENC 0x13
66#define CPACF_KMC_AES_192_DEC 0x93
67#define CPACF_KMC_AES_256_ENC 0x14
68#define CPACF_KMC_AES_256_DEC 0x94
69#define CPACF_KMC_PRNG 0x43 59#define CPACF_KMC_PRNG 0x43
70 60
71/* 61/*
72 * Function codes for the KMCTR (CIPHER MESSAGE WITH COUNTER) 62 * Function codes for the KMCTR (CIPHER MESSAGE WITH COUNTER)
73 * instruction (0x80 is the decipher modifier bit) 63 * instruction
74 */ 64 */
75#define CPACF_KMCTR_QUERY 0x00 65#define CPACF_KMCTR_QUERY 0x00
76#define CPACF_KMCTR_DEA_ENC 0x01 66#define CPACF_KMCTR_DEA 0x01
77#define CPACF_KMCTR_DEA_DEC 0x81 67#define CPACF_KMCTR_TDEA_128 0x02
78#define CPACF_KMCTR_TDEA_128_ENC 0x02 68#define CPACF_KMCTR_TDEA_192 0x03
79#define CPACF_KMCTR_TDEA_128_DEC 0x82 69#define CPACF_KMCTR_AES_128 0x12
80#define CPACF_KMCTR_TDEA_192_ENC 0x03 70#define CPACF_KMCTR_AES_192 0x13
81#define CPACF_KMCTR_TDEA_192_DEC 0x83 71#define CPACF_KMCTR_AES_256 0x14
82#define CPACF_KMCTR_AES_128_ENC 0x12
83#define CPACF_KMCTR_AES_128_DEC 0x92
84#define CPACF_KMCTR_AES_192_ENC 0x13
85#define CPACF_KMCTR_AES_192_DEC 0x93
86#define CPACF_KMCTR_AES_256_ENC 0x14
87#define CPACF_KMCTR_AES_256_DEC 0x94
88 72
89/* 73/*
90 * Function codes for the KIMD (COMPUTE INTERMEDIATE MESSAGE DIGEST) 74 * Function codes for the KIMD (COMPUTE INTERMEDIATE MESSAGE DIGEST)
91 * instruction (0x80 is the decipher modifier bit) 75 * instruction
92 */ 76 */
93#define CPACF_KIMD_QUERY 0x00 77#define CPACF_KIMD_QUERY 0x00
94#define CPACF_KIMD_SHA_1 0x01 78#define CPACF_KIMD_SHA_1 0x01
@@ -98,7 +82,7 @@
98 82
99/* 83/*
100 * Function codes for the KLMD (COMPUTE LAST MESSAGE DIGEST) 84 * Function codes for the KLMD (COMPUTE LAST MESSAGE DIGEST)
101 * instruction (0x80 is the decipher modifier bit) 85 * instruction
102 */ 86 */
103#define CPACF_KLMD_QUERY 0x00 87#define CPACF_KLMD_QUERY 0x00
104#define CPACF_KLMD_SHA_1 0x01 88#define CPACF_KLMD_SHA_1 0x01
@@ -107,7 +91,7 @@
107 91
108/* 92/*
109 * function codes for the KMAC (COMPUTE MESSAGE AUTHENTICATION CODE) 93 * function codes for the KMAC (COMPUTE MESSAGE AUTHENTICATION CODE)
110 * instruction (0x80 is the decipher modifier bit) 94 * instruction
111 */ 95 */
112#define CPACF_KMAC_QUERY 0x00 96#define CPACF_KMAC_QUERY 0x00
113#define CPACF_KMAC_DEA 0x01 97#define CPACF_KMAC_DEA 0x01
@@ -116,7 +100,7 @@
116 100
117/* 101/*
118 * Function codes for the PPNO (PERFORM PSEUDORANDOM NUMBER OPERATION) 102 * Function codes for the PPNO (PERFORM PSEUDORANDOM NUMBER OPERATION)
119 * instruction (0x80 is the decipher modifier bit) 103 * instruction
120 */ 104 */
121#define CPACF_PPNO_QUERY 0x00 105#define CPACF_PPNO_QUERY 0x00
122#define CPACF_PPNO_SHA512_DRNG_GEN 0x03 106#define CPACF_PPNO_SHA512_DRNG_GEN 0x03
@@ -194,7 +178,7 @@ static inline int cpacf_query(unsigned int opcode, unsigned int func)
194 * Returns 0 for the query func, number of processed bytes for 178 * Returns 0 for the query func, number of processed bytes for
195 * encryption/decryption funcs 179 * encryption/decryption funcs
196 */ 180 */
197static inline int cpacf_km(long func, void *param, 181static inline int cpacf_km(unsigned long func, void *param,
198 u8 *dest, const u8 *src, long src_len) 182 u8 *dest, const u8 *src, long src_len)
199{ 183{
200 register unsigned long r0 asm("0") = (unsigned long) func; 184 register unsigned long r0 asm("0") = (unsigned long) func;
@@ -224,7 +208,7 @@ static inline int cpacf_km(long func, void *param,
224 * Returns 0 for the query func, number of processed bytes for 208 * Returns 0 for the query func, number of processed bytes for
225 * encryption/decryption funcs 209 * encryption/decryption funcs
226 */ 210 */
227static inline int cpacf_kmc(long func, void *param, 211static inline int cpacf_kmc(unsigned long func, void *param,
228 u8 *dest, const u8 *src, long src_len) 212 u8 *dest, const u8 *src, long src_len)
229{ 213{
230 register unsigned long r0 asm("0") = (unsigned long) func; 214 register unsigned long r0 asm("0") = (unsigned long) func;
@@ -253,7 +237,7 @@ static inline int cpacf_kmc(long func, void *param,
253 * 237 *
254 * Returns 0 for the query func, number of processed bytes for digest funcs 238 * Returns 0 for the query func, number of processed bytes for digest funcs
255 */ 239 */
256static inline int cpacf_kimd(long func, void *param, 240static inline int cpacf_kimd(unsigned long func, void *param,
257 const u8 *src, long src_len) 241 const u8 *src, long src_len)
258{ 242{
259 register unsigned long r0 asm("0") = (unsigned long) func; 243 register unsigned long r0 asm("0") = (unsigned long) func;
@@ -280,7 +264,7 @@ static inline int cpacf_kimd(long func, void *param,
280 * 264 *
281 * Returns 0 for the query func, number of processed bytes for digest funcs 265 * Returns 0 for the query func, number of processed bytes for digest funcs
282 */ 266 */
283static inline int cpacf_klmd(long func, void *param, 267static inline int cpacf_klmd(unsigned long func, void *param,
284 const u8 *src, long src_len) 268 const u8 *src, long src_len)
285{ 269{
286 register unsigned long r0 asm("0") = (unsigned long) func; 270 register unsigned long r0 asm("0") = (unsigned long) func;
@@ -308,7 +292,7 @@ static inline int cpacf_klmd(long func, void *param,
308 * 292 *
309 * Returns 0 for the query func, number of processed bytes for digest funcs 293 * Returns 0 for the query func, number of processed bytes for digest funcs
310 */ 294 */
311static inline int cpacf_kmac(long func, void *param, 295static inline int cpacf_kmac(unsigned long func, void *param,
312 const u8 *src, long src_len) 296 const u8 *src, long src_len)
313{ 297{
314 register unsigned long r0 asm("0") = (unsigned long) func; 298 register unsigned long r0 asm("0") = (unsigned long) func;
@@ -338,7 +322,7 @@ static inline int cpacf_kmac(long func, void *param,
338 * Returns 0 for the query func, number of processed bytes for 322 * Returns 0 for the query func, number of processed bytes for
339 * encryption/decryption funcs 323 * encryption/decryption funcs
340 */ 324 */
341static inline int cpacf_kmctr(long func, void *param, u8 *dest, 325static inline int cpacf_kmctr(unsigned long func, void *param, u8 *dest,
342 const u8 *src, long src_len, u8 *counter) 326 const u8 *src, long src_len, u8 *counter)
343{ 327{
344 register unsigned long r0 asm("0") = (unsigned long) func; 328 register unsigned long r0 asm("0") = (unsigned long) func;
@@ -372,7 +356,7 @@ static inline int cpacf_kmctr(long func, void *param, u8 *dest,
372 * Returns 0 for the query func, number of random bytes stored in 356 * Returns 0 for the query func, number of random bytes stored in
373 * dest buffer for generate function 357 * dest buffer for generate function
374 */ 358 */
375static inline int cpacf_ppno(long func, void *param, 359static inline int cpacf_ppno(unsigned long func, void *param,
376 u8 *dest, long dest_len, 360 u8 *dest, long dest_len,
377 const u8 *seed, long seed_len) 361 const u8 *seed, long seed_len)
378{ 362{
@@ -402,7 +386,7 @@ static inline int cpacf_ppno(long func, void *param,
402 * 386 *
403 * Returns 0. 387 * Returns 0.
404 */ 388 */
405static inline int cpacf_pcc(long func, void *param) 389static inline int cpacf_pcc(unsigned long func, void *param)
406{ 390{
407 register unsigned long r0 asm("0") = (unsigned long) func; 391 register unsigned long r0 asm("0") = (unsigned long) func;
408 register unsigned long r1 asm("1") = (unsigned long) param; 392 register unsigned long r1 asm("1") = (unsigned long) param;