aboutsummaryrefslogtreecommitdiffstats
path: root/arch/s390
diff options
context:
space:
mode:
authorJan Glauber <jan.glauber@de.ibm.com>2006-01-14 16:20:53 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2006-01-14 21:27:08 -0500
commitb8dc6038ff894d0eb0b5d61c9fafdf323ec10251 (patch)
treea703e90f2f73aacc1d8742f5f99451b93fc763d7 /arch/s390
parentc1357833bf5d92b1bda41215ae88a6597664251b (diff)
[PATCH] s390: des crypto code speedup
Provide ECB and CBC encrypt / decrypt functions to crypto API to speed up our hardware accelerated DES implementation. This new functions allow the crypto API to call ECB / CBC directly with large blocks in difference to the old functions that were calles with algorithm block size (8 bytes for DES). This is up to factor 10 faster than our old hardware implementation :) Signed-off-by: Jan Glauber <jan.glauber@de.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch/s390')
-rw-r--r--arch/s390/crypto/des_s390.c217
1 files changed, 210 insertions, 7 deletions
diff --git a/arch/s390/crypto/des_s390.c b/arch/s390/crypto/des_s390.c
index f090c3c2745b..e3c37aa0a199 100644
--- a/arch/s390/crypto/des_s390.c
+++ b/arch/s390/crypto/des_s390.c
@@ -57,18 +57,79 @@ static int des_setkey(void *ctx, const u8 *key, unsigned int keylen,
57 return ret; 57 return ret;
58} 58}
59 59
60static void des_encrypt(void *ctx, u8 *dst, const u8 *src) 60static void des_encrypt(void *ctx, u8 *out, const u8 *in)
61{ 61{
62 struct crypt_s390_des_ctx *dctx = ctx; 62 struct crypt_s390_des_ctx *dctx = ctx;
63 63
64 crypt_s390_km(KM_DEA_ENCRYPT, dctx->key, dst, src, DES_BLOCK_SIZE); 64 crypt_s390_km(KM_DEA_ENCRYPT, dctx->key, out, in, DES_BLOCK_SIZE);
65} 65}
66 66
67static void des_decrypt(void *ctx, u8 *dst, const u8 *src) 67static void des_decrypt(void *ctx, u8 *out, const u8 *in)
68{ 68{
69 struct crypt_s390_des_ctx *dctx = ctx; 69 struct crypt_s390_des_ctx *dctx = ctx;
70 70
71 crypt_s390_km(KM_DEA_DECRYPT, dctx->key, dst, src, DES_BLOCK_SIZE); 71 crypt_s390_km(KM_DEA_DECRYPT, dctx->key, out, in, DES_BLOCK_SIZE);
72}
73
74static unsigned int des_encrypt_ecb(const struct cipher_desc *desc, u8 *out,
75 const u8 *in, unsigned int nbytes)
76{
77 struct crypt_s390_des_ctx *sctx = crypto_tfm_ctx(desc->tfm);
78 int ret;
79
80 /* only use complete blocks */
81 nbytes &= ~(DES_BLOCK_SIZE - 1);
82 ret = crypt_s390_km(KM_DEA_ENCRYPT, sctx->key, out, in, nbytes);
83 BUG_ON((ret < 0) || (ret != nbytes));
84
85 return nbytes;
86}
87
88static unsigned int des_decrypt_ecb(const struct cipher_desc *desc, u8 *out,
89 const u8 *in, unsigned int nbytes)
90{
91 struct crypt_s390_des_ctx *sctx = crypto_tfm_ctx(desc->tfm);
92 int ret;
93
94 /* only use complete blocks */
95 nbytes &= ~(DES_BLOCK_SIZE - 1);
96 ret = crypt_s390_km(KM_DEA_DECRYPT, sctx->key, out, in, nbytes);
97 BUG_ON((ret < 0) || (ret != nbytes));
98
99 return nbytes;
100}
101
102static unsigned int des_encrypt_cbc(const struct cipher_desc *desc, u8 *out,
103 const u8 *in, unsigned int nbytes)
104{
105 struct crypt_s390_des_ctx *sctx = crypto_tfm_ctx(desc->tfm);
106 int ret;
107
108 /* only use complete blocks */
109 nbytes &= ~(DES_BLOCK_SIZE - 1);
110
111 memcpy(sctx->iv, desc->info, DES_BLOCK_SIZE);
112 ret = crypt_s390_kmc(KMC_DEA_ENCRYPT, &sctx->iv, out, in, nbytes);
113 BUG_ON((ret < 0) || (ret != nbytes));
114
115 memcpy(desc->info, sctx->iv, DES_BLOCK_SIZE);
116 return nbytes;
117}
118
119static unsigned int des_decrypt_cbc(const struct cipher_desc *desc, u8 *out,
120 const u8 *in, unsigned int nbytes)
121{
122 struct crypt_s390_des_ctx *sctx = crypto_tfm_ctx(desc->tfm);
123 int ret;
124
125 /* only use complete blocks */
126 nbytes &= ~(DES_BLOCK_SIZE - 1);
127
128 memcpy(&sctx->iv, desc->info, DES_BLOCK_SIZE);
129 ret = crypt_s390_kmc(KMC_DEA_DECRYPT, &sctx->iv, out, in, nbytes);
130 BUG_ON((ret < 0) || (ret != nbytes));
131
132 return nbytes;
72} 133}
73 134
74static struct crypto_alg des_alg = { 135static struct crypto_alg des_alg = {
@@ -84,7 +145,11 @@ static struct crypto_alg des_alg = {
84 .cia_max_keysize = DES_KEY_SIZE, 145 .cia_max_keysize = DES_KEY_SIZE,
85 .cia_setkey = des_setkey, 146 .cia_setkey = des_setkey,
86 .cia_encrypt = des_encrypt, 147 .cia_encrypt = des_encrypt,
87 .cia_decrypt = des_decrypt 148 .cia_decrypt = des_decrypt,
149 .cia_encrypt_ecb = des_encrypt_ecb,
150 .cia_decrypt_ecb = des_decrypt_ecb,
151 .cia_encrypt_cbc = des_encrypt_cbc,
152 .cia_decrypt_cbc = des_decrypt_cbc,
88 } 153 }
89 } 154 }
90}; 155};
@@ -137,6 +202,71 @@ static void des3_128_decrypt(void *ctx, u8 *dst, const u8 *src)
137 DES3_128_BLOCK_SIZE); 202 DES3_128_BLOCK_SIZE);
138} 203}
139 204
205static unsigned int des3_128_encrypt_ecb(const struct cipher_desc *desc,
206 u8 *out, const u8 *in,
207 unsigned int nbytes)
208{
209 struct crypt_s390_des3_128_ctx *sctx = crypto_tfm_ctx(desc->tfm);
210 int ret;
211
212 /* only use complete blocks */
213 nbytes &= ~(DES3_128_BLOCK_SIZE - 1);
214 ret = crypt_s390_km(KM_TDEA_128_ENCRYPT, sctx->key, out, in, nbytes);
215 BUG_ON((ret < 0) || (ret != nbytes));
216
217 return nbytes;
218}
219
220static unsigned int des3_128_decrypt_ecb(const struct cipher_desc *desc,
221 u8 *out, const u8 *in,
222 unsigned int nbytes)
223{
224 struct crypt_s390_des3_128_ctx *sctx = crypto_tfm_ctx(desc->tfm);
225 int ret;
226
227 /* only use complete blocks */
228 nbytes &= ~(DES3_128_BLOCK_SIZE - 1);
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}
234
235static unsigned int des3_128_encrypt_cbc(const struct cipher_desc *desc,
236 u8 *out, const u8 *in,
237 unsigned int nbytes)
238{
239 struct crypt_s390_des3_128_ctx *sctx = crypto_tfm_ctx(desc->tfm);
240 int ret;
241
242 /* only use complete blocks */
243 nbytes &= ~(DES3_128_BLOCK_SIZE - 1);
244
245 memcpy(sctx->iv, desc->info, DES3_128_BLOCK_SIZE);
246 ret = crypt_s390_kmc(KMC_TDEA_128_ENCRYPT, &sctx->iv, out, in, nbytes);
247 BUG_ON((ret < 0) || (ret != nbytes));
248
249 memcpy(desc->info, sctx->iv, DES3_128_BLOCK_SIZE);
250 return nbytes;
251}
252
253static unsigned int des3_128_decrypt_cbc(const struct cipher_desc *desc,
254 u8 *out, const u8 *in,
255 unsigned int nbytes)
256{
257 struct crypt_s390_des3_128_ctx *sctx = crypto_tfm_ctx(desc->tfm);
258 int ret;
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
267 return nbytes;
268}
269
140static struct crypto_alg des3_128_alg = { 270static struct crypto_alg des3_128_alg = {
141 .cra_name = "des3_ede128", 271 .cra_name = "des3_ede128",
142 .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 272 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
@@ -150,7 +280,11 @@ static struct crypto_alg des3_128_alg = {
150 .cia_max_keysize = DES3_128_KEY_SIZE, 280 .cia_max_keysize = DES3_128_KEY_SIZE,
151 .cia_setkey = des3_128_setkey, 281 .cia_setkey = des3_128_setkey,
152 .cia_encrypt = des3_128_encrypt, 282 .cia_encrypt = des3_128_encrypt,
153 .cia_decrypt = des3_128_decrypt 283 .cia_decrypt = des3_128_decrypt,
284 .cia_encrypt_ecb = des3_128_encrypt_ecb,
285 .cia_decrypt_ecb = des3_128_decrypt_ecb,
286 .cia_encrypt_cbc = des3_128_encrypt_cbc,
287 .cia_decrypt_cbc = des3_128_decrypt_cbc,
154 } 288 }
155 } 289 }
156}; 290};
@@ -207,6 +341,71 @@ static void des3_192_decrypt(void *ctx, u8 *dst, const u8 *src)
207 DES3_192_BLOCK_SIZE); 341 DES3_192_BLOCK_SIZE);
208} 342}
209 343
344static unsigned int des3_192_encrypt_ecb(const struct cipher_desc *desc,
345 u8 *out, const u8 *in,
346 unsigned int nbytes)
347{
348 struct crypt_s390_des3_192_ctx *sctx = crypto_tfm_ctx(desc->tfm);
349 int ret;
350
351 /* only use complete blocks */
352 nbytes &= ~(DES3_192_BLOCK_SIZE - 1);
353 ret = crypt_s390_km(KM_TDEA_192_ENCRYPT, sctx->key, out, in, nbytes);
354 BUG_ON((ret < 0) || (ret != nbytes));
355
356 return nbytes;
357}
358
359static unsigned int des3_192_decrypt_ecb(const struct cipher_desc *desc,
360 u8 *out, const u8 *in,
361 unsigned int nbytes)
362{
363 struct crypt_s390_des3_192_ctx *sctx = crypto_tfm_ctx(desc->tfm);
364 int ret;
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
371 return nbytes;
372}
373
374static unsigned int des3_192_encrypt_cbc(const struct cipher_desc *desc,
375 u8 *out, const u8 *in,
376 unsigned int nbytes)
377{
378 struct crypt_s390_des3_192_ctx *sctx = crypto_tfm_ctx(desc->tfm);
379 int ret;
380
381 /* only use complete blocks */
382 nbytes &= ~(DES3_192_BLOCK_SIZE - 1);
383
384 memcpy(sctx->iv, desc->info, DES3_192_BLOCK_SIZE);
385 ret = crypt_s390_kmc(KMC_TDEA_192_ENCRYPT, &sctx->iv, out, in, nbytes);
386 BUG_ON((ret < 0) || (ret != nbytes));
387
388 memcpy(desc->info, sctx->iv, DES3_192_BLOCK_SIZE);
389 return nbytes;
390}
391
392static unsigned int des3_192_decrypt_cbc(const struct cipher_desc *desc,
393 u8 *out, const u8 *in,
394 unsigned int nbytes)
395{
396 struct crypt_s390_des3_192_ctx *sctx = crypto_tfm_ctx(desc->tfm);
397 int ret;
398
399 /* only use complete blocks */
400 nbytes &= ~(DES3_192_BLOCK_SIZE - 1);
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}
408
210static struct crypto_alg des3_192_alg = { 409static struct crypto_alg des3_192_alg = {
211 .cra_name = "des3_ede", 410 .cra_name = "des3_ede",
212 .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 411 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
@@ -220,7 +419,11 @@ static struct crypto_alg des3_192_alg = {
220 .cia_max_keysize = DES3_192_KEY_SIZE, 419 .cia_max_keysize = DES3_192_KEY_SIZE,
221 .cia_setkey = des3_192_setkey, 420 .cia_setkey = des3_192_setkey,
222 .cia_encrypt = des3_192_encrypt, 421 .cia_encrypt = des3_192_encrypt,
223 .cia_decrypt = des3_192_decrypt 422 .cia_decrypt = des3_192_decrypt,
423 .cia_encrypt_ecb = des3_192_encrypt_ecb,
424 .cia_decrypt_ecb = des3_192_decrypt_ecb,
425 .cia_encrypt_cbc = des3_192_encrypt_cbc,
426 .cia_decrypt_cbc = des3_192_decrypt_cbc,
224 } 427 }
225 } 428 }
226}; 429};