aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/s390/crypto/des_check_key.c132
-rw-r--r--arch/s390/crypto/des_s390.c199
2 files changed, 96 insertions, 235 deletions
diff --git a/arch/s390/crypto/des_check_key.c b/arch/s390/crypto/des_check_key.c
deleted file mode 100644
index 5706af26644..00000000000
--- a/arch/s390/crypto/des_check_key.c
+++ /dev/null
@@ -1,132 +0,0 @@
1/*
2 * Cryptographic API.
3 *
4 * Function for checking keys for the DES and Tripple DES Encryption
5 * algorithms.
6 *
7 * Originally released as descore by Dana L. How <how@isl.stanford.edu>.
8 * Modified by Raimar Falke <rf13@inf.tu-dresden.de> for the Linux-Kernel.
9 * Derived from Cryptoapi and Nettle implementations, adapted for in-place
10 * scatterlist interface. Changed LGPL to GPL per section 3 of the LGPL.
11 *
12 * s390 Version:
13 * Copyright IBM Corp. 2003
14 * Author(s): Thomas Spatzier
15 * Jan Glauber (jan.glauber@de.ibm.com)
16 *
17 * Derived from "crypto/des.c"
18 * Copyright (c) 1992 Dana L. How.
19 * Copyright (c) Raimar Falke <rf13@inf.tu-dresden.de>
20 * Copyright (c) Gisle Sflensminde <gisle@ii.uib.no>
21 * Copyright (C) 2001 Niels Mvller.
22 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
23 *
24 * This program is free software; you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation; either version 2 of the License, or
27 * (at your option) any later version.
28 *
29 */
30#include <linux/init.h>
31#include <linux/module.h>
32#include <linux/errno.h>
33#include <linux/crypto.h>
34#include "crypto_des.h"
35
36#define ROR(d,c,o) ((d) = (d) >> (c) | (d) << (o))
37
38static const u8 parity[] = {
39 8,1,0,8,0,8,8,0,0,8,8,0,8,0,2,8,0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,3,
40 0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8,
41 0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8,
42 8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8,0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,
43 0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8,
44 8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8,0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,
45 8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8,0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,
46 4,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,8,5,0,8,0,8,8,0,0,8,8,0,8,0,6,8,
47};
48
49/*
50 * RFC2451: Weak key checks SHOULD be performed.
51 */
52int
53crypto_des_check_key(const u8 *key, unsigned int keylen, u32 *flags)
54{
55 u32 n, w;
56
57 n = parity[key[0]]; n <<= 4;
58 n |= parity[key[1]]; n <<= 4;
59 n |= parity[key[2]]; n <<= 4;
60 n |= parity[key[3]]; n <<= 4;
61 n |= parity[key[4]]; n <<= 4;
62 n |= parity[key[5]]; n <<= 4;
63 n |= parity[key[6]]; n <<= 4;
64 n |= parity[key[7]];
65 w = 0x88888888L;
66
67 if ((*flags & CRYPTO_TFM_REQ_WEAK_KEY)
68 && !((n - (w >> 3)) & w)) { /* 1 in 10^10 keys passes this test */
69 if (n < 0x41415151) {
70 if (n < 0x31312121) {
71 if (n < 0x14141515) {
72 /* 01 01 01 01 01 01 01 01 */
73 if (n == 0x11111111) goto weak;
74 /* 01 1F 01 1F 01 0E 01 0E */
75 if (n == 0x13131212) goto weak;
76 } else {
77 /* 01 E0 01 E0 01 F1 01 F1 */
78 if (n == 0x14141515) goto weak;
79 /* 01 FE 01 FE 01 FE 01 FE */
80 if (n == 0x16161616) goto weak;
81 }
82 } else {
83 if (n < 0x34342525) {
84 /* 1F 01 1F 01 0E 01 0E 01 */
85 if (n == 0x31312121) goto weak;
86 /* 1F 1F 1F 1F 0E 0E 0E 0E (?) */
87 if (n == 0x33332222) goto weak;
88 } else {
89 /* 1F E0 1F E0 0E F1 0E F1 */
90 if (n == 0x34342525) goto weak;
91 /* 1F FE 1F FE 0E FE 0E FE */
92 if (n == 0x36362626) goto weak;
93 }
94 }
95 } else {
96 if (n < 0x61616161) {
97 if (n < 0x44445555) {
98 /* E0 01 E0 01 F1 01 F1 01 */
99 if (n == 0x41415151) goto weak;
100 /* E0 1F E0 1F F1 0E F1 0E */
101 if (n == 0x43435252) goto weak;
102 } else {
103 /* E0 E0 E0 E0 F1 F1 F1 F1 (?) */
104 if (n == 0x44445555) goto weak;
105 /* E0 FE E0 FE F1 FE F1 FE */
106 if (n == 0x46465656) goto weak;
107 }
108 } else {
109 if (n < 0x64646565) {
110 /* FE 01 FE 01 FE 01 FE 01 */
111 if (n == 0x61616161) goto weak;
112 /* FE 1F FE 1F FE 0E FE 0E */
113 if (n == 0x63636262) goto weak;
114 } else {
115 /* FE E0 FE E0 FE F1 FE F1 */
116 if (n == 0x64646565) goto weak;
117 /* FE FE FE FE FE FE FE FE */
118 if (n == 0x66666666) goto weak;
119 }
120 }
121 }
122 }
123 return 0;
124weak:
125 *flags |= CRYPTO_TFM_RES_WEAK_KEY;
126 return -EINVAL;
127}
128
129EXPORT_SYMBOL(crypto_des_check_key);
130
131MODULE_LICENSE("GPL");
132MODULE_DESCRIPTION("Key Check function for DES & DES3 Cipher Algorithms");
diff --git a/arch/s390/crypto/des_s390.c b/arch/s390/crypto/des_s390.c
index 1121e73115a..c36a01d70e0 100644
--- a/arch/s390/crypto/des_s390.c
+++ b/arch/s390/crypto/des_s390.c
@@ -22,22 +22,17 @@
22 22
23#include "crypt_s390.h" 23#include "crypt_s390.h"
24 24
25#define DES3_192_KEY_SIZE (3 * DES_KEY_SIZE) 25#define DES3_KEY_SIZE (3 * DES_KEY_SIZE)
26 26
27struct crypt_s390_des_ctx { 27struct s390_des_ctx {
28 u8 iv[DES_BLOCK_SIZE]; 28 u8 iv[DES_BLOCK_SIZE];
29 u8 key[DES_KEY_SIZE]; 29 u8 key[DES3_KEY_SIZE];
30};
31
32struct crypt_s390_des3_192_ctx {
33 u8 iv[DES_BLOCK_SIZE];
34 u8 key[DES3_192_KEY_SIZE];
35}; 30};
36 31
37static int des_setkey(struct crypto_tfm *tfm, const u8 *key, 32static int des_setkey(struct crypto_tfm *tfm, const u8 *key,
38 unsigned int keylen) 33 unsigned int key_len)
39{ 34{
40 struct crypt_s390_des_ctx *dctx = crypto_tfm_ctx(tfm); 35 struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
41 u32 *flags = &tfm->crt_flags; 36 u32 *flags = &tfm->crt_flags;
42 u32 tmp[DES_EXPKEY_WORDS]; 37 u32 tmp[DES_EXPKEY_WORDS];
43 38
@@ -47,22 +42,22 @@ static int des_setkey(struct crypto_tfm *tfm, const u8 *key,
47 return -EINVAL; 42 return -EINVAL;
48 } 43 }
49 44
50 memcpy(dctx->key, key, keylen); 45 memcpy(ctx->key, key, key_len);
51 return 0; 46 return 0;
52} 47}
53 48
54static void des_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) 49static void des_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
55{ 50{
56 struct crypt_s390_des_ctx *dctx = crypto_tfm_ctx(tfm); 51 struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
57 52
58 crypt_s390_km(KM_DEA_ENCRYPT, dctx->key, out, in, DES_BLOCK_SIZE); 53 crypt_s390_km(KM_DEA_ENCRYPT, ctx->key, out, in, DES_BLOCK_SIZE);
59} 54}
60 55
61static void des_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) 56static void des_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
62{ 57{
63 struct crypt_s390_des_ctx *dctx = crypto_tfm_ctx(tfm); 58 struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
64 59
65 crypt_s390_km(KM_DEA_DECRYPT, dctx->key, out, in, DES_BLOCK_SIZE); 60 crypt_s390_km(KM_DEA_DECRYPT, ctx->key, out, in, DES_BLOCK_SIZE);
66} 61}
67 62
68static struct crypto_alg des_alg = { 63static struct crypto_alg des_alg = {
@@ -71,7 +66,7 @@ static struct crypto_alg des_alg = {
71 .cra_priority = CRYPT_S390_PRIORITY, 66 .cra_priority = CRYPT_S390_PRIORITY,
72 .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 67 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
73 .cra_blocksize = DES_BLOCK_SIZE, 68 .cra_blocksize = DES_BLOCK_SIZE,
74 .cra_ctxsize = sizeof(struct crypt_s390_des_ctx), 69 .cra_ctxsize = sizeof(struct s390_des_ctx),
75 .cra_module = THIS_MODULE, 70 .cra_module = THIS_MODULE,
76 .cra_list = LIST_HEAD_INIT(des_alg.cra_list), 71 .cra_list = LIST_HEAD_INIT(des_alg.cra_list),
77 .cra_u = { 72 .cra_u = {
@@ -86,7 +81,7 @@ static struct crypto_alg des_alg = {
86}; 81};
87 82
88static int ecb_desall_crypt(struct blkcipher_desc *desc, long func, 83static int ecb_desall_crypt(struct blkcipher_desc *desc, long func,
89 void *param, struct blkcipher_walk *walk) 84 u8 *key, struct blkcipher_walk *walk)
90{ 85{
91 int ret = blkcipher_walk_virt(desc, walk); 86 int ret = blkcipher_walk_virt(desc, walk);
92 unsigned int nbytes; 87 unsigned int nbytes;
@@ -97,7 +92,7 @@ static int ecb_desall_crypt(struct blkcipher_desc *desc, long func,
97 u8 *out = walk->dst.virt.addr; 92 u8 *out = walk->dst.virt.addr;
98 u8 *in = walk->src.virt.addr; 93 u8 *in = walk->src.virt.addr;
99 94
100 ret = crypt_s390_km(func, param, out, in, n); 95 ret = crypt_s390_km(func, key, out, in, n);
101 BUG_ON((ret < 0) || (ret != n)); 96 BUG_ON((ret < 0) || (ret != n));
102 97
103 nbytes &= DES_BLOCK_SIZE - 1; 98 nbytes &= DES_BLOCK_SIZE - 1;
@@ -108,7 +103,7 @@ static int ecb_desall_crypt(struct blkcipher_desc *desc, long func,
108} 103}
109 104
110static int cbc_desall_crypt(struct blkcipher_desc *desc, long func, 105static int cbc_desall_crypt(struct blkcipher_desc *desc, long func,
111 void *param, struct blkcipher_walk *walk) 106 u8 *iv, struct blkcipher_walk *walk)
112{ 107{
113 int ret = blkcipher_walk_virt(desc, walk); 108 int ret = blkcipher_walk_virt(desc, walk);
114 unsigned int nbytes = walk->nbytes; 109 unsigned int nbytes = walk->nbytes;
@@ -116,20 +111,20 @@ static int cbc_desall_crypt(struct blkcipher_desc *desc, long func,
116 if (!nbytes) 111 if (!nbytes)
117 goto out; 112 goto out;
118 113
119 memcpy(param, walk->iv, DES_BLOCK_SIZE); 114 memcpy(iv, walk->iv, DES_BLOCK_SIZE);
120 do { 115 do {
121 /* only use complete blocks */ 116 /* only use complete blocks */
122 unsigned int n = nbytes & ~(DES_BLOCK_SIZE - 1); 117 unsigned int n = nbytes & ~(DES_BLOCK_SIZE - 1);
123 u8 *out = walk->dst.virt.addr; 118 u8 *out = walk->dst.virt.addr;
124 u8 *in = walk->src.virt.addr; 119 u8 *in = walk->src.virt.addr;
125 120
126 ret = crypt_s390_kmc(func, param, out, in, n); 121 ret = crypt_s390_kmc(func, iv, out, in, n);
127 BUG_ON((ret < 0) || (ret != n)); 122 BUG_ON((ret < 0) || (ret != n));
128 123
129 nbytes &= DES_BLOCK_SIZE - 1; 124 nbytes &= DES_BLOCK_SIZE - 1;
130 ret = blkcipher_walk_done(desc, walk, nbytes); 125 ret = blkcipher_walk_done(desc, walk, nbytes);
131 } while ((nbytes = walk->nbytes)); 126 } while ((nbytes = walk->nbytes));
132 memcpy(walk->iv, param, DES_BLOCK_SIZE); 127 memcpy(walk->iv, iv, DES_BLOCK_SIZE);
133 128
134out: 129out:
135 return ret; 130 return ret;
@@ -139,22 +134,22 @@ static int ecb_des_encrypt(struct blkcipher_desc *desc,
139 struct scatterlist *dst, struct scatterlist *src, 134 struct scatterlist *dst, struct scatterlist *src,
140 unsigned int nbytes) 135 unsigned int nbytes)
141{ 136{
142 struct crypt_s390_des_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); 137 struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
143 struct blkcipher_walk walk; 138 struct blkcipher_walk walk;
144 139
145 blkcipher_walk_init(&walk, dst, src, nbytes); 140 blkcipher_walk_init(&walk, dst, src, nbytes);
146 return ecb_desall_crypt(desc, KM_DEA_ENCRYPT, sctx->key, &walk); 141 return ecb_desall_crypt(desc, KM_DEA_ENCRYPT, ctx->key, &walk);
147} 142}
148 143
149static int ecb_des_decrypt(struct blkcipher_desc *desc, 144static int ecb_des_decrypt(struct blkcipher_desc *desc,
150 struct scatterlist *dst, struct scatterlist *src, 145 struct scatterlist *dst, struct scatterlist *src,
151 unsigned int nbytes) 146 unsigned int nbytes)
152{ 147{
153 struct crypt_s390_des_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); 148 struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
154 struct blkcipher_walk walk; 149 struct blkcipher_walk walk;
155 150
156 blkcipher_walk_init(&walk, dst, src, nbytes); 151 blkcipher_walk_init(&walk, dst, src, nbytes);
157 return ecb_desall_crypt(desc, KM_DEA_DECRYPT, sctx->key, &walk); 152 return ecb_desall_crypt(desc, KM_DEA_DECRYPT, ctx->key, &walk);
158} 153}
159 154
160static struct crypto_alg ecb_des_alg = { 155static struct crypto_alg ecb_des_alg = {
@@ -163,7 +158,7 @@ static struct crypto_alg ecb_des_alg = {
163 .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, 158 .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY,
164 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, 159 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
165 .cra_blocksize = DES_BLOCK_SIZE, 160 .cra_blocksize = DES_BLOCK_SIZE,
166 .cra_ctxsize = sizeof(struct crypt_s390_des_ctx), 161 .cra_ctxsize = sizeof(struct s390_des_ctx),
167 .cra_type = &crypto_blkcipher_type, 162 .cra_type = &crypto_blkcipher_type,
168 .cra_module = THIS_MODULE, 163 .cra_module = THIS_MODULE,
169 .cra_list = LIST_HEAD_INIT(ecb_des_alg.cra_list), 164 .cra_list = LIST_HEAD_INIT(ecb_des_alg.cra_list),
@@ -182,22 +177,22 @@ static int cbc_des_encrypt(struct blkcipher_desc *desc,
182 struct scatterlist *dst, struct scatterlist *src, 177 struct scatterlist *dst, struct scatterlist *src,
183 unsigned int nbytes) 178 unsigned int nbytes)
184{ 179{
185 struct crypt_s390_des_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); 180 struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
186 struct blkcipher_walk walk; 181 struct blkcipher_walk walk;
187 182
188 blkcipher_walk_init(&walk, dst, src, nbytes); 183 blkcipher_walk_init(&walk, dst, src, nbytes);
189 return cbc_desall_crypt(desc, KMC_DEA_ENCRYPT, sctx->iv, &walk); 184 return cbc_desall_crypt(desc, KMC_DEA_ENCRYPT, ctx->iv, &walk);
190} 185}
191 186
192static int cbc_des_decrypt(struct blkcipher_desc *desc, 187static int cbc_des_decrypt(struct blkcipher_desc *desc,
193 struct scatterlist *dst, struct scatterlist *src, 188 struct scatterlist *dst, struct scatterlist *src,
194 unsigned int nbytes) 189 unsigned int nbytes)
195{ 190{
196 struct crypt_s390_des_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); 191 struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
197 struct blkcipher_walk walk; 192 struct blkcipher_walk walk;
198 193
199 blkcipher_walk_init(&walk, dst, src, nbytes); 194 blkcipher_walk_init(&walk, dst, src, nbytes);
200 return cbc_desall_crypt(desc, KMC_DEA_DECRYPT, sctx->iv, &walk); 195 return cbc_desall_crypt(desc, KMC_DEA_DECRYPT, ctx->iv, &walk);
201} 196}
202 197
203static struct crypto_alg cbc_des_alg = { 198static struct crypto_alg cbc_des_alg = {
@@ -206,7 +201,7 @@ static struct crypto_alg cbc_des_alg = {
206 .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, 201 .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY,
207 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, 202 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
208 .cra_blocksize = DES_BLOCK_SIZE, 203 .cra_blocksize = DES_BLOCK_SIZE,
209 .cra_ctxsize = sizeof(struct crypt_s390_des_ctx), 204 .cra_ctxsize = sizeof(struct s390_des_ctx),
210 .cra_type = &crypto_blkcipher_type, 205 .cra_type = &crypto_blkcipher_type,
211 .cra_module = THIS_MODULE, 206 .cra_module = THIS_MODULE,
212 .cra_list = LIST_HEAD_INIT(cbc_des_alg.cra_list), 207 .cra_list = LIST_HEAD_INIT(cbc_des_alg.cra_list),
@@ -235,10 +230,10 @@ static struct crypto_alg cbc_des_alg = {
235 * property. 230 * property.
236 * 231 *
237 */ 232 */
238static int des3_192_setkey(struct crypto_tfm *tfm, const u8 *key, 233static int des3_setkey(struct crypto_tfm *tfm, const u8 *key,
239 unsigned int keylen) 234 unsigned int key_len)
240{ 235{
241 struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm); 236 struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
242 u32 *flags = &tfm->crt_flags; 237 u32 *flags = &tfm->crt_flags;
243 238
244 if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) && 239 if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) &&
@@ -248,136 +243,134 @@ static int des3_192_setkey(struct crypto_tfm *tfm, const u8 *key,
248 *flags |= CRYPTO_TFM_RES_WEAK_KEY; 243 *flags |= CRYPTO_TFM_RES_WEAK_KEY;
249 return -EINVAL; 244 return -EINVAL;
250 } 245 }
251 memcpy(dctx->key, key, keylen); 246 memcpy(ctx->key, key, key_len);
252 return 0; 247 return 0;
253} 248}
254 249
255static void des3_192_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 250static void des3_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
256{ 251{
257 struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm); 252 struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
258 253
259 crypt_s390_km(KM_TDEA_192_ENCRYPT, dctx->key, dst, (void*)src, 254 crypt_s390_km(KM_TDEA_192_ENCRYPT, ctx->key, dst, src, DES_BLOCK_SIZE);
260 DES_BLOCK_SIZE);
261} 255}
262 256
263static void des3_192_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 257static void des3_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
264{ 258{
265 struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm); 259 struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
266 260
267 crypt_s390_km(KM_TDEA_192_DECRYPT, dctx->key, dst, (void*)src, 261 crypt_s390_km(KM_TDEA_192_DECRYPT, ctx->key, dst, src, DES_BLOCK_SIZE);
268 DES_BLOCK_SIZE);
269} 262}
270 263
271static struct crypto_alg des3_192_alg = { 264static struct crypto_alg des3_alg = {
272 .cra_name = "des3_ede", 265 .cra_name = "des3_ede",
273 .cra_driver_name = "des3_ede-s390", 266 .cra_driver_name = "des3_ede-s390",
274 .cra_priority = CRYPT_S390_PRIORITY, 267 .cra_priority = CRYPT_S390_PRIORITY,
275 .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 268 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
276 .cra_blocksize = DES_BLOCK_SIZE, 269 .cra_blocksize = DES_BLOCK_SIZE,
277 .cra_ctxsize = sizeof(struct crypt_s390_des3_192_ctx), 270 .cra_ctxsize = sizeof(struct s390_des_ctx),
278 .cra_module = THIS_MODULE, 271 .cra_module = THIS_MODULE,
279 .cra_list = LIST_HEAD_INIT(des3_192_alg.cra_list), 272 .cra_list = LIST_HEAD_INIT(des3_alg.cra_list),
280 .cra_u = { 273 .cra_u = {
281 .cipher = { 274 .cipher = {
282 .cia_min_keysize = DES3_192_KEY_SIZE, 275 .cia_min_keysize = DES3_KEY_SIZE,
283 .cia_max_keysize = DES3_192_KEY_SIZE, 276 .cia_max_keysize = DES3_KEY_SIZE,
284 .cia_setkey = des3_192_setkey, 277 .cia_setkey = des3_setkey,
285 .cia_encrypt = des3_192_encrypt, 278 .cia_encrypt = des3_encrypt,
286 .cia_decrypt = des3_192_decrypt, 279 .cia_decrypt = des3_decrypt,
287 } 280 }
288 } 281 }
289}; 282};
290 283
291static int ecb_des3_192_encrypt(struct blkcipher_desc *desc, 284static int ecb_des3_encrypt(struct blkcipher_desc *desc,
292 struct scatterlist *dst, 285 struct scatterlist *dst, struct scatterlist *src,
293 struct scatterlist *src, unsigned int nbytes) 286 unsigned int nbytes)
294{ 287{
295 struct crypt_s390_des3_192_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); 288 struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
296 struct blkcipher_walk walk; 289 struct blkcipher_walk walk;
297 290
298 blkcipher_walk_init(&walk, dst, src, nbytes); 291 blkcipher_walk_init(&walk, dst, src, nbytes);
299 return ecb_desall_crypt(desc, KM_TDEA_192_ENCRYPT, sctx->key, &walk); 292 return ecb_desall_crypt(desc, KM_TDEA_192_ENCRYPT, ctx->key, &walk);
300} 293}
301 294
302static int ecb_des3_192_decrypt(struct blkcipher_desc *desc, 295static int ecb_des3_decrypt(struct blkcipher_desc *desc,
303 struct scatterlist *dst, 296 struct scatterlist *dst, struct scatterlist *src,
304 struct scatterlist *src, unsigned int nbytes) 297 unsigned int nbytes)
305{ 298{
306 struct crypt_s390_des3_192_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); 299 struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
307 struct blkcipher_walk walk; 300 struct blkcipher_walk walk;
308 301
309 blkcipher_walk_init(&walk, dst, src, nbytes); 302 blkcipher_walk_init(&walk, dst, src, nbytes);
310 return ecb_desall_crypt(desc, KM_TDEA_192_DECRYPT, sctx->key, &walk); 303 return ecb_desall_crypt(desc, KM_TDEA_192_DECRYPT, ctx->key, &walk);
311} 304}
312 305
313static struct crypto_alg ecb_des3_192_alg = { 306static struct crypto_alg ecb_des3_alg = {
314 .cra_name = "ecb(des3_ede)", 307 .cra_name = "ecb(des3_ede)",
315 .cra_driver_name = "ecb-des3_ede-s390", 308 .cra_driver_name = "ecb-des3_ede-s390",
316 .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, 309 .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY,
317 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, 310 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
318 .cra_blocksize = DES_BLOCK_SIZE, 311 .cra_blocksize = DES_BLOCK_SIZE,
319 .cra_ctxsize = sizeof(struct crypt_s390_des3_192_ctx), 312 .cra_ctxsize = sizeof(struct s390_des_ctx),
320 .cra_type = &crypto_blkcipher_type, 313 .cra_type = &crypto_blkcipher_type,
321 .cra_module = THIS_MODULE, 314 .cra_module = THIS_MODULE,
322 .cra_list = LIST_HEAD_INIT( 315 .cra_list = LIST_HEAD_INIT(
323 ecb_des3_192_alg.cra_list), 316 ecb_des3_alg.cra_list),
324 .cra_u = { 317 .cra_u = {
325 .blkcipher = { 318 .blkcipher = {
326 .min_keysize = DES3_192_KEY_SIZE, 319 .min_keysize = DES3_KEY_SIZE,
327 .max_keysize = DES3_192_KEY_SIZE, 320 .max_keysize = DES3_KEY_SIZE,
328 .setkey = des3_192_setkey, 321 .setkey = des3_setkey,
329 .encrypt = ecb_des3_192_encrypt, 322 .encrypt = ecb_des3_encrypt,
330 .decrypt = ecb_des3_192_decrypt, 323 .decrypt = ecb_des3_decrypt,
331 } 324 }
332 } 325 }
333}; 326};
334 327
335static int cbc_des3_192_encrypt(struct blkcipher_desc *desc, 328static int cbc_des3_encrypt(struct blkcipher_desc *desc,
336 struct scatterlist *dst, 329 struct scatterlist *dst, struct scatterlist *src,
337 struct scatterlist *src, unsigned int nbytes) 330 unsigned int nbytes)
338{ 331{
339 struct crypt_s390_des3_192_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); 332 struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
340 struct blkcipher_walk walk; 333 struct blkcipher_walk walk;
341 334
342 blkcipher_walk_init(&walk, dst, src, nbytes); 335 blkcipher_walk_init(&walk, dst, src, nbytes);
343 return cbc_desall_crypt(desc, KMC_TDEA_192_ENCRYPT, sctx->iv, &walk); 336 return cbc_desall_crypt(desc, KMC_TDEA_192_ENCRYPT, ctx->iv, &walk);
344} 337}
345 338
346static int cbc_des3_192_decrypt(struct blkcipher_desc *desc, 339static int cbc_des3_decrypt(struct blkcipher_desc *desc,
347 struct scatterlist *dst, 340 struct scatterlist *dst, struct scatterlist *src,
348 struct scatterlist *src, unsigned int nbytes) 341 unsigned int nbytes)
349{ 342{
350 struct crypt_s390_des3_192_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); 343 struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
351 struct blkcipher_walk walk; 344 struct blkcipher_walk walk;
352 345
353 blkcipher_walk_init(&walk, dst, src, nbytes); 346 blkcipher_walk_init(&walk, dst, src, nbytes);
354 return cbc_desall_crypt(desc, KMC_TDEA_192_DECRYPT, sctx->iv, &walk); 347 return cbc_desall_crypt(desc, KMC_TDEA_192_DECRYPT, ctx->iv, &walk);
355} 348}
356 349
357static struct crypto_alg cbc_des3_192_alg = { 350static struct crypto_alg cbc_des3_alg = {
358 .cra_name = "cbc(des3_ede)", 351 .cra_name = "cbc(des3_ede)",
359 .cra_driver_name = "cbc-des3_ede-s390", 352 .cra_driver_name = "cbc-des3_ede-s390",
360 .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, 353 .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY,
361 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, 354 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
362 .cra_blocksize = DES_BLOCK_SIZE, 355 .cra_blocksize = DES_BLOCK_SIZE,
363 .cra_ctxsize = sizeof(struct crypt_s390_des3_192_ctx), 356 .cra_ctxsize = sizeof(struct s390_des_ctx),
364 .cra_type = &crypto_blkcipher_type, 357 .cra_type = &crypto_blkcipher_type,
365 .cra_module = THIS_MODULE, 358 .cra_module = THIS_MODULE,
366 .cra_list = LIST_HEAD_INIT( 359 .cra_list = LIST_HEAD_INIT(
367 cbc_des3_192_alg.cra_list), 360 cbc_des3_alg.cra_list),
368 .cra_u = { 361 .cra_u = {
369 .blkcipher = { 362 .blkcipher = {
370 .min_keysize = DES3_192_KEY_SIZE, 363 .min_keysize = DES3_KEY_SIZE,
371 .max_keysize = DES3_192_KEY_SIZE, 364 .max_keysize = DES3_KEY_SIZE,
372 .ivsize = DES_BLOCK_SIZE, 365 .ivsize = DES_BLOCK_SIZE,
373 .setkey = des3_192_setkey, 366 .setkey = des3_setkey,
374 .encrypt = cbc_des3_192_encrypt, 367 .encrypt = cbc_des3_encrypt,
375 .decrypt = cbc_des3_192_decrypt, 368 .decrypt = cbc_des3_decrypt,
376 } 369 }
377 } 370 }
378}; 371};
379 372
380static int des_s390_init(void) 373static int __init des_s390_init(void)
381{ 374{
382 int ret; 375 int ret;
383 376
@@ -394,23 +387,23 @@ static int des_s390_init(void)
394 ret = crypto_register_alg(&cbc_des_alg); 387 ret = crypto_register_alg(&cbc_des_alg);
395 if (ret) 388 if (ret)
396 goto cbc_des_err; 389 goto cbc_des_err;
397 ret = crypto_register_alg(&des3_192_alg); 390 ret = crypto_register_alg(&des3_alg);
398 if (ret) 391 if (ret)
399 goto des3_192_err; 392 goto des3_err;
400 ret = crypto_register_alg(&ecb_des3_192_alg); 393 ret = crypto_register_alg(&ecb_des3_alg);
401 if (ret) 394 if (ret)
402 goto ecb_des3_192_err; 395 goto ecb_des3_err;
403 ret = crypto_register_alg(&cbc_des3_192_alg); 396 ret = crypto_register_alg(&cbc_des3_alg);
404 if (ret) 397 if (ret)
405 goto cbc_des3_192_err; 398 goto cbc_des3_err;
406out: 399out:
407 return ret; 400 return ret;
408 401
409cbc_des3_192_err: 402cbc_des3_err:
410 crypto_unregister_alg(&ecb_des3_192_alg); 403 crypto_unregister_alg(&ecb_des3_alg);
411ecb_des3_192_err: 404ecb_des3_err:
412 crypto_unregister_alg(&des3_192_alg); 405 crypto_unregister_alg(&des3_alg);
413des3_192_err: 406des3_err:
414 crypto_unregister_alg(&cbc_des_alg); 407 crypto_unregister_alg(&cbc_des_alg);
415cbc_des_err: 408cbc_des_err:
416 crypto_unregister_alg(&ecb_des_alg); 409 crypto_unregister_alg(&ecb_des_alg);
@@ -422,9 +415,9 @@ des_err:
422 415
423static void __exit des_s390_exit(void) 416static void __exit des_s390_exit(void)
424{ 417{
425 crypto_unregister_alg(&cbc_des3_192_alg); 418 crypto_unregister_alg(&cbc_des3_alg);
426 crypto_unregister_alg(&ecb_des3_192_alg); 419 crypto_unregister_alg(&ecb_des3_alg);
427 crypto_unregister_alg(&des3_192_alg); 420 crypto_unregister_alg(&des3_alg);
428 crypto_unregister_alg(&cbc_des_alg); 421 crypto_unregister_alg(&cbc_des_alg);
429 crypto_unregister_alg(&ecb_des_alg); 422 crypto_unregister_alg(&ecb_des_alg);
430 crypto_unregister_alg(&des_alg); 423 crypto_unregister_alg(&des_alg);