.. | .. |
---|
16 | 16 | #include <linux/fips.h> |
---|
17 | 17 | #include <linux/mutex.h> |
---|
18 | 18 | #include <crypto/algapi.h> |
---|
19 | | -#include <crypto/des.h> |
---|
| 19 | +#include <crypto/internal/des.h> |
---|
| 20 | +#include <crypto/internal/skcipher.h> |
---|
20 | 21 | #include <asm/cpacf.h> |
---|
21 | 22 | |
---|
22 | 23 | #define DES3_KEY_SIZE (3 * DES_KEY_SIZE) |
---|
.. | .. |
---|
35 | 36 | unsigned int key_len) |
---|
36 | 37 | { |
---|
37 | 38 | struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm); |
---|
38 | | - u32 tmp[DES_EXPKEY_WORDS]; |
---|
| 39 | + int err; |
---|
39 | 40 | |
---|
40 | | - /* check for weak keys */ |
---|
41 | | - if (!des_ekey(tmp, key) && |
---|
42 | | - (tfm->crt_flags & CRYPTO_TFM_REQ_WEAK_KEY)) { |
---|
43 | | - tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY; |
---|
44 | | - return -EINVAL; |
---|
45 | | - } |
---|
| 41 | + err = crypto_des_verify_key(tfm, key); |
---|
| 42 | + if (err) |
---|
| 43 | + return err; |
---|
46 | 44 | |
---|
47 | 45 | memcpy(ctx->key, key, key_len); |
---|
48 | 46 | return 0; |
---|
49 | 47 | } |
---|
50 | 48 | |
---|
51 | | -static void des_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) |
---|
| 49 | +static int des_setkey_skcipher(struct crypto_skcipher *tfm, const u8 *key, |
---|
| 50 | + unsigned int key_len) |
---|
| 51 | +{ |
---|
| 52 | + return des_setkey(crypto_skcipher_tfm(tfm), key, key_len); |
---|
| 53 | +} |
---|
| 54 | + |
---|
| 55 | +static void s390_des_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) |
---|
52 | 56 | { |
---|
53 | 57 | struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm); |
---|
54 | 58 | |
---|
55 | 59 | cpacf_km(CPACF_KM_DEA, ctx->key, out, in, DES_BLOCK_SIZE); |
---|
56 | 60 | } |
---|
57 | 61 | |
---|
58 | | -static void des_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) |
---|
| 62 | +static void s390_des_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) |
---|
59 | 63 | { |
---|
60 | 64 | struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm); |
---|
61 | 65 | |
---|
.. | .. |
---|
76 | 80 | .cia_min_keysize = DES_KEY_SIZE, |
---|
77 | 81 | .cia_max_keysize = DES_KEY_SIZE, |
---|
78 | 82 | .cia_setkey = des_setkey, |
---|
79 | | - .cia_encrypt = des_encrypt, |
---|
80 | | - .cia_decrypt = des_decrypt, |
---|
| 83 | + .cia_encrypt = s390_des_encrypt, |
---|
| 84 | + .cia_decrypt = s390_des_decrypt, |
---|
81 | 85 | } |
---|
82 | 86 | } |
---|
83 | 87 | }; |
---|
84 | 88 | |
---|
85 | | -static int ecb_desall_crypt(struct blkcipher_desc *desc, unsigned long fc, |
---|
86 | | - struct blkcipher_walk *walk) |
---|
| 89 | +static int ecb_desall_crypt(struct skcipher_request *req, unsigned long fc) |
---|
87 | 90 | { |
---|
88 | | - struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); |
---|
| 91 | + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); |
---|
| 92 | + struct s390_des_ctx *ctx = crypto_skcipher_ctx(tfm); |
---|
| 93 | + struct skcipher_walk walk; |
---|
89 | 94 | unsigned int nbytes, n; |
---|
90 | 95 | int ret; |
---|
91 | 96 | |
---|
92 | | - ret = blkcipher_walk_virt(desc, walk); |
---|
93 | | - while ((nbytes = walk->nbytes) >= DES_BLOCK_SIZE) { |
---|
| 97 | + ret = skcipher_walk_virt(&walk, req, false); |
---|
| 98 | + while ((nbytes = walk.nbytes) != 0) { |
---|
94 | 99 | /* only use complete blocks */ |
---|
95 | 100 | n = nbytes & ~(DES_BLOCK_SIZE - 1); |
---|
96 | | - cpacf_km(fc, ctx->key, walk->dst.virt.addr, |
---|
97 | | - walk->src.virt.addr, n); |
---|
98 | | - ret = blkcipher_walk_done(desc, walk, nbytes - n); |
---|
| 101 | + cpacf_km(fc, ctx->key, walk.dst.virt.addr, |
---|
| 102 | + walk.src.virt.addr, n); |
---|
| 103 | + ret = skcipher_walk_done(&walk, nbytes - n); |
---|
99 | 104 | } |
---|
100 | 105 | return ret; |
---|
101 | 106 | } |
---|
102 | 107 | |
---|
103 | | -static int cbc_desall_crypt(struct blkcipher_desc *desc, unsigned long fc, |
---|
104 | | - struct blkcipher_walk *walk) |
---|
| 108 | +static int cbc_desall_crypt(struct skcipher_request *req, unsigned long fc) |
---|
105 | 109 | { |
---|
106 | | - struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); |
---|
| 110 | + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); |
---|
| 111 | + struct s390_des_ctx *ctx = crypto_skcipher_ctx(tfm); |
---|
| 112 | + struct skcipher_walk walk; |
---|
107 | 113 | unsigned int nbytes, n; |
---|
108 | 114 | int ret; |
---|
109 | 115 | struct { |
---|
.. | .. |
---|
111 | 117 | u8 key[DES3_KEY_SIZE]; |
---|
112 | 118 | } param; |
---|
113 | 119 | |
---|
114 | | - ret = blkcipher_walk_virt(desc, walk); |
---|
115 | | - memcpy(param.iv, walk->iv, DES_BLOCK_SIZE); |
---|
| 120 | + ret = skcipher_walk_virt(&walk, req, false); |
---|
| 121 | + if (ret) |
---|
| 122 | + return ret; |
---|
| 123 | + memcpy(param.iv, walk.iv, DES_BLOCK_SIZE); |
---|
116 | 124 | memcpy(param.key, ctx->key, DES3_KEY_SIZE); |
---|
117 | | - while ((nbytes = walk->nbytes) >= DES_BLOCK_SIZE) { |
---|
| 125 | + while ((nbytes = walk.nbytes) != 0) { |
---|
118 | 126 | /* only use complete blocks */ |
---|
119 | 127 | n = nbytes & ~(DES_BLOCK_SIZE - 1); |
---|
120 | | - cpacf_kmc(fc, ¶m, walk->dst.virt.addr, |
---|
121 | | - walk->src.virt.addr, n); |
---|
122 | | - ret = blkcipher_walk_done(desc, walk, nbytes - n); |
---|
| 128 | + cpacf_kmc(fc, ¶m, walk.dst.virt.addr, |
---|
| 129 | + walk.src.virt.addr, n); |
---|
| 130 | + memcpy(walk.iv, param.iv, DES_BLOCK_SIZE); |
---|
| 131 | + ret = skcipher_walk_done(&walk, nbytes - n); |
---|
123 | 132 | } |
---|
124 | | - memcpy(walk->iv, param.iv, DES_BLOCK_SIZE); |
---|
125 | 133 | return ret; |
---|
126 | 134 | } |
---|
127 | 135 | |
---|
128 | | -static int ecb_des_encrypt(struct blkcipher_desc *desc, |
---|
129 | | - struct scatterlist *dst, struct scatterlist *src, |
---|
130 | | - unsigned int nbytes) |
---|
| 136 | +static int ecb_des_encrypt(struct skcipher_request *req) |
---|
131 | 137 | { |
---|
132 | | - struct blkcipher_walk walk; |
---|
133 | | - |
---|
134 | | - blkcipher_walk_init(&walk, dst, src, nbytes); |
---|
135 | | - return ecb_desall_crypt(desc, CPACF_KM_DEA, &walk); |
---|
| 138 | + return ecb_desall_crypt(req, CPACF_KM_DEA); |
---|
136 | 139 | } |
---|
137 | 140 | |
---|
138 | | -static int ecb_des_decrypt(struct blkcipher_desc *desc, |
---|
139 | | - struct scatterlist *dst, struct scatterlist *src, |
---|
140 | | - unsigned int nbytes) |
---|
| 141 | +static int ecb_des_decrypt(struct skcipher_request *req) |
---|
141 | 142 | { |
---|
142 | | - struct blkcipher_walk walk; |
---|
143 | | - |
---|
144 | | - blkcipher_walk_init(&walk, dst, src, nbytes); |
---|
145 | | - return ecb_desall_crypt(desc, CPACF_KM_DEA | CPACF_DECRYPT, &walk); |
---|
| 143 | + return ecb_desall_crypt(req, CPACF_KM_DEA | CPACF_DECRYPT); |
---|
146 | 144 | } |
---|
147 | 145 | |
---|
148 | | -static struct crypto_alg ecb_des_alg = { |
---|
149 | | - .cra_name = "ecb(des)", |
---|
150 | | - .cra_driver_name = "ecb-des-s390", |
---|
151 | | - .cra_priority = 400, /* combo: des + ecb */ |
---|
152 | | - .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, |
---|
153 | | - .cra_blocksize = DES_BLOCK_SIZE, |
---|
154 | | - .cra_ctxsize = sizeof(struct s390_des_ctx), |
---|
155 | | - .cra_type = &crypto_blkcipher_type, |
---|
156 | | - .cra_module = THIS_MODULE, |
---|
157 | | - .cra_u = { |
---|
158 | | - .blkcipher = { |
---|
159 | | - .min_keysize = DES_KEY_SIZE, |
---|
160 | | - .max_keysize = DES_KEY_SIZE, |
---|
161 | | - .setkey = des_setkey, |
---|
162 | | - .encrypt = ecb_des_encrypt, |
---|
163 | | - .decrypt = ecb_des_decrypt, |
---|
164 | | - } |
---|
165 | | - } |
---|
| 146 | +static struct skcipher_alg ecb_des_alg = { |
---|
| 147 | + .base.cra_name = "ecb(des)", |
---|
| 148 | + .base.cra_driver_name = "ecb-des-s390", |
---|
| 149 | + .base.cra_priority = 400, /* combo: des + ecb */ |
---|
| 150 | + .base.cra_blocksize = DES_BLOCK_SIZE, |
---|
| 151 | + .base.cra_ctxsize = sizeof(struct s390_des_ctx), |
---|
| 152 | + .base.cra_module = THIS_MODULE, |
---|
| 153 | + .min_keysize = DES_KEY_SIZE, |
---|
| 154 | + .max_keysize = DES_KEY_SIZE, |
---|
| 155 | + .setkey = des_setkey_skcipher, |
---|
| 156 | + .encrypt = ecb_des_encrypt, |
---|
| 157 | + .decrypt = ecb_des_decrypt, |
---|
166 | 158 | }; |
---|
167 | 159 | |
---|
168 | | -static int cbc_des_encrypt(struct blkcipher_desc *desc, |
---|
169 | | - struct scatterlist *dst, struct scatterlist *src, |
---|
170 | | - unsigned int nbytes) |
---|
| 160 | +static int cbc_des_encrypt(struct skcipher_request *req) |
---|
171 | 161 | { |
---|
172 | | - struct blkcipher_walk walk; |
---|
173 | | - |
---|
174 | | - blkcipher_walk_init(&walk, dst, src, nbytes); |
---|
175 | | - return cbc_desall_crypt(desc, CPACF_KMC_DEA, &walk); |
---|
| 162 | + return cbc_desall_crypt(req, CPACF_KMC_DEA); |
---|
176 | 163 | } |
---|
177 | 164 | |
---|
178 | | -static int cbc_des_decrypt(struct blkcipher_desc *desc, |
---|
179 | | - struct scatterlist *dst, struct scatterlist *src, |
---|
180 | | - unsigned int nbytes) |
---|
| 165 | +static int cbc_des_decrypt(struct skcipher_request *req) |
---|
181 | 166 | { |
---|
182 | | - struct blkcipher_walk walk; |
---|
183 | | - |
---|
184 | | - blkcipher_walk_init(&walk, dst, src, nbytes); |
---|
185 | | - return cbc_desall_crypt(desc, CPACF_KMC_DEA | CPACF_DECRYPT, &walk); |
---|
| 167 | + return cbc_desall_crypt(req, CPACF_KMC_DEA | CPACF_DECRYPT); |
---|
186 | 168 | } |
---|
187 | 169 | |
---|
188 | | -static struct crypto_alg cbc_des_alg = { |
---|
189 | | - .cra_name = "cbc(des)", |
---|
190 | | - .cra_driver_name = "cbc-des-s390", |
---|
191 | | - .cra_priority = 400, /* combo: des + cbc */ |
---|
192 | | - .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, |
---|
193 | | - .cra_blocksize = DES_BLOCK_SIZE, |
---|
194 | | - .cra_ctxsize = sizeof(struct s390_des_ctx), |
---|
195 | | - .cra_type = &crypto_blkcipher_type, |
---|
196 | | - .cra_module = THIS_MODULE, |
---|
197 | | - .cra_u = { |
---|
198 | | - .blkcipher = { |
---|
199 | | - .min_keysize = DES_KEY_SIZE, |
---|
200 | | - .max_keysize = DES_KEY_SIZE, |
---|
201 | | - .ivsize = DES_BLOCK_SIZE, |
---|
202 | | - .setkey = des_setkey, |
---|
203 | | - .encrypt = cbc_des_encrypt, |
---|
204 | | - .decrypt = cbc_des_decrypt, |
---|
205 | | - } |
---|
206 | | - } |
---|
| 170 | +static struct skcipher_alg cbc_des_alg = { |
---|
| 171 | + .base.cra_name = "cbc(des)", |
---|
| 172 | + .base.cra_driver_name = "cbc-des-s390", |
---|
| 173 | + .base.cra_priority = 400, /* combo: des + cbc */ |
---|
| 174 | + .base.cra_blocksize = DES_BLOCK_SIZE, |
---|
| 175 | + .base.cra_ctxsize = sizeof(struct s390_des_ctx), |
---|
| 176 | + .base.cra_module = THIS_MODULE, |
---|
| 177 | + .min_keysize = DES_KEY_SIZE, |
---|
| 178 | + .max_keysize = DES_KEY_SIZE, |
---|
| 179 | + .ivsize = DES_BLOCK_SIZE, |
---|
| 180 | + .setkey = des_setkey_skcipher, |
---|
| 181 | + .encrypt = cbc_des_encrypt, |
---|
| 182 | + .decrypt = cbc_des_decrypt, |
---|
207 | 183 | }; |
---|
208 | 184 | |
---|
209 | 185 | /* |
---|
.. | .. |
---|
225 | 201 | unsigned int key_len) |
---|
226 | 202 | { |
---|
227 | 203 | struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm); |
---|
| 204 | + int err; |
---|
228 | 205 | |
---|
229 | | - if (!(crypto_memneq(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) && |
---|
230 | | - crypto_memneq(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2], |
---|
231 | | - DES_KEY_SIZE)) && |
---|
232 | | - (tfm->crt_flags & CRYPTO_TFM_REQ_WEAK_KEY)) { |
---|
233 | | - tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY; |
---|
234 | | - return -EINVAL; |
---|
235 | | - } |
---|
236 | | - |
---|
237 | | - /* in fips mode, ensure k1 != k2 and k2 != k3 and k1 != k3 */ |
---|
238 | | - if (fips_enabled && |
---|
239 | | - !(crypto_memneq(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) && |
---|
240 | | - crypto_memneq(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2], |
---|
241 | | - DES_KEY_SIZE) && |
---|
242 | | - crypto_memneq(key, &key[DES_KEY_SIZE * 2], DES_KEY_SIZE))) { |
---|
243 | | - tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY; |
---|
244 | | - return -EINVAL; |
---|
245 | | - } |
---|
| 206 | + err = crypto_des3_ede_verify_key(tfm, key); |
---|
| 207 | + if (err) |
---|
| 208 | + return err; |
---|
246 | 209 | |
---|
247 | 210 | memcpy(ctx->key, key, key_len); |
---|
248 | 211 | return 0; |
---|
| 212 | +} |
---|
| 213 | + |
---|
| 214 | +static int des3_setkey_skcipher(struct crypto_skcipher *tfm, const u8 *key, |
---|
| 215 | + unsigned int key_len) |
---|
| 216 | +{ |
---|
| 217 | + return des3_setkey(crypto_skcipher_tfm(tfm), key, key_len); |
---|
249 | 218 | } |
---|
250 | 219 | |
---|
251 | 220 | static void des3_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) |
---|
.. | .. |
---|
282 | 251 | } |
---|
283 | 252 | }; |
---|
284 | 253 | |
---|
285 | | -static int ecb_des3_encrypt(struct blkcipher_desc *desc, |
---|
286 | | - struct scatterlist *dst, struct scatterlist *src, |
---|
287 | | - unsigned int nbytes) |
---|
| 254 | +static int ecb_des3_encrypt(struct skcipher_request *req) |
---|
288 | 255 | { |
---|
289 | | - struct blkcipher_walk walk; |
---|
290 | | - |
---|
291 | | - blkcipher_walk_init(&walk, dst, src, nbytes); |
---|
292 | | - return ecb_desall_crypt(desc, CPACF_KM_TDEA_192, &walk); |
---|
| 256 | + return ecb_desall_crypt(req, CPACF_KM_TDEA_192); |
---|
293 | 257 | } |
---|
294 | 258 | |
---|
295 | | -static int ecb_des3_decrypt(struct blkcipher_desc *desc, |
---|
296 | | - struct scatterlist *dst, struct scatterlist *src, |
---|
297 | | - unsigned int nbytes) |
---|
| 259 | +static int ecb_des3_decrypt(struct skcipher_request *req) |
---|
298 | 260 | { |
---|
299 | | - struct blkcipher_walk walk; |
---|
300 | | - |
---|
301 | | - blkcipher_walk_init(&walk, dst, src, nbytes); |
---|
302 | | - return ecb_desall_crypt(desc, CPACF_KM_TDEA_192 | CPACF_DECRYPT, |
---|
303 | | - &walk); |
---|
| 261 | + return ecb_desall_crypt(req, CPACF_KM_TDEA_192 | CPACF_DECRYPT); |
---|
304 | 262 | } |
---|
305 | 263 | |
---|
306 | | -static struct crypto_alg ecb_des3_alg = { |
---|
307 | | - .cra_name = "ecb(des3_ede)", |
---|
308 | | - .cra_driver_name = "ecb-des3_ede-s390", |
---|
309 | | - .cra_priority = 400, /* combo: des3 + ecb */ |
---|
310 | | - .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, |
---|
311 | | - .cra_blocksize = DES_BLOCK_SIZE, |
---|
312 | | - .cra_ctxsize = sizeof(struct s390_des_ctx), |
---|
313 | | - .cra_type = &crypto_blkcipher_type, |
---|
314 | | - .cra_module = THIS_MODULE, |
---|
315 | | - .cra_u = { |
---|
316 | | - .blkcipher = { |
---|
317 | | - .min_keysize = DES3_KEY_SIZE, |
---|
318 | | - .max_keysize = DES3_KEY_SIZE, |
---|
319 | | - .setkey = des3_setkey, |
---|
320 | | - .encrypt = ecb_des3_encrypt, |
---|
321 | | - .decrypt = ecb_des3_decrypt, |
---|
322 | | - } |
---|
323 | | - } |
---|
| 264 | +static struct skcipher_alg ecb_des3_alg = { |
---|
| 265 | + .base.cra_name = "ecb(des3_ede)", |
---|
| 266 | + .base.cra_driver_name = "ecb-des3_ede-s390", |
---|
| 267 | + .base.cra_priority = 400, /* combo: des3 + ecb */ |
---|
| 268 | + .base.cra_blocksize = DES_BLOCK_SIZE, |
---|
| 269 | + .base.cra_ctxsize = sizeof(struct s390_des_ctx), |
---|
| 270 | + .base.cra_module = THIS_MODULE, |
---|
| 271 | + .min_keysize = DES3_KEY_SIZE, |
---|
| 272 | + .max_keysize = DES3_KEY_SIZE, |
---|
| 273 | + .setkey = des3_setkey_skcipher, |
---|
| 274 | + .encrypt = ecb_des3_encrypt, |
---|
| 275 | + .decrypt = ecb_des3_decrypt, |
---|
324 | 276 | }; |
---|
325 | 277 | |
---|
326 | | -static int cbc_des3_encrypt(struct blkcipher_desc *desc, |
---|
327 | | - struct scatterlist *dst, struct scatterlist *src, |
---|
328 | | - unsigned int nbytes) |
---|
| 278 | +static int cbc_des3_encrypt(struct skcipher_request *req) |
---|
329 | 279 | { |
---|
330 | | - struct blkcipher_walk walk; |
---|
331 | | - |
---|
332 | | - blkcipher_walk_init(&walk, dst, src, nbytes); |
---|
333 | | - return cbc_desall_crypt(desc, CPACF_KMC_TDEA_192, &walk); |
---|
| 280 | + return cbc_desall_crypt(req, CPACF_KMC_TDEA_192); |
---|
334 | 281 | } |
---|
335 | 282 | |
---|
336 | | -static int cbc_des3_decrypt(struct blkcipher_desc *desc, |
---|
337 | | - struct scatterlist *dst, struct scatterlist *src, |
---|
338 | | - unsigned int nbytes) |
---|
| 283 | +static int cbc_des3_decrypt(struct skcipher_request *req) |
---|
339 | 284 | { |
---|
340 | | - struct blkcipher_walk walk; |
---|
341 | | - |
---|
342 | | - blkcipher_walk_init(&walk, dst, src, nbytes); |
---|
343 | | - return cbc_desall_crypt(desc, CPACF_KMC_TDEA_192 | CPACF_DECRYPT, |
---|
344 | | - &walk); |
---|
| 285 | + return cbc_desall_crypt(req, CPACF_KMC_TDEA_192 | CPACF_DECRYPT); |
---|
345 | 286 | } |
---|
346 | 287 | |
---|
347 | | -static struct crypto_alg cbc_des3_alg = { |
---|
348 | | - .cra_name = "cbc(des3_ede)", |
---|
349 | | - .cra_driver_name = "cbc-des3_ede-s390", |
---|
350 | | - .cra_priority = 400, /* combo: des3 + cbc */ |
---|
351 | | - .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, |
---|
352 | | - .cra_blocksize = DES_BLOCK_SIZE, |
---|
353 | | - .cra_ctxsize = sizeof(struct s390_des_ctx), |
---|
354 | | - .cra_type = &crypto_blkcipher_type, |
---|
355 | | - .cra_module = THIS_MODULE, |
---|
356 | | - .cra_u = { |
---|
357 | | - .blkcipher = { |
---|
358 | | - .min_keysize = DES3_KEY_SIZE, |
---|
359 | | - .max_keysize = DES3_KEY_SIZE, |
---|
360 | | - .ivsize = DES_BLOCK_SIZE, |
---|
361 | | - .setkey = des3_setkey, |
---|
362 | | - .encrypt = cbc_des3_encrypt, |
---|
363 | | - .decrypt = cbc_des3_decrypt, |
---|
364 | | - } |
---|
365 | | - } |
---|
| 288 | +static struct skcipher_alg cbc_des3_alg = { |
---|
| 289 | + .base.cra_name = "cbc(des3_ede)", |
---|
| 290 | + .base.cra_driver_name = "cbc-des3_ede-s390", |
---|
| 291 | + .base.cra_priority = 400, /* combo: des3 + cbc */ |
---|
| 292 | + .base.cra_blocksize = DES_BLOCK_SIZE, |
---|
| 293 | + .base.cra_ctxsize = sizeof(struct s390_des_ctx), |
---|
| 294 | + .base.cra_module = THIS_MODULE, |
---|
| 295 | + .min_keysize = DES3_KEY_SIZE, |
---|
| 296 | + .max_keysize = DES3_KEY_SIZE, |
---|
| 297 | + .ivsize = DES_BLOCK_SIZE, |
---|
| 298 | + .setkey = des3_setkey_skcipher, |
---|
| 299 | + .encrypt = cbc_des3_encrypt, |
---|
| 300 | + .decrypt = cbc_des3_decrypt, |
---|
366 | 301 | }; |
---|
367 | 302 | |
---|
368 | 303 | static unsigned int __ctrblk_init(u8 *ctrptr, u8 *iv, unsigned int nbytes) |
---|
.. | .. |
---|
380 | 315 | return n; |
---|
381 | 316 | } |
---|
382 | 317 | |
---|
383 | | -static int ctr_desall_crypt(struct blkcipher_desc *desc, unsigned long fc, |
---|
384 | | - struct blkcipher_walk *walk) |
---|
| 318 | +static int ctr_desall_crypt(struct skcipher_request *req, unsigned long fc) |
---|
385 | 319 | { |
---|
386 | | - struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); |
---|
| 320 | + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); |
---|
| 321 | + struct s390_des_ctx *ctx = crypto_skcipher_ctx(tfm); |
---|
387 | 322 | u8 buf[DES_BLOCK_SIZE], *ctrptr; |
---|
| 323 | + struct skcipher_walk walk; |
---|
388 | 324 | unsigned int n, nbytes; |
---|
389 | 325 | int ret, locked; |
---|
390 | 326 | |
---|
391 | 327 | locked = mutex_trylock(&ctrblk_lock); |
---|
392 | 328 | |
---|
393 | | - ret = blkcipher_walk_virt_block(desc, walk, DES_BLOCK_SIZE); |
---|
394 | | - while ((nbytes = walk->nbytes) >= DES_BLOCK_SIZE) { |
---|
| 329 | + ret = skcipher_walk_virt(&walk, req, false); |
---|
| 330 | + while ((nbytes = walk.nbytes) >= DES_BLOCK_SIZE) { |
---|
395 | 331 | n = DES_BLOCK_SIZE; |
---|
396 | 332 | if (nbytes >= 2*DES_BLOCK_SIZE && locked) |
---|
397 | | - n = __ctrblk_init(ctrblk, walk->iv, nbytes); |
---|
398 | | - ctrptr = (n > DES_BLOCK_SIZE) ? ctrblk : walk->iv; |
---|
399 | | - cpacf_kmctr(fc, ctx->key, walk->dst.virt.addr, |
---|
400 | | - walk->src.virt.addr, n, ctrptr); |
---|
| 333 | + n = __ctrblk_init(ctrblk, walk.iv, nbytes); |
---|
| 334 | + ctrptr = (n > DES_BLOCK_SIZE) ? ctrblk : walk.iv; |
---|
| 335 | + cpacf_kmctr(fc, ctx->key, walk.dst.virt.addr, |
---|
| 336 | + walk.src.virt.addr, n, ctrptr); |
---|
401 | 337 | if (ctrptr == ctrblk) |
---|
402 | | - memcpy(walk->iv, ctrptr + n - DES_BLOCK_SIZE, |
---|
| 338 | + memcpy(walk.iv, ctrptr + n - DES_BLOCK_SIZE, |
---|
403 | 339 | DES_BLOCK_SIZE); |
---|
404 | | - crypto_inc(walk->iv, DES_BLOCK_SIZE); |
---|
405 | | - ret = blkcipher_walk_done(desc, walk, nbytes - n); |
---|
| 340 | + crypto_inc(walk.iv, DES_BLOCK_SIZE); |
---|
| 341 | + ret = skcipher_walk_done(&walk, nbytes - n); |
---|
406 | 342 | } |
---|
407 | 343 | if (locked) |
---|
408 | 344 | mutex_unlock(&ctrblk_lock); |
---|
409 | 345 | /* final block may be < DES_BLOCK_SIZE, copy only nbytes */ |
---|
410 | 346 | if (nbytes) { |
---|
411 | | - cpacf_kmctr(fc, ctx->key, buf, walk->src.virt.addr, |
---|
412 | | - DES_BLOCK_SIZE, walk->iv); |
---|
413 | | - memcpy(walk->dst.virt.addr, buf, nbytes); |
---|
414 | | - crypto_inc(walk->iv, DES_BLOCK_SIZE); |
---|
415 | | - ret = blkcipher_walk_done(desc, walk, 0); |
---|
| 347 | + cpacf_kmctr(fc, ctx->key, buf, walk.src.virt.addr, |
---|
| 348 | + DES_BLOCK_SIZE, walk.iv); |
---|
| 349 | + memcpy(walk.dst.virt.addr, buf, nbytes); |
---|
| 350 | + crypto_inc(walk.iv, DES_BLOCK_SIZE); |
---|
| 351 | + ret = skcipher_walk_done(&walk, 0); |
---|
416 | 352 | } |
---|
417 | 353 | return ret; |
---|
418 | 354 | } |
---|
419 | 355 | |
---|
420 | | -static int ctr_des_encrypt(struct blkcipher_desc *desc, |
---|
421 | | - struct scatterlist *dst, struct scatterlist *src, |
---|
422 | | - unsigned int nbytes) |
---|
| 356 | +static int ctr_des_crypt(struct skcipher_request *req) |
---|
423 | 357 | { |
---|
424 | | - struct blkcipher_walk walk; |
---|
425 | | - |
---|
426 | | - blkcipher_walk_init(&walk, dst, src, nbytes); |
---|
427 | | - return ctr_desall_crypt(desc, CPACF_KMCTR_DEA, &walk); |
---|
| 358 | + return ctr_desall_crypt(req, CPACF_KMCTR_DEA); |
---|
428 | 359 | } |
---|
429 | 360 | |
---|
430 | | -static int ctr_des_decrypt(struct blkcipher_desc *desc, |
---|
431 | | - struct scatterlist *dst, struct scatterlist *src, |
---|
432 | | - unsigned int nbytes) |
---|
433 | | -{ |
---|
434 | | - struct blkcipher_walk walk; |
---|
435 | | - |
---|
436 | | - blkcipher_walk_init(&walk, dst, src, nbytes); |
---|
437 | | - return ctr_desall_crypt(desc, CPACF_KMCTR_DEA | CPACF_DECRYPT, &walk); |
---|
438 | | -} |
---|
439 | | - |
---|
440 | | -static struct crypto_alg ctr_des_alg = { |
---|
441 | | - .cra_name = "ctr(des)", |
---|
442 | | - .cra_driver_name = "ctr-des-s390", |
---|
443 | | - .cra_priority = 400, /* combo: des + ctr */ |
---|
444 | | - .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, |
---|
445 | | - .cra_blocksize = 1, |
---|
446 | | - .cra_ctxsize = sizeof(struct s390_des_ctx), |
---|
447 | | - .cra_type = &crypto_blkcipher_type, |
---|
448 | | - .cra_module = THIS_MODULE, |
---|
449 | | - .cra_u = { |
---|
450 | | - .blkcipher = { |
---|
451 | | - .min_keysize = DES_KEY_SIZE, |
---|
452 | | - .max_keysize = DES_KEY_SIZE, |
---|
453 | | - .ivsize = DES_BLOCK_SIZE, |
---|
454 | | - .setkey = des_setkey, |
---|
455 | | - .encrypt = ctr_des_encrypt, |
---|
456 | | - .decrypt = ctr_des_decrypt, |
---|
457 | | - } |
---|
458 | | - } |
---|
| 361 | +static struct skcipher_alg ctr_des_alg = { |
---|
| 362 | + .base.cra_name = "ctr(des)", |
---|
| 363 | + .base.cra_driver_name = "ctr-des-s390", |
---|
| 364 | + .base.cra_priority = 400, /* combo: des + ctr */ |
---|
| 365 | + .base.cra_blocksize = 1, |
---|
| 366 | + .base.cra_ctxsize = sizeof(struct s390_des_ctx), |
---|
| 367 | + .base.cra_module = THIS_MODULE, |
---|
| 368 | + .min_keysize = DES_KEY_SIZE, |
---|
| 369 | + .max_keysize = DES_KEY_SIZE, |
---|
| 370 | + .ivsize = DES_BLOCK_SIZE, |
---|
| 371 | + .setkey = des_setkey_skcipher, |
---|
| 372 | + .encrypt = ctr_des_crypt, |
---|
| 373 | + .decrypt = ctr_des_crypt, |
---|
| 374 | + .chunksize = DES_BLOCK_SIZE, |
---|
459 | 375 | }; |
---|
460 | 376 | |
---|
461 | | -static int ctr_des3_encrypt(struct blkcipher_desc *desc, |
---|
462 | | - struct scatterlist *dst, struct scatterlist *src, |
---|
463 | | - unsigned int nbytes) |
---|
| 377 | +static int ctr_des3_crypt(struct skcipher_request *req) |
---|
464 | 378 | { |
---|
465 | | - struct blkcipher_walk walk; |
---|
466 | | - |
---|
467 | | - blkcipher_walk_init(&walk, dst, src, nbytes); |
---|
468 | | - return ctr_desall_crypt(desc, CPACF_KMCTR_TDEA_192, &walk); |
---|
| 379 | + return ctr_desall_crypt(req, CPACF_KMCTR_TDEA_192); |
---|
469 | 380 | } |
---|
470 | 381 | |
---|
471 | | -static int ctr_des3_decrypt(struct blkcipher_desc *desc, |
---|
472 | | - struct scatterlist *dst, struct scatterlist *src, |
---|
473 | | - unsigned int nbytes) |
---|
474 | | -{ |
---|
475 | | - struct blkcipher_walk walk; |
---|
476 | | - |
---|
477 | | - blkcipher_walk_init(&walk, dst, src, nbytes); |
---|
478 | | - return ctr_desall_crypt(desc, CPACF_KMCTR_TDEA_192 | CPACF_DECRYPT, |
---|
479 | | - &walk); |
---|
480 | | -} |
---|
481 | | - |
---|
482 | | -static struct crypto_alg ctr_des3_alg = { |
---|
483 | | - .cra_name = "ctr(des3_ede)", |
---|
484 | | - .cra_driver_name = "ctr-des3_ede-s390", |
---|
485 | | - .cra_priority = 400, /* combo: des3 + ede */ |
---|
486 | | - .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, |
---|
487 | | - .cra_blocksize = 1, |
---|
488 | | - .cra_ctxsize = sizeof(struct s390_des_ctx), |
---|
489 | | - .cra_type = &crypto_blkcipher_type, |
---|
490 | | - .cra_module = THIS_MODULE, |
---|
491 | | - .cra_u = { |
---|
492 | | - .blkcipher = { |
---|
493 | | - .min_keysize = DES3_KEY_SIZE, |
---|
494 | | - .max_keysize = DES3_KEY_SIZE, |
---|
495 | | - .ivsize = DES_BLOCK_SIZE, |
---|
496 | | - .setkey = des3_setkey, |
---|
497 | | - .encrypt = ctr_des3_encrypt, |
---|
498 | | - .decrypt = ctr_des3_decrypt, |
---|
499 | | - } |
---|
500 | | - } |
---|
| 382 | +static struct skcipher_alg ctr_des3_alg = { |
---|
| 383 | + .base.cra_name = "ctr(des3_ede)", |
---|
| 384 | + .base.cra_driver_name = "ctr-des3_ede-s390", |
---|
| 385 | + .base.cra_priority = 400, /* combo: des3 + ede */ |
---|
| 386 | + .base.cra_blocksize = 1, |
---|
| 387 | + .base.cra_ctxsize = sizeof(struct s390_des_ctx), |
---|
| 388 | + .base.cra_module = THIS_MODULE, |
---|
| 389 | + .min_keysize = DES3_KEY_SIZE, |
---|
| 390 | + .max_keysize = DES3_KEY_SIZE, |
---|
| 391 | + .ivsize = DES_BLOCK_SIZE, |
---|
| 392 | + .setkey = des3_setkey_skcipher, |
---|
| 393 | + .encrypt = ctr_des3_crypt, |
---|
| 394 | + .decrypt = ctr_des3_crypt, |
---|
| 395 | + .chunksize = DES_BLOCK_SIZE, |
---|
501 | 396 | }; |
---|
502 | 397 | |
---|
503 | | -static struct crypto_alg *des_s390_algs_ptr[8]; |
---|
| 398 | +static struct crypto_alg *des_s390_algs_ptr[2]; |
---|
504 | 399 | static int des_s390_algs_num; |
---|
| 400 | +static struct skcipher_alg *des_s390_skciphers_ptr[6]; |
---|
| 401 | +static int des_s390_skciphers_num; |
---|
505 | 402 | |
---|
506 | 403 | static int des_s390_register_alg(struct crypto_alg *alg) |
---|
507 | 404 | { |
---|
.. | .. |
---|
513 | 410 | return ret; |
---|
514 | 411 | } |
---|
515 | 412 | |
---|
| 413 | +static int des_s390_register_skcipher(struct skcipher_alg *alg) |
---|
| 414 | +{ |
---|
| 415 | + int ret; |
---|
| 416 | + |
---|
| 417 | + ret = crypto_register_skcipher(alg); |
---|
| 418 | + if (!ret) |
---|
| 419 | + des_s390_skciphers_ptr[des_s390_skciphers_num++] = alg; |
---|
| 420 | + return ret; |
---|
| 421 | +} |
---|
| 422 | + |
---|
516 | 423 | static void des_s390_exit(void) |
---|
517 | 424 | { |
---|
518 | 425 | while (des_s390_algs_num--) |
---|
519 | 426 | crypto_unregister_alg(des_s390_algs_ptr[des_s390_algs_num]); |
---|
| 427 | + while (des_s390_skciphers_num--) |
---|
| 428 | + crypto_unregister_skcipher(des_s390_skciphers_ptr[des_s390_skciphers_num]); |
---|
520 | 429 | if (ctrblk) |
---|
521 | 430 | free_page((unsigned long) ctrblk); |
---|
522 | 431 | } |
---|
.. | .. |
---|
534 | 443 | ret = des_s390_register_alg(&des_alg); |
---|
535 | 444 | if (ret) |
---|
536 | 445 | goto out_err; |
---|
537 | | - ret = des_s390_register_alg(&ecb_des_alg); |
---|
| 446 | + ret = des_s390_register_skcipher(&ecb_des_alg); |
---|
538 | 447 | if (ret) |
---|
539 | 448 | goto out_err; |
---|
540 | 449 | } |
---|
541 | 450 | if (cpacf_test_func(&kmc_functions, CPACF_KMC_DEA)) { |
---|
542 | | - ret = des_s390_register_alg(&cbc_des_alg); |
---|
| 451 | + ret = des_s390_register_skcipher(&cbc_des_alg); |
---|
543 | 452 | if (ret) |
---|
544 | 453 | goto out_err; |
---|
545 | 454 | } |
---|
.. | .. |
---|
547 | 456 | ret = des_s390_register_alg(&des3_alg); |
---|
548 | 457 | if (ret) |
---|
549 | 458 | goto out_err; |
---|
550 | | - ret = des_s390_register_alg(&ecb_des3_alg); |
---|
| 459 | + ret = des_s390_register_skcipher(&ecb_des3_alg); |
---|
551 | 460 | if (ret) |
---|
552 | 461 | goto out_err; |
---|
553 | 462 | } |
---|
554 | 463 | if (cpacf_test_func(&kmc_functions, CPACF_KMC_TDEA_192)) { |
---|
555 | | - ret = des_s390_register_alg(&cbc_des3_alg); |
---|
| 464 | + ret = des_s390_register_skcipher(&cbc_des3_alg); |
---|
556 | 465 | if (ret) |
---|
557 | 466 | goto out_err; |
---|
558 | 467 | } |
---|
.. | .. |
---|
567 | 476 | } |
---|
568 | 477 | |
---|
569 | 478 | if (cpacf_test_func(&kmctr_functions, CPACF_KMCTR_DEA)) { |
---|
570 | | - ret = des_s390_register_alg(&ctr_des_alg); |
---|
| 479 | + ret = des_s390_register_skcipher(&ctr_des_alg); |
---|
571 | 480 | if (ret) |
---|
572 | 481 | goto out_err; |
---|
573 | 482 | } |
---|
574 | 483 | if (cpacf_test_func(&kmctr_functions, CPACF_KMCTR_TDEA_192)) { |
---|
575 | | - ret = des_s390_register_alg(&ctr_des3_alg); |
---|
| 484 | + ret = des_s390_register_skcipher(&ctr_des3_alg); |
---|
576 | 485 | if (ret) |
---|
577 | 486 | goto out_err; |
---|
578 | 487 | } |
---|