diff options
Diffstat (limited to 'arch/s390/crypto/des_s390.c')
-rw-r--r-- | arch/s390/crypto/des_s390.c | 559 |
1 files changed, 364 insertions, 195 deletions
diff --git a/arch/s390/crypto/des_s390.c b/arch/s390/crypto/des_s390.c index b3f7496a79b4..2aba04852fe3 100644 --- a/arch/s390/crypto/des_s390.c +++ b/arch/s390/crypto/des_s390.c | |||
@@ -13,9 +13,10 @@ | |||
13 | * (at your option) any later version. | 13 | * (at your option) any later version. |
14 | * | 14 | * |
15 | */ | 15 | */ |
16 | |||
17 | #include <crypto/algapi.h> | ||
16 | #include <linux/init.h> | 18 | #include <linux/init.h> |
17 | #include <linux/module.h> | 19 | #include <linux/module.h> |
18 | #include <linux/crypto.h> | ||
19 | 20 | ||
20 | #include "crypt_s390.h" | 21 | #include "crypt_s390.h" |
21 | #include "crypto_des.h" | 22 | #include "crypto_des.h" |
@@ -45,9 +46,10 @@ struct crypt_s390_des3_192_ctx { | |||
45 | }; | 46 | }; |
46 | 47 | ||
47 | static int des_setkey(struct crypto_tfm *tfm, const u8 *key, | 48 | static int des_setkey(struct crypto_tfm *tfm, const u8 *key, |
48 | unsigned int keylen, u32 *flags) | 49 | unsigned int keylen) |
49 | { | 50 | { |
50 | struct crypt_s390_des_ctx *dctx = crypto_tfm_ctx(tfm); | 51 | struct crypt_s390_des_ctx *dctx = crypto_tfm_ctx(tfm); |
52 | u32 *flags = &tfm->crt_flags; | ||
51 | int ret; | 53 | int ret; |
52 | 54 | ||
53 | /* test if key is valid (not a weak key) */ | 55 | /* test if key is valid (not a weak key) */ |
@@ -71,85 +73,159 @@ static void des_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) | |||
71 | crypt_s390_km(KM_DEA_DECRYPT, dctx->key, out, in, DES_BLOCK_SIZE); | 73 | crypt_s390_km(KM_DEA_DECRYPT, dctx->key, out, in, DES_BLOCK_SIZE); |
72 | } | 74 | } |
73 | 75 | ||
74 | static unsigned int des_encrypt_ecb(const struct cipher_desc *desc, u8 *out, | 76 | static struct crypto_alg des_alg = { |
75 | const u8 *in, unsigned int nbytes) | 77 | .cra_name = "des", |
78 | .cra_driver_name = "des-s390", | ||
79 | .cra_priority = CRYPT_S390_PRIORITY, | ||
80 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, | ||
81 | .cra_blocksize = DES_BLOCK_SIZE, | ||
82 | .cra_ctxsize = sizeof(struct crypt_s390_des_ctx), | ||
83 | .cra_module = THIS_MODULE, | ||
84 | .cra_list = LIST_HEAD_INIT(des_alg.cra_list), | ||
85 | .cra_u = { | ||
86 | .cipher = { | ||
87 | .cia_min_keysize = DES_KEY_SIZE, | ||
88 | .cia_max_keysize = DES_KEY_SIZE, | ||
89 | .cia_setkey = des_setkey, | ||
90 | .cia_encrypt = des_encrypt, | ||
91 | .cia_decrypt = des_decrypt, | ||
92 | } | ||
93 | } | ||
94 | }; | ||
95 | |||
96 | static int ecb_desall_crypt(struct blkcipher_desc *desc, long func, | ||
97 | void *param, struct blkcipher_walk *walk) | ||
76 | { | 98 | { |
77 | struct crypt_s390_des_ctx *sctx = crypto_tfm_ctx(desc->tfm); | 99 | int ret = blkcipher_walk_virt(desc, walk); |
78 | int ret; | 100 | unsigned int nbytes; |
101 | |||
102 | while ((nbytes = walk->nbytes)) { | ||
103 | /* only use complete blocks */ | ||
104 | unsigned int n = nbytes & ~(DES_BLOCK_SIZE - 1); | ||
105 | u8 *out = walk->dst.virt.addr; | ||
106 | u8 *in = walk->src.virt.addr; | ||
79 | 107 | ||
80 | /* only use complete blocks */ | 108 | ret = crypt_s390_km(func, param, out, in, n); |
81 | nbytes &= ~(DES_BLOCK_SIZE - 1); | 109 | BUG_ON((ret < 0) || (ret != n)); |
82 | ret = crypt_s390_km(KM_DEA_ENCRYPT, sctx->key, out, in, nbytes); | ||
83 | BUG_ON((ret < 0) || (ret != nbytes)); | ||
84 | 110 | ||
85 | return nbytes; | 111 | nbytes &= DES_BLOCK_SIZE - 1; |
112 | ret = blkcipher_walk_done(desc, walk, nbytes); | ||
113 | } | ||
114 | |||
115 | return ret; | ||
86 | } | 116 | } |
87 | 117 | ||
88 | static unsigned int des_decrypt_ecb(const struct cipher_desc *desc, u8 *out, | 118 | static int cbc_desall_crypt(struct blkcipher_desc *desc, long func, |
89 | const u8 *in, unsigned int nbytes) | 119 | void *param, struct blkcipher_walk *walk) |
90 | { | 120 | { |
91 | struct crypt_s390_des_ctx *sctx = crypto_tfm_ctx(desc->tfm); | 121 | int ret = blkcipher_walk_virt(desc, walk); |
92 | int ret; | 122 | unsigned int nbytes = walk->nbytes; |
123 | |||
124 | if (!nbytes) | ||
125 | goto out; | ||
126 | |||
127 | memcpy(param, walk->iv, DES_BLOCK_SIZE); | ||
128 | do { | ||
129 | /* only use complete blocks */ | ||
130 | unsigned int n = nbytes & ~(DES_BLOCK_SIZE - 1); | ||
131 | u8 *out = walk->dst.virt.addr; | ||
132 | u8 *in = walk->src.virt.addr; | ||
93 | 133 | ||
94 | /* only use complete blocks */ | 134 | ret = crypt_s390_kmc(func, param, out, in, n); |
95 | nbytes &= ~(DES_BLOCK_SIZE - 1); | 135 | BUG_ON((ret < 0) || (ret != n)); |
96 | ret = crypt_s390_km(KM_DEA_DECRYPT, sctx->key, out, in, nbytes); | ||
97 | BUG_ON((ret < 0) || (ret != nbytes)); | ||
98 | 136 | ||
99 | return nbytes; | 137 | nbytes &= DES_BLOCK_SIZE - 1; |
138 | ret = blkcipher_walk_done(desc, walk, nbytes); | ||
139 | } while ((nbytes = walk->nbytes)); | ||
140 | memcpy(walk->iv, param, DES_BLOCK_SIZE); | ||
141 | |||
142 | out: | ||
143 | return ret; | ||
100 | } | 144 | } |
101 | 145 | ||
102 | static unsigned int des_encrypt_cbc(const struct cipher_desc *desc, u8 *out, | 146 | static int ecb_des_encrypt(struct blkcipher_desc *desc, |
103 | const u8 *in, unsigned int nbytes) | 147 | struct scatterlist *dst, struct scatterlist *src, |
148 | unsigned int nbytes) | ||
104 | { | 149 | { |
105 | struct crypt_s390_des_ctx *sctx = crypto_tfm_ctx(desc->tfm); | 150 | struct crypt_s390_des_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); |
106 | int ret; | 151 | struct blkcipher_walk walk; |
107 | 152 | ||
108 | /* only use complete blocks */ | 153 | blkcipher_walk_init(&walk, dst, src, nbytes); |
109 | nbytes &= ~(DES_BLOCK_SIZE - 1); | 154 | return ecb_desall_crypt(desc, KM_DEA_ENCRYPT, sctx->key, &walk); |
155 | } | ||
110 | 156 | ||
111 | memcpy(sctx->iv, desc->info, DES_BLOCK_SIZE); | 157 | static int ecb_des_decrypt(struct blkcipher_desc *desc, |
112 | ret = crypt_s390_kmc(KMC_DEA_ENCRYPT, &sctx->iv, out, in, nbytes); | 158 | struct scatterlist *dst, struct scatterlist *src, |
113 | BUG_ON((ret < 0) || (ret != nbytes)); | 159 | unsigned int nbytes) |
160 | { | ||
161 | struct crypt_s390_des_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); | ||
162 | struct blkcipher_walk walk; | ||
114 | 163 | ||
115 | memcpy(desc->info, sctx->iv, DES_BLOCK_SIZE); | 164 | blkcipher_walk_init(&walk, dst, src, nbytes); |
116 | return nbytes; | 165 | return ecb_desall_crypt(desc, KM_DEA_DECRYPT, sctx->key, &walk); |
117 | } | 166 | } |
118 | 167 | ||
119 | static unsigned int des_decrypt_cbc(const struct cipher_desc *desc, u8 *out, | 168 | static struct crypto_alg ecb_des_alg = { |
120 | const u8 *in, unsigned int nbytes) | 169 | .cra_name = "ecb(des)", |
170 | .cra_driver_name = "ecb-des-s390", | ||
171 | .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, | ||
172 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | ||
173 | .cra_blocksize = DES_BLOCK_SIZE, | ||
174 | .cra_ctxsize = sizeof(struct crypt_s390_des_ctx), | ||
175 | .cra_type = &crypto_blkcipher_type, | ||
176 | .cra_module = THIS_MODULE, | ||
177 | .cra_list = LIST_HEAD_INIT(ecb_des_alg.cra_list), | ||
178 | .cra_u = { | ||
179 | .blkcipher = { | ||
180 | .min_keysize = DES_KEY_SIZE, | ||
181 | .max_keysize = DES_KEY_SIZE, | ||
182 | .setkey = des_setkey, | ||
183 | .encrypt = ecb_des_encrypt, | ||
184 | .decrypt = ecb_des_decrypt, | ||
185 | } | ||
186 | } | ||
187 | }; | ||
188 | |||
189 | static int cbc_des_encrypt(struct blkcipher_desc *desc, | ||
190 | struct scatterlist *dst, struct scatterlist *src, | ||
191 | unsigned int nbytes) | ||
121 | { | 192 | { |
122 | struct crypt_s390_des_ctx *sctx = crypto_tfm_ctx(desc->tfm); | 193 | struct crypt_s390_des_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); |
123 | int ret; | 194 | struct blkcipher_walk walk; |
124 | 195 | ||
125 | /* only use complete blocks */ | 196 | blkcipher_walk_init(&walk, dst, src, nbytes); |
126 | nbytes &= ~(DES_BLOCK_SIZE - 1); | 197 | return cbc_desall_crypt(desc, KMC_DEA_ENCRYPT, sctx->iv, &walk); |
198 | } | ||
127 | 199 | ||
128 | memcpy(&sctx->iv, desc->info, DES_BLOCK_SIZE); | 200 | static int cbc_des_decrypt(struct blkcipher_desc *desc, |
129 | ret = crypt_s390_kmc(KMC_DEA_DECRYPT, &sctx->iv, out, in, nbytes); | 201 | struct scatterlist *dst, struct scatterlist *src, |
130 | BUG_ON((ret < 0) || (ret != nbytes)); | 202 | unsigned int nbytes) |
203 | { | ||
204 | struct crypt_s390_des_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); | ||
205 | struct blkcipher_walk walk; | ||
131 | 206 | ||
132 | return nbytes; | 207 | blkcipher_walk_init(&walk, dst, src, nbytes); |
208 | return cbc_desall_crypt(desc, KMC_DEA_DECRYPT, sctx->iv, &walk); | ||
133 | } | 209 | } |
134 | 210 | ||
135 | static struct crypto_alg des_alg = { | 211 | static struct crypto_alg cbc_des_alg = { |
136 | .cra_name = "des", | 212 | .cra_name = "cbc(des)", |
137 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, | 213 | .cra_driver_name = "cbc-des-s390", |
214 | .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, | ||
215 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | ||
138 | .cra_blocksize = DES_BLOCK_SIZE, | 216 | .cra_blocksize = DES_BLOCK_SIZE, |
139 | .cra_ctxsize = sizeof(struct crypt_s390_des_ctx), | 217 | .cra_ctxsize = sizeof(struct crypt_s390_des_ctx), |
218 | .cra_type = &crypto_blkcipher_type, | ||
140 | .cra_module = THIS_MODULE, | 219 | .cra_module = THIS_MODULE, |
141 | .cra_list = LIST_HEAD_INIT(des_alg.cra_list), | 220 | .cra_list = LIST_HEAD_INIT(cbc_des_alg.cra_list), |
142 | .cra_u = { | 221 | .cra_u = { |
143 | .cipher = { | 222 | .blkcipher = { |
144 | .cia_min_keysize = DES_KEY_SIZE, | 223 | .min_keysize = DES_KEY_SIZE, |
145 | .cia_max_keysize = DES_KEY_SIZE, | 224 | .max_keysize = DES_KEY_SIZE, |
146 | .cia_setkey = des_setkey, | 225 | .ivsize = DES_BLOCK_SIZE, |
147 | .cia_encrypt = des_encrypt, | 226 | .setkey = des_setkey, |
148 | .cia_decrypt = des_decrypt, | 227 | .encrypt = cbc_des_encrypt, |
149 | .cia_encrypt_ecb = des_encrypt_ecb, | 228 | .decrypt = cbc_des_decrypt, |
150 | .cia_decrypt_ecb = des_decrypt_ecb, | ||
151 | .cia_encrypt_cbc = des_encrypt_cbc, | ||
152 | .cia_decrypt_cbc = des_decrypt_cbc, | ||
153 | } | 229 | } |
154 | } | 230 | } |
155 | }; | 231 | }; |
@@ -167,11 +243,12 @@ static struct crypto_alg des_alg = { | |||
167 | * | 243 | * |
168 | */ | 244 | */ |
169 | static int des3_128_setkey(struct crypto_tfm *tfm, const u8 *key, | 245 | static int des3_128_setkey(struct crypto_tfm *tfm, const u8 *key, |
170 | unsigned int keylen, u32 *flags) | 246 | unsigned int keylen) |
171 | { | 247 | { |
172 | int i, ret; | 248 | int i, ret; |
173 | struct crypt_s390_des3_128_ctx *dctx = crypto_tfm_ctx(tfm); | 249 | struct crypt_s390_des3_128_ctx *dctx = crypto_tfm_ctx(tfm); |
174 | const u8* temp_key = key; | 250 | const u8 *temp_key = key; |
251 | u32 *flags = &tfm->crt_flags; | ||
175 | 252 | ||
176 | if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE))) { | 253 | if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE))) { |
177 | *flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED; | 254 | *flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED; |
@@ -202,89 +279,111 @@ static void des3_128_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) | |||
202 | DES3_128_BLOCK_SIZE); | 279 | DES3_128_BLOCK_SIZE); |
203 | } | 280 | } |
204 | 281 | ||
205 | static unsigned int des3_128_encrypt_ecb(const struct cipher_desc *desc, | 282 | static struct crypto_alg des3_128_alg = { |
206 | u8 *out, const u8 *in, | 283 | .cra_name = "des3_ede128", |
207 | unsigned int nbytes) | 284 | .cra_driver_name = "des3_ede128-s390", |
208 | { | 285 | .cra_priority = CRYPT_S390_PRIORITY, |
209 | struct crypt_s390_des3_128_ctx *sctx = crypto_tfm_ctx(desc->tfm); | 286 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, |
210 | int ret; | 287 | .cra_blocksize = DES3_128_BLOCK_SIZE, |
288 | .cra_ctxsize = sizeof(struct crypt_s390_des3_128_ctx), | ||
289 | .cra_module = THIS_MODULE, | ||
290 | .cra_list = LIST_HEAD_INIT(des3_128_alg.cra_list), | ||
291 | .cra_u = { | ||
292 | .cipher = { | ||
293 | .cia_min_keysize = DES3_128_KEY_SIZE, | ||
294 | .cia_max_keysize = DES3_128_KEY_SIZE, | ||
295 | .cia_setkey = des3_128_setkey, | ||
296 | .cia_encrypt = des3_128_encrypt, | ||
297 | .cia_decrypt = des3_128_decrypt, | ||
298 | } | ||
299 | } | ||
300 | }; | ||
211 | 301 | ||
212 | /* only use complete blocks */ | 302 | static int ecb_des3_128_encrypt(struct blkcipher_desc *desc, |
213 | nbytes &= ~(DES3_128_BLOCK_SIZE - 1); | 303 | struct scatterlist *dst, |
214 | ret = crypt_s390_km(KM_TDEA_128_ENCRYPT, sctx->key, out, in, nbytes); | 304 | struct scatterlist *src, unsigned int nbytes) |
215 | BUG_ON((ret < 0) || (ret != nbytes)); | 305 | { |
306 | struct crypt_s390_des3_128_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); | ||
307 | struct blkcipher_walk walk; | ||
216 | 308 | ||
217 | return nbytes; | 309 | blkcipher_walk_init(&walk, dst, src, nbytes); |
310 | return ecb_desall_crypt(desc, KM_TDEA_128_ENCRYPT, sctx->key, &walk); | ||
218 | } | 311 | } |
219 | 312 | ||
220 | static unsigned int des3_128_decrypt_ecb(const struct cipher_desc *desc, | 313 | static int ecb_des3_128_decrypt(struct blkcipher_desc *desc, |
221 | u8 *out, const u8 *in, | 314 | struct scatterlist *dst, |
222 | unsigned int nbytes) | 315 | struct scatterlist *src, unsigned int nbytes) |
223 | { | 316 | { |
224 | struct crypt_s390_des3_128_ctx *sctx = crypto_tfm_ctx(desc->tfm); | 317 | struct crypt_s390_des3_128_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); |
225 | int ret; | 318 | struct blkcipher_walk walk; |
226 | 319 | ||
227 | /* only use complete blocks */ | 320 | blkcipher_walk_init(&walk, dst, src, nbytes); |
228 | nbytes &= ~(DES3_128_BLOCK_SIZE - 1); | 321 | return ecb_desall_crypt(desc, KM_TDEA_128_DECRYPT, sctx->key, &walk); |
229 | ret = crypt_s390_km(KM_TDEA_128_DECRYPT, sctx->key, out, in, nbytes); | ||
230 | BUG_ON((ret < 0) || (ret != nbytes)); | ||
231 | |||
232 | return nbytes; | ||
233 | } | 322 | } |
234 | 323 | ||
235 | static unsigned int des3_128_encrypt_cbc(const struct cipher_desc *desc, | 324 | static struct crypto_alg ecb_des3_128_alg = { |
236 | u8 *out, const u8 *in, | 325 | .cra_name = "ecb(des3_ede128)", |
237 | unsigned int nbytes) | 326 | .cra_driver_name = "ecb-des3_ede128-s390", |
238 | { | 327 | .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, |
239 | struct crypt_s390_des3_128_ctx *sctx = crypto_tfm_ctx(desc->tfm); | 328 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, |
240 | int ret; | 329 | .cra_blocksize = DES3_128_BLOCK_SIZE, |
241 | 330 | .cra_ctxsize = sizeof(struct crypt_s390_des3_128_ctx), | |
242 | /* only use complete blocks */ | 331 | .cra_type = &crypto_blkcipher_type, |
243 | nbytes &= ~(DES3_128_BLOCK_SIZE - 1); | 332 | .cra_module = THIS_MODULE, |
333 | .cra_list = LIST_HEAD_INIT( | ||
334 | ecb_des3_128_alg.cra_list), | ||
335 | .cra_u = { | ||
336 | .blkcipher = { | ||
337 | .min_keysize = DES3_128_KEY_SIZE, | ||
338 | .max_keysize = DES3_128_KEY_SIZE, | ||
339 | .setkey = des3_128_setkey, | ||
340 | .encrypt = ecb_des3_128_encrypt, | ||
341 | .decrypt = ecb_des3_128_decrypt, | ||
342 | } | ||
343 | } | ||
344 | }; | ||
244 | 345 | ||
245 | memcpy(sctx->iv, desc->info, DES3_128_BLOCK_SIZE); | 346 | static int cbc_des3_128_encrypt(struct blkcipher_desc *desc, |
246 | ret = crypt_s390_kmc(KMC_TDEA_128_ENCRYPT, &sctx->iv, out, in, nbytes); | 347 | struct scatterlist *dst, |
247 | BUG_ON((ret < 0) || (ret != nbytes)); | 348 | struct scatterlist *src, unsigned int nbytes) |
349 | { | ||
350 | struct crypt_s390_des3_128_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); | ||
351 | struct blkcipher_walk walk; | ||
248 | 352 | ||
249 | memcpy(desc->info, sctx->iv, DES3_128_BLOCK_SIZE); | 353 | blkcipher_walk_init(&walk, dst, src, nbytes); |
250 | return nbytes; | 354 | return cbc_desall_crypt(desc, KMC_TDEA_128_ENCRYPT, sctx->iv, &walk); |
251 | } | 355 | } |
252 | 356 | ||
253 | static unsigned int des3_128_decrypt_cbc(const struct cipher_desc *desc, | 357 | static int cbc_des3_128_decrypt(struct blkcipher_desc *desc, |
254 | u8 *out, const u8 *in, | 358 | struct scatterlist *dst, |
255 | unsigned int nbytes) | 359 | struct scatterlist *src, unsigned int nbytes) |
256 | { | 360 | { |
257 | struct crypt_s390_des3_128_ctx *sctx = crypto_tfm_ctx(desc->tfm); | 361 | struct crypt_s390_des3_128_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); |
258 | int ret; | 362 | struct blkcipher_walk walk; |
259 | |||
260 | /* only use complete blocks */ | ||
261 | nbytes &= ~(DES3_128_BLOCK_SIZE - 1); | ||
262 | |||
263 | memcpy(&sctx->iv, desc->info, DES3_128_BLOCK_SIZE); | ||
264 | ret = crypt_s390_kmc(KMC_TDEA_128_DECRYPT, &sctx->iv, out, in, nbytes); | ||
265 | BUG_ON((ret < 0) || (ret != nbytes)); | ||
266 | 363 | ||
267 | return nbytes; | 364 | blkcipher_walk_init(&walk, dst, src, nbytes); |
365 | return cbc_desall_crypt(desc, KMC_TDEA_128_DECRYPT, sctx->iv, &walk); | ||
268 | } | 366 | } |
269 | 367 | ||
270 | static struct crypto_alg des3_128_alg = { | 368 | static struct crypto_alg cbc_des3_128_alg = { |
271 | .cra_name = "des3_ede128", | 369 | .cra_name = "cbc(des3_ede128)", |
272 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, | 370 | .cra_driver_name = "cbc-des3_ede128-s390", |
371 | .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, | ||
372 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | ||
273 | .cra_blocksize = DES3_128_BLOCK_SIZE, | 373 | .cra_blocksize = DES3_128_BLOCK_SIZE, |
274 | .cra_ctxsize = sizeof(struct crypt_s390_des3_128_ctx), | 374 | .cra_ctxsize = sizeof(struct crypt_s390_des3_128_ctx), |
375 | .cra_type = &crypto_blkcipher_type, | ||
275 | .cra_module = THIS_MODULE, | 376 | .cra_module = THIS_MODULE, |
276 | .cra_list = LIST_HEAD_INIT(des3_128_alg.cra_list), | 377 | .cra_list = LIST_HEAD_INIT( |
378 | cbc_des3_128_alg.cra_list), | ||
277 | .cra_u = { | 379 | .cra_u = { |
278 | .cipher = { | 380 | .blkcipher = { |
279 | .cia_min_keysize = DES3_128_KEY_SIZE, | 381 | .min_keysize = DES3_128_KEY_SIZE, |
280 | .cia_max_keysize = DES3_128_KEY_SIZE, | 382 | .max_keysize = DES3_128_KEY_SIZE, |
281 | .cia_setkey = des3_128_setkey, | 383 | .ivsize = DES3_128_BLOCK_SIZE, |
282 | .cia_encrypt = des3_128_encrypt, | 384 | .setkey = des3_128_setkey, |
283 | .cia_decrypt = des3_128_decrypt, | 385 | .encrypt = cbc_des3_128_encrypt, |
284 | .cia_encrypt_ecb = des3_128_encrypt_ecb, | 386 | .decrypt = cbc_des3_128_decrypt, |
285 | .cia_decrypt_ecb = des3_128_decrypt_ecb, | ||
286 | .cia_encrypt_cbc = des3_128_encrypt_cbc, | ||
287 | .cia_decrypt_cbc = des3_128_decrypt_cbc, | ||
288 | } | 387 | } |
289 | } | 388 | } |
290 | }; | 389 | }; |
@@ -303,11 +402,12 @@ static struct crypto_alg des3_128_alg = { | |||
303 | * | 402 | * |
304 | */ | 403 | */ |
305 | static int des3_192_setkey(struct crypto_tfm *tfm, const u8 *key, | 404 | static int des3_192_setkey(struct crypto_tfm *tfm, const u8 *key, |
306 | unsigned int keylen, u32 *flags) | 405 | unsigned int keylen) |
307 | { | 406 | { |
308 | int i, ret; | 407 | int i, ret; |
309 | struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm); | 408 | struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm); |
310 | const u8* temp_key = key; | 409 | const u8 *temp_key = key; |
410 | u32 *flags = &tfm->crt_flags; | ||
311 | 411 | ||
312 | if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) && | 412 | if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) && |
313 | memcmp(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2], | 413 | memcmp(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2], |
@@ -341,89 +441,111 @@ static void des3_192_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) | |||
341 | DES3_192_BLOCK_SIZE); | 441 | DES3_192_BLOCK_SIZE); |
342 | } | 442 | } |
343 | 443 | ||
344 | static unsigned int des3_192_encrypt_ecb(const struct cipher_desc *desc, | 444 | static struct crypto_alg des3_192_alg = { |
345 | u8 *out, const u8 *in, | 445 | .cra_name = "des3_ede", |
346 | unsigned int nbytes) | 446 | .cra_driver_name = "des3_ede-s390", |
347 | { | 447 | .cra_priority = CRYPT_S390_PRIORITY, |
348 | struct crypt_s390_des3_192_ctx *sctx = crypto_tfm_ctx(desc->tfm); | 448 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, |
349 | int ret; | 449 | .cra_blocksize = DES3_192_BLOCK_SIZE, |
450 | .cra_ctxsize = sizeof(struct crypt_s390_des3_192_ctx), | ||
451 | .cra_module = THIS_MODULE, | ||
452 | .cra_list = LIST_HEAD_INIT(des3_192_alg.cra_list), | ||
453 | .cra_u = { | ||
454 | .cipher = { | ||
455 | .cia_min_keysize = DES3_192_KEY_SIZE, | ||
456 | .cia_max_keysize = DES3_192_KEY_SIZE, | ||
457 | .cia_setkey = des3_192_setkey, | ||
458 | .cia_encrypt = des3_192_encrypt, | ||
459 | .cia_decrypt = des3_192_decrypt, | ||
460 | } | ||
461 | } | ||
462 | }; | ||
350 | 463 | ||
351 | /* only use complete blocks */ | 464 | static int ecb_des3_192_encrypt(struct blkcipher_desc *desc, |
352 | nbytes &= ~(DES3_192_BLOCK_SIZE - 1); | 465 | struct scatterlist *dst, |
353 | ret = crypt_s390_km(KM_TDEA_192_ENCRYPT, sctx->key, out, in, nbytes); | 466 | struct scatterlist *src, unsigned int nbytes) |
354 | BUG_ON((ret < 0) || (ret != nbytes)); | 467 | { |
468 | struct crypt_s390_des3_192_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); | ||
469 | struct blkcipher_walk walk; | ||
355 | 470 | ||
356 | return nbytes; | 471 | blkcipher_walk_init(&walk, dst, src, nbytes); |
472 | return ecb_desall_crypt(desc, KM_TDEA_192_ENCRYPT, sctx->key, &walk); | ||
357 | } | 473 | } |
358 | 474 | ||
359 | static unsigned int des3_192_decrypt_ecb(const struct cipher_desc *desc, | 475 | static int ecb_des3_192_decrypt(struct blkcipher_desc *desc, |
360 | u8 *out, const u8 *in, | 476 | struct scatterlist *dst, |
361 | unsigned int nbytes) | 477 | struct scatterlist *src, unsigned int nbytes) |
362 | { | 478 | { |
363 | struct crypt_s390_des3_192_ctx *sctx = crypto_tfm_ctx(desc->tfm); | 479 | struct crypt_s390_des3_192_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); |
364 | int ret; | 480 | struct blkcipher_walk walk; |
365 | |||
366 | /* only use complete blocks */ | ||
367 | nbytes &= ~(DES3_192_BLOCK_SIZE - 1); | ||
368 | ret = crypt_s390_km(KM_TDEA_192_DECRYPT, sctx->key, out, in, nbytes); | ||
369 | BUG_ON((ret < 0) || (ret != nbytes)); | ||
370 | 481 | ||
371 | return nbytes; | 482 | blkcipher_walk_init(&walk, dst, src, nbytes); |
483 | return ecb_desall_crypt(desc, KM_TDEA_192_DECRYPT, sctx->key, &walk); | ||
372 | } | 484 | } |
373 | 485 | ||
374 | static unsigned int des3_192_encrypt_cbc(const struct cipher_desc *desc, | 486 | static struct crypto_alg ecb_des3_192_alg = { |
375 | u8 *out, const u8 *in, | 487 | .cra_name = "ecb(des3_ede)", |
376 | unsigned int nbytes) | 488 | .cra_driver_name = "ecb-des3_ede-s390", |
377 | { | 489 | .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, |
378 | struct crypt_s390_des3_192_ctx *sctx = crypto_tfm_ctx(desc->tfm); | 490 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, |
379 | int ret; | 491 | .cra_blocksize = DES3_192_BLOCK_SIZE, |
380 | 492 | .cra_ctxsize = sizeof(struct crypt_s390_des3_192_ctx), | |
381 | /* only use complete blocks */ | 493 | .cra_type = &crypto_blkcipher_type, |
382 | nbytes &= ~(DES3_192_BLOCK_SIZE - 1); | 494 | .cra_module = THIS_MODULE, |
495 | .cra_list = LIST_HEAD_INIT( | ||
496 | ecb_des3_192_alg.cra_list), | ||
497 | .cra_u = { | ||
498 | .blkcipher = { | ||
499 | .min_keysize = DES3_192_KEY_SIZE, | ||
500 | .max_keysize = DES3_192_KEY_SIZE, | ||
501 | .setkey = des3_192_setkey, | ||
502 | .encrypt = ecb_des3_192_encrypt, | ||
503 | .decrypt = ecb_des3_192_decrypt, | ||
504 | } | ||
505 | } | ||
506 | }; | ||
383 | 507 | ||
384 | memcpy(sctx->iv, desc->info, DES3_192_BLOCK_SIZE); | 508 | static int cbc_des3_192_encrypt(struct blkcipher_desc *desc, |
385 | ret = crypt_s390_kmc(KMC_TDEA_192_ENCRYPT, &sctx->iv, out, in, nbytes); | 509 | struct scatterlist *dst, |
386 | BUG_ON((ret < 0) || (ret != nbytes)); | 510 | struct scatterlist *src, unsigned int nbytes) |
511 | { | ||
512 | struct crypt_s390_des3_192_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); | ||
513 | struct blkcipher_walk walk; | ||
387 | 514 | ||
388 | memcpy(desc->info, sctx->iv, DES3_192_BLOCK_SIZE); | 515 | blkcipher_walk_init(&walk, dst, src, nbytes); |
389 | return nbytes; | 516 | return cbc_desall_crypt(desc, KMC_TDEA_192_ENCRYPT, sctx->iv, &walk); |
390 | } | 517 | } |
391 | 518 | ||
392 | static unsigned int des3_192_decrypt_cbc(const struct cipher_desc *desc, | 519 | static int cbc_des3_192_decrypt(struct blkcipher_desc *desc, |
393 | u8 *out, const u8 *in, | 520 | struct scatterlist *dst, |
394 | unsigned int nbytes) | 521 | struct scatterlist *src, unsigned int nbytes) |
395 | { | 522 | { |
396 | struct crypt_s390_des3_192_ctx *sctx = crypto_tfm_ctx(desc->tfm); | 523 | struct crypt_s390_des3_192_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); |
397 | int ret; | 524 | struct blkcipher_walk walk; |
398 | 525 | ||
399 | /* only use complete blocks */ | 526 | blkcipher_walk_init(&walk, dst, src, nbytes); |
400 | nbytes &= ~(DES3_192_BLOCK_SIZE - 1); | 527 | return cbc_desall_crypt(desc, KMC_TDEA_192_DECRYPT, sctx->iv, &walk); |
401 | |||
402 | memcpy(&sctx->iv, desc->info, DES3_192_BLOCK_SIZE); | ||
403 | ret = crypt_s390_kmc(KMC_TDEA_192_DECRYPT, &sctx->iv, out, in, nbytes); | ||
404 | BUG_ON((ret < 0) || (ret != nbytes)); | ||
405 | |||
406 | return nbytes; | ||
407 | } | 528 | } |
408 | 529 | ||
409 | static struct crypto_alg des3_192_alg = { | 530 | static struct crypto_alg cbc_des3_192_alg = { |
410 | .cra_name = "des3_ede", | 531 | .cra_name = "cbc(des3_ede)", |
411 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, | 532 | .cra_driver_name = "cbc-des3_ede-s390", |
533 | .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY, | ||
534 | .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, | ||
412 | .cra_blocksize = DES3_192_BLOCK_SIZE, | 535 | .cra_blocksize = DES3_192_BLOCK_SIZE, |
413 | .cra_ctxsize = sizeof(struct crypt_s390_des3_192_ctx), | 536 | .cra_ctxsize = sizeof(struct crypt_s390_des3_192_ctx), |
537 | .cra_type = &crypto_blkcipher_type, | ||
414 | .cra_module = THIS_MODULE, | 538 | .cra_module = THIS_MODULE, |
415 | .cra_list = LIST_HEAD_INIT(des3_192_alg.cra_list), | 539 | .cra_list = LIST_HEAD_INIT( |
540 | cbc_des3_192_alg.cra_list), | ||
416 | .cra_u = { | 541 | .cra_u = { |
417 | .cipher = { | 542 | .blkcipher = { |
418 | .cia_min_keysize = DES3_192_KEY_SIZE, | 543 | .min_keysize = DES3_192_KEY_SIZE, |
419 | .cia_max_keysize = DES3_192_KEY_SIZE, | 544 | .max_keysize = DES3_192_KEY_SIZE, |
420 | .cia_setkey = des3_192_setkey, | 545 | .ivsize = DES3_192_BLOCK_SIZE, |
421 | .cia_encrypt = des3_192_encrypt, | 546 | .setkey = des3_192_setkey, |
422 | .cia_decrypt = des3_192_decrypt, | 547 | .encrypt = cbc_des3_192_encrypt, |
423 | .cia_encrypt_ecb = des3_192_encrypt_ecb, | 548 | .decrypt = cbc_des3_192_decrypt, |
424 | .cia_decrypt_ecb = des3_192_decrypt_ecb, | ||
425 | .cia_encrypt_cbc = des3_192_encrypt_cbc, | ||
426 | .cia_decrypt_cbc = des3_192_decrypt_cbc, | ||
427 | } | 549 | } |
428 | } | 550 | } |
429 | }; | 551 | }; |
@@ -437,22 +559,69 @@ static int init(void) | |||
437 | !crypt_s390_func_available(KM_TDEA_192_ENCRYPT)) | 559 | !crypt_s390_func_available(KM_TDEA_192_ENCRYPT)) |
438 | return -ENOSYS; | 560 | return -ENOSYS; |
439 | 561 | ||
440 | ret |= (crypto_register_alg(&des_alg) == 0) ? 0:1; | 562 | ret = crypto_register_alg(&des_alg); |
441 | ret |= (crypto_register_alg(&des3_128_alg) == 0) ? 0:2; | 563 | if (ret) |
442 | ret |= (crypto_register_alg(&des3_192_alg) == 0) ? 0:4; | 564 | goto des_err; |
443 | if (ret) { | 565 | ret = crypto_register_alg(&ecb_des_alg); |
444 | crypto_unregister_alg(&des3_192_alg); | 566 | if (ret) |
445 | crypto_unregister_alg(&des3_128_alg); | 567 | goto ecb_des_err; |
446 | crypto_unregister_alg(&des_alg); | 568 | ret = crypto_register_alg(&cbc_des_alg); |
447 | return -EEXIST; | 569 | if (ret) |
448 | } | 570 | goto cbc_des_err; |
449 | return 0; | 571 | |
572 | ret = crypto_register_alg(&des3_128_alg); | ||
573 | if (ret) | ||
574 | goto des3_128_err; | ||
575 | ret = crypto_register_alg(&ecb_des3_128_alg); | ||
576 | if (ret) | ||
577 | goto ecb_des3_128_err; | ||
578 | ret = crypto_register_alg(&cbc_des3_128_alg); | ||
579 | if (ret) | ||
580 | goto cbc_des3_128_err; | ||
581 | |||
582 | ret = crypto_register_alg(&des3_192_alg); | ||
583 | if (ret) | ||
584 | goto des3_192_err; | ||
585 | ret = crypto_register_alg(&ecb_des3_192_alg); | ||
586 | if (ret) | ||
587 | goto ecb_des3_192_err; | ||
588 | ret = crypto_register_alg(&cbc_des3_192_alg); | ||
589 | if (ret) | ||
590 | goto cbc_des3_192_err; | ||
591 | |||
592 | out: | ||
593 | return ret; | ||
594 | |||
595 | cbc_des3_192_err: | ||
596 | crypto_unregister_alg(&ecb_des3_192_alg); | ||
597 | ecb_des3_192_err: | ||
598 | crypto_unregister_alg(&des3_192_alg); | ||
599 | des3_192_err: | ||
600 | crypto_unregister_alg(&cbc_des3_128_alg); | ||
601 | cbc_des3_128_err: | ||
602 | crypto_unregister_alg(&ecb_des3_128_alg); | ||
603 | ecb_des3_128_err: | ||
604 | crypto_unregister_alg(&des3_128_alg); | ||
605 | des3_128_err: | ||
606 | crypto_unregister_alg(&cbc_des_alg); | ||
607 | cbc_des_err: | ||
608 | crypto_unregister_alg(&ecb_des_alg); | ||
609 | ecb_des_err: | ||
610 | crypto_unregister_alg(&des_alg); | ||
611 | des_err: | ||
612 | goto out; | ||
450 | } | 613 | } |
451 | 614 | ||
452 | static void __exit fini(void) | 615 | static void __exit fini(void) |
453 | { | 616 | { |
617 | crypto_unregister_alg(&cbc_des3_192_alg); | ||
618 | crypto_unregister_alg(&ecb_des3_192_alg); | ||
454 | crypto_unregister_alg(&des3_192_alg); | 619 | crypto_unregister_alg(&des3_192_alg); |
620 | crypto_unregister_alg(&cbc_des3_128_alg); | ||
621 | crypto_unregister_alg(&ecb_des3_128_alg); | ||
455 | crypto_unregister_alg(&des3_128_alg); | 622 | crypto_unregister_alg(&des3_128_alg); |
623 | crypto_unregister_alg(&cbc_des_alg); | ||
624 | crypto_unregister_alg(&ecb_des_alg); | ||
456 | crypto_unregister_alg(&des_alg); | 625 | crypto_unregister_alg(&des_alg); |
457 | } | 626 | } |
458 | 627 | ||