aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2006-05-16 08:09:29 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2006-06-26 03:34:39 -0400
commit6c2bb98bc33ae33c7a33a133a4cd5a06395fece5 (patch)
tree96684cd2c473cd05d651ce1fa3dd72b1b4b19b09 /crypto
parent43600106e32809a4dead79fec67a63e9860e3d5d (diff)
[CRYPTO] all: Pass tfm instead of ctx to algorithms
Up until now algorithms have been happy to get a context pointer since they know everything that's in the tfm already (e.g., alignment, block size). However, once we have parameterised algorithms, such information will be specific to each tfm. So the algorithm API needs to be changed to pass the tfm structure instead of the context pointer. This patch is basically a text substitution. The only tricky bit is the assembly routines that need to get the context pointer offset through asm-offsets.h. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/aes.c14
-rw-r--r--crypto/anubis.c13
-rw-r--r--crypto/arc4.c9
-rw-r--r--crypto/blowfish.c19
-rw-r--r--crypto/cast5.c14
-rw-r--r--crypto/cast6.c15
-rw-r--r--crypto/cipher.c14
-rw-r--r--crypto/compress.c6
-rw-r--r--crypto/crc32c.c19
-rw-r--r--crypto/crypto_null.c17
-rw-r--r--crypto/deflate.c19
-rw-r--r--crypto/des.c27
-rw-r--r--crypto/digest.c15
-rw-r--r--crypto/khazad.c14
-rw-r--r--crypto/md4.c12
-rw-r--r--crypto/md5.c12
-rw-r--r--crypto/michael_mic.c19
-rw-r--r--crypto/serpent.c27
-rw-r--r--crypto/sha1.c17
-rw-r--r--crypto/sha256.c17
-rw-r--r--crypto/sha512.c25
-rw-r--r--crypto/tea.c55
-rw-r--r--crypto/tgr192.c29
-rw-r--r--crypto/twofish.c14
-rw-r--r--crypto/wp512.c24
25 files changed, 237 insertions, 229 deletions
diff --git a/crypto/aes.c b/crypto/aes.c
index a5017292e066..a038711831e7 100644
--- a/crypto/aes.c
+++ b/crypto/aes.c
@@ -248,10 +248,10 @@ gen_tabs (void)
248 t ^= E_KEY[8 * i + 7]; E_KEY[8 * i + 15] = t; \ 248 t ^= E_KEY[8 * i + 7]; E_KEY[8 * i + 15] = t; \
249} 249}
250 250
251static int 251static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
252aes_set_key(void *ctx_arg, const u8 *in_key, unsigned int key_len, u32 *flags) 252 unsigned int key_len, u32 *flags)
253{ 253{
254 struct aes_ctx *ctx = ctx_arg; 254 struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
255 const __le32 *key = (const __le32 *)in_key; 255 const __le32 *key = (const __le32 *)in_key;
256 u32 i, t, u, v, w; 256 u32 i, t, u, v, w;
257 257
@@ -318,9 +318,9 @@ aes_set_key(void *ctx_arg, const u8 *in_key, unsigned int key_len, u32 *flags)
318 f_rl(bo, bi, 2, k); \ 318 f_rl(bo, bi, 2, k); \
319 f_rl(bo, bi, 3, k) 319 f_rl(bo, bi, 3, k)
320 320
321static void aes_encrypt(void *ctx_arg, u8 *out, const u8 *in) 321static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
322{ 322{
323 const struct aes_ctx *ctx = ctx_arg; 323 const struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
324 const __le32 *src = (const __le32 *)in; 324 const __le32 *src = (const __le32 *)in;
325 __le32 *dst = (__le32 *)out; 325 __le32 *dst = (__le32 *)out;
326 u32 b0[4], b1[4]; 326 u32 b0[4], b1[4];
@@ -373,9 +373,9 @@ static void aes_encrypt(void *ctx_arg, u8 *out, const u8 *in)
373 i_rl(bo, bi, 2, k); \ 373 i_rl(bo, bi, 2, k); \
374 i_rl(bo, bi, 3, k) 374 i_rl(bo, bi, 3, k)
375 375
376static void aes_decrypt(void *ctx_arg, u8 *out, const u8 *in) 376static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
377{ 377{
378 const struct aes_ctx *ctx = ctx_arg; 378 const struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
379 const __le32 *src = (const __le32 *)in; 379 const __le32 *src = (const __le32 *)in;
380 __le32 *dst = (__le32 *)out; 380 __le32 *dst = (__le32 *)out;
381 u32 b0[4], b1[4]; 381 u32 b0[4], b1[4];
diff --git a/crypto/anubis.c b/crypto/anubis.c
index 2c796bdb91a6..7e2e1a29800e 100644
--- a/crypto/anubis.c
+++ b/crypto/anubis.c
@@ -460,16 +460,15 @@ static const u32 rc[] = {
460 0xf726ffedU, 0xe89d6f8eU, 0x19a0f089U, 460 0xf726ffedU, 0xe89d6f8eU, 0x19a0f089U,
461}; 461};
462 462
463static int anubis_setkey(void *ctx_arg, const u8 *in_key, 463static int anubis_setkey(struct crypto_tfm *tfm, const u8 *in_key,
464 unsigned int key_len, u32 *flags) 464 unsigned int key_len, u32 *flags)
465{ 465{
466 struct anubis_ctx *ctx = crypto_tfm_ctx(tfm);
466 const __be32 *key = (const __be32 *)in_key; 467 const __be32 *key = (const __be32 *)in_key;
467 int N, R, i, r; 468 int N, R, i, r;
468 u32 kappa[ANUBIS_MAX_N]; 469 u32 kappa[ANUBIS_MAX_N];
469 u32 inter[ANUBIS_MAX_N]; 470 u32 inter[ANUBIS_MAX_N];
470 471
471 struct anubis_ctx *ctx = ctx_arg;
472
473 switch (key_len) 472 switch (key_len)
474 { 473 {
475 case 16: case 20: case 24: case 28: 474 case 16: case 20: case 24: case 28:
@@ -660,15 +659,15 @@ static void anubis_crypt(u32 roundKey[ANUBIS_MAX_ROUNDS + 1][4],
660 dst[i] = cpu_to_be32(inter[i]); 659 dst[i] = cpu_to_be32(inter[i]);
661} 660}
662 661
663static void anubis_encrypt(void *ctx_arg, u8 *dst, const u8 *src) 662static void anubis_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
664{ 663{
665 struct anubis_ctx *ctx = ctx_arg; 664 struct anubis_ctx *ctx = crypto_tfm_ctx(tfm);
666 anubis_crypt(ctx->E, dst, src, ctx->R); 665 anubis_crypt(ctx->E, dst, src, ctx->R);
667} 666}
668 667
669static void anubis_decrypt(void *ctx_arg, u8 *dst, const u8 *src) 668static void anubis_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
670{ 669{
671 struct anubis_ctx *ctx = ctx_arg; 670 struct anubis_ctx *ctx = crypto_tfm_ctx(tfm);
672 anubis_crypt(ctx->D, dst, src, ctx->R); 671 anubis_crypt(ctx->D, dst, src, ctx->R);
673} 672}
674 673
diff --git a/crypto/arc4.c b/crypto/arc4.c
index 9efbcaae88a1..5edc6a65b987 100644
--- a/crypto/arc4.c
+++ b/crypto/arc4.c
@@ -24,9 +24,10 @@ struct arc4_ctx {
24 u8 x, y; 24 u8 x, y;
25}; 25};
26 26
27static int arc4_set_key(void *ctx_arg, const u8 *in_key, unsigned int key_len, u32 *flags) 27static int arc4_set_key(struct crypto_tfm *tfm, const u8 *in_key,
28 unsigned int key_len, u32 *flags)
28{ 29{
29 struct arc4_ctx *ctx = ctx_arg; 30 struct arc4_ctx *ctx = crypto_tfm_ctx(tfm);
30 int i, j = 0, k = 0; 31 int i, j = 0, k = 0;
31 32
32 ctx->x = 1; 33 ctx->x = 1;
@@ -48,9 +49,9 @@ static int arc4_set_key(void *ctx_arg, const u8 *in_key, unsigned int key_len, u
48 return 0; 49 return 0;
49} 50}
50 51
51static void arc4_crypt(void *ctx_arg, u8 *out, const u8 *in) 52static void arc4_crypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
52{ 53{
53 struct arc4_ctx *ctx = ctx_arg; 54 struct arc4_ctx *ctx = crypto_tfm_ctx(tfm);
54 55
55 u8 *const S = ctx->S; 56 u8 *const S = ctx->S;
56 u8 x = ctx->x; 57 u8 x = ctx->x;
diff --git a/crypto/blowfish.c b/crypto/blowfish.c
index 7f710b201f20..490265f42b3b 100644
--- a/crypto/blowfish.c
+++ b/crypto/blowfish.c
@@ -349,7 +349,7 @@ static void encrypt_block(struct bf_ctx *bctx, u32 *dst, u32 *src)
349 dst[1] = yl; 349 dst[1] = yl;
350} 350}
351 351
352static void bf_encrypt(void *ctx, u8 *dst, const u8 *src) 352static void bf_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
353{ 353{
354 const __be32 *in_blk = (const __be32 *)src; 354 const __be32 *in_blk = (const __be32 *)src;
355 __be32 *const out_blk = (__be32 *)dst; 355 __be32 *const out_blk = (__be32 *)dst;
@@ -357,17 +357,18 @@ static void bf_encrypt(void *ctx, u8 *dst, const u8 *src)
357 357
358 in32[0] = be32_to_cpu(in_blk[0]); 358 in32[0] = be32_to_cpu(in_blk[0]);
359 in32[1] = be32_to_cpu(in_blk[1]); 359 in32[1] = be32_to_cpu(in_blk[1]);
360 encrypt_block(ctx, out32, in32); 360 encrypt_block(crypto_tfm_ctx(tfm), out32, in32);
361 out_blk[0] = cpu_to_be32(out32[0]); 361 out_blk[0] = cpu_to_be32(out32[0]);
362 out_blk[1] = cpu_to_be32(out32[1]); 362 out_blk[1] = cpu_to_be32(out32[1]);
363} 363}
364 364
365static void bf_decrypt(void *ctx, u8 *dst, const u8 *src) 365static void bf_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
366{ 366{
367 struct bf_ctx *ctx = crypto_tfm_ctx(tfm);
367 const __be32 *in_blk = (const __be32 *)src; 368 const __be32 *in_blk = (const __be32 *)src;
368 __be32 *const out_blk = (__be32 *)dst; 369 __be32 *const out_blk = (__be32 *)dst;
369 const u32 *P = ((struct bf_ctx *)ctx)->p; 370 const u32 *P = ctx->p;
370 const u32 *S = ((struct bf_ctx *)ctx)->s; 371 const u32 *S = ctx->s;
371 u32 yl = be32_to_cpu(in_blk[0]); 372 u32 yl = be32_to_cpu(in_blk[0]);
372 u32 yr = be32_to_cpu(in_blk[1]); 373 u32 yr = be32_to_cpu(in_blk[1]);
373 374
@@ -398,12 +399,14 @@ static void bf_decrypt(void *ctx, u8 *dst, const u8 *src)
398/* 399/*
399 * Calculates the blowfish S and P boxes for encryption and decryption. 400 * Calculates the blowfish S and P boxes for encryption and decryption.
400 */ 401 */
401static int bf_setkey(void *ctx, const u8 *key, unsigned int keylen, u32 *flags) 402static int bf_setkey(struct crypto_tfm *tfm, const u8 *key,
403 unsigned int keylen, u32 *flags)
402{ 404{
405 struct bf_ctx *ctx = crypto_tfm_ctx(tfm);
406 u32 *P = ctx->p;
407 u32 *S = ctx->s;
403 short i, j, count; 408 short i, j, count;
404 u32 data[2], temp; 409 u32 data[2], temp;
405 u32 *P = ((struct bf_ctx *)ctx)->p;
406 u32 *S = ((struct bf_ctx *)ctx)->s;
407 410
408 /* Copy the initialization s-boxes */ 411 /* Copy the initialization s-boxes */
409 for (i = 0, count = 0; i < 256; i++) 412 for (i = 0, count = 0; i < 256; i++)
diff --git a/crypto/cast5.c b/crypto/cast5.c
index 8834c8580c04..08eef58c1d3d 100644
--- a/crypto/cast5.c
+++ b/crypto/cast5.c
@@ -577,9 +577,9 @@ static const u32 sb8[256] = {
577 (((s1[I >> 24] + s2[(I>>16)&0xff]) ^ s3[(I>>8)&0xff]) - s4[I&0xff]) ) 577 (((s1[I >> 24] + s2[(I>>16)&0xff]) ^ s3[(I>>8)&0xff]) - s4[I&0xff]) )
578 578
579 579
580static void cast5_encrypt(void *ctx, u8 * outbuf, const u8 * inbuf) 580static void cast5_encrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf)
581{ 581{
582 struct cast5_ctx *c = (struct cast5_ctx *) ctx; 582 struct cast5_ctx *c = crypto_tfm_ctx(tfm);
583 const __be32 *src = (const __be32 *)inbuf; 583 const __be32 *src = (const __be32 *)inbuf;
584 __be32 *dst = (__be32 *)outbuf; 584 __be32 *dst = (__be32 *)outbuf;
585 u32 l, r, t; 585 u32 l, r, t;
@@ -642,9 +642,9 @@ static void cast5_encrypt(void *ctx, u8 * outbuf, const u8 * inbuf)
642 dst[1] = cpu_to_be32(l); 642 dst[1] = cpu_to_be32(l);
643} 643}
644 644
645static void cast5_decrypt(void *ctx, u8 * outbuf, const u8 * inbuf) 645static void cast5_decrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf)
646{ 646{
647 struct cast5_ctx *c = (struct cast5_ctx *) ctx; 647 struct cast5_ctx *c = crypto_tfm_ctx(tfm);
648 const __be32 *src = (const __be32 *)inbuf; 648 const __be32 *src = (const __be32 *)inbuf;
649 __be32 *dst = (__be32 *)outbuf; 649 __be32 *dst = (__be32 *)outbuf;
650 u32 l, r, t; 650 u32 l, r, t;
@@ -769,15 +769,15 @@ static void key_schedule(u32 * x, u32 * z, u32 * k)
769} 769}
770 770
771 771
772static int 772static int cast5_setkey(struct crypto_tfm *tfm, const u8 *key,
773cast5_setkey(void *ctx, const u8 * key, unsigned key_len, u32 * flags) 773 unsigned key_len, u32 *flags)
774{ 774{
775 struct cast5_ctx *c = crypto_tfm_ctx(tfm);
775 int i; 776 int i;
776 u32 x[4]; 777 u32 x[4];
777 u32 z[4]; 778 u32 z[4];
778 u32 k[16]; 779 u32 k[16];
779 __be32 p_key[4]; 780 __be32 p_key[4];
780 struct cast5_ctx *c = (struct cast5_ctx *) ctx;
781 781
782 if (key_len < 5 || key_len > 16) { 782 if (key_len < 5 || key_len > 16) {
783 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; 783 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
diff --git a/crypto/cast6.c b/crypto/cast6.c
index 9e28740ba775..08e33bfc3ad1 100644
--- a/crypto/cast6.c
+++ b/crypto/cast6.c
@@ -381,13 +381,13 @@ static inline void W(u32 *key, unsigned int i) {
381 key[7] ^= F2(key[0], Tr[i % 4][7], Tm[i][7]); 381 key[7] ^= F2(key[0], Tr[i % 4][7], Tm[i][7]);
382} 382}
383 383
384static int 384static int cast6_setkey(struct crypto_tfm *tfm, const u8 *in_key,
385cast6_setkey(void *ctx, const u8 * in_key, unsigned key_len, u32 * flags) 385 unsigned key_len, u32 *flags)
386{ 386{
387 int i; 387 int i;
388 u32 key[8]; 388 u32 key[8];
389 __be32 p_key[8]; /* padded key */ 389 __be32 p_key[8]; /* padded key */
390 struct cast6_ctx *c = (struct cast6_ctx *) ctx; 390 struct cast6_ctx *c = crypto_tfm_ctx(tfm);
391 391
392 if (key_len < 16 || key_len > 32 || key_len % 4 != 0) { 392 if (key_len < 16 || key_len > 32 || key_len % 4 != 0) {
393 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; 393 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
@@ -444,8 +444,9 @@ static inline void QBAR (u32 * block, u8 * Kr, u32 * Km) {
444 block[2] ^= F1(block[3], Kr[0], Km[0]); 444 block[2] ^= F1(block[3], Kr[0], Km[0]);
445} 445}
446 446
447static void cast6_encrypt (void * ctx, u8 * outbuf, const u8 * inbuf) { 447static void cast6_encrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf)
448 struct cast6_ctx * c = (struct cast6_ctx *)ctx; 448{
449 struct cast6_ctx *c = crypto_tfm_ctx(tfm);
449 const __be32 *src = (const __be32 *)inbuf; 450 const __be32 *src = (const __be32 *)inbuf;
450 __be32 *dst = (__be32 *)outbuf; 451 __be32 *dst = (__be32 *)outbuf;
451 u32 block[4]; 452 u32 block[4];
@@ -476,8 +477,8 @@ static void cast6_encrypt (void * ctx, u8 * outbuf, const u8 * inbuf) {
476 dst[3] = cpu_to_be32(block[3]); 477 dst[3] = cpu_to_be32(block[3]);
477} 478}
478 479
479static void cast6_decrypt (void * ctx, u8 * outbuf, const u8 * inbuf) { 480static void cast6_decrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf) {
480 struct cast6_ctx * c = (struct cast6_ctx *)ctx; 481 struct cast6_ctx * c = crypto_tfm_ctx(tfm);
481 const __be32 *src = (const __be32 *)inbuf; 482 const __be32 *src = (const __be32 *)inbuf;
482 __be32 *dst = (__be32 *)outbuf; 483 __be32 *dst = (__be32 *)outbuf;
483 u32 block[4]; 484 u32 block[4];
diff --git a/crypto/cipher.c b/crypto/cipher.c
index 65bcea0cd17c..b899eb97abd7 100644
--- a/crypto/cipher.c
+++ b/crypto/cipher.c
@@ -187,7 +187,7 @@ static unsigned int cbc_process_encrypt(const struct cipher_desc *desc,
187 void (*xor)(u8 *, const u8 *) = tfm->crt_u.cipher.cit_xor_block; 187 void (*xor)(u8 *, const u8 *) = tfm->crt_u.cipher.cit_xor_block;
188 int bsize = crypto_tfm_alg_blocksize(tfm); 188 int bsize = crypto_tfm_alg_blocksize(tfm);
189 189
190 void (*fn)(void *, u8 *, const u8 *) = desc->crfn; 190 void (*fn)(struct crypto_tfm *, u8 *, const u8 *) = desc->crfn;
191 u8 *iv = desc->info; 191 u8 *iv = desc->info;
192 unsigned int done = 0; 192 unsigned int done = 0;
193 193
@@ -195,7 +195,7 @@ static unsigned int cbc_process_encrypt(const struct cipher_desc *desc,
195 195
196 do { 196 do {
197 xor(iv, src); 197 xor(iv, src);
198 fn(crypto_tfm_ctx(tfm), dst, iv); 198 fn(tfm, dst, iv);
199 memcpy(iv, dst, bsize); 199 memcpy(iv, dst, bsize);
200 200
201 src += bsize; 201 src += bsize;
@@ -218,7 +218,7 @@ static unsigned int cbc_process_decrypt(const struct cipher_desc *desc,
218 u8 *buf = (u8 *)ALIGN((unsigned long)stack, alignmask + 1); 218 u8 *buf = (u8 *)ALIGN((unsigned long)stack, alignmask + 1);
219 u8 **dst_p = src == dst ? &buf : &dst; 219 u8 **dst_p = src == dst ? &buf : &dst;
220 220
221 void (*fn)(void *, u8 *, const u8 *) = desc->crfn; 221 void (*fn)(struct crypto_tfm *, u8 *, const u8 *) = desc->crfn;
222 u8 *iv = desc->info; 222 u8 *iv = desc->info;
223 unsigned int done = 0; 223 unsigned int done = 0;
224 224
@@ -227,7 +227,7 @@ static unsigned int cbc_process_decrypt(const struct cipher_desc *desc,
227 do { 227 do {
228 u8 *tmp_dst = *dst_p; 228 u8 *tmp_dst = *dst_p;
229 229
230 fn(crypto_tfm_ctx(tfm), tmp_dst, src); 230 fn(tfm, tmp_dst, src);
231 xor(tmp_dst, iv); 231 xor(tmp_dst, iv);
232 memcpy(iv, src, bsize); 232 memcpy(iv, src, bsize);
233 if (tmp_dst != dst) 233 if (tmp_dst != dst)
@@ -245,13 +245,13 @@ static unsigned int ecb_process(const struct cipher_desc *desc, u8 *dst,
245{ 245{
246 struct crypto_tfm *tfm = desc->tfm; 246 struct crypto_tfm *tfm = desc->tfm;
247 int bsize = crypto_tfm_alg_blocksize(tfm); 247 int bsize = crypto_tfm_alg_blocksize(tfm);
248 void (*fn)(void *, u8 *, const u8 *) = desc->crfn; 248 void (*fn)(struct crypto_tfm *, u8 *, const u8 *) = desc->crfn;
249 unsigned int done = 0; 249 unsigned int done = 0;
250 250
251 nbytes -= bsize; 251 nbytes -= bsize;
252 252
253 do { 253 do {
254 fn(crypto_tfm_ctx(tfm), dst, src); 254 fn(tfm, dst, src);
255 255
256 src += bsize; 256 src += bsize;
257 dst += bsize; 257 dst += bsize;
@@ -268,7 +268,7 @@ static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
268 tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; 268 tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
269 return -EINVAL; 269 return -EINVAL;
270 } else 270 } else
271 return cia->cia_setkey(crypto_tfm_ctx(tfm), key, keylen, 271 return cia->cia_setkey(tfm, key, keylen,
272 &tfm->crt_flags); 272 &tfm->crt_flags);
273} 273}
274 274
diff --git a/crypto/compress.c b/crypto/compress.c
index eb36d9364da3..c12fc0c41dac 100644
--- a/crypto/compress.c
+++ b/crypto/compress.c
@@ -22,8 +22,7 @@ static int crypto_compress(struct crypto_tfm *tfm,
22 const u8 *src, unsigned int slen, 22 const u8 *src, unsigned int slen,
23 u8 *dst, unsigned int *dlen) 23 u8 *dst, unsigned int *dlen)
24{ 24{
25 return tfm->__crt_alg->cra_compress.coa_compress(crypto_tfm_ctx(tfm), 25 return tfm->__crt_alg->cra_compress.coa_compress(tfm, src, slen, dst,
26 src, slen, dst,
27 dlen); 26 dlen);
28} 27}
29 28
@@ -31,8 +30,7 @@ static int crypto_decompress(struct crypto_tfm *tfm,
31 const u8 *src, unsigned int slen, 30 const u8 *src, unsigned int slen,
32 u8 *dst, unsigned int *dlen) 31 u8 *dst, unsigned int *dlen)
33{ 32{
34 return tfm->__crt_alg->cra_compress.coa_decompress(crypto_tfm_ctx(tfm), 33 return tfm->__crt_alg->cra_compress.coa_decompress(tfm, src, slen, dst,
35 src, slen, dst,
36 dlen); 34 dlen);
37} 35}
38 36
diff --git a/crypto/crc32c.c b/crypto/crc32c.c
index 953362423a5c..f2660123aeb4 100644
--- a/crypto/crc32c.c
+++ b/crypto/crc32c.c
@@ -31,9 +31,9 @@ struct chksum_ctx {
31 * crc using table. 31 * crc using table.
32 */ 32 */
33 33
34static void chksum_init(void *ctx) 34static void chksum_init(struct crypto_tfm *tfm)
35{ 35{
36 struct chksum_ctx *mctx = ctx; 36 struct chksum_ctx *mctx = crypto_tfm_ctx(tfm);
37 37
38 mctx->crc = ~(u32)0; /* common usage */ 38 mctx->crc = ~(u32)0; /* common usage */
39} 39}
@@ -43,10 +43,10 @@ static void chksum_init(void *ctx)
43 * If your algorithm starts with ~0, then XOR with ~0 before you set 43 * If your algorithm starts with ~0, then XOR with ~0 before you set
44 * the seed. 44 * the seed.
45 */ 45 */
46static int chksum_setkey(void *ctx, const u8 *key, unsigned int keylen, 46static int chksum_setkey(struct crypto_tfm *tfm, const u8 *key,
47 u32 *flags) 47 unsigned int keylen, u32 *flags)
48{ 48{
49 struct chksum_ctx *mctx = ctx; 49 struct chksum_ctx *mctx = crypto_tfm_ctx(tfm);
50 50
51 if (keylen != sizeof(mctx->crc)) { 51 if (keylen != sizeof(mctx->crc)) {
52 if (flags) 52 if (flags)
@@ -57,9 +57,10 @@ static int chksum_setkey(void *ctx, const u8 *key, unsigned int keylen,
57 return 0; 57 return 0;
58} 58}
59 59
60static void chksum_update(void *ctx, const u8 *data, unsigned int length) 60static void chksum_update(struct crypto_tfm *tfm, const u8 *data,
61 unsigned int length)
61{ 62{
62 struct chksum_ctx *mctx = ctx; 63 struct chksum_ctx *mctx = crypto_tfm_ctx(tfm);
63 u32 mcrc; 64 u32 mcrc;
64 65
65 mcrc = crc32c(mctx->crc, data, (size_t)length); 66 mcrc = crc32c(mctx->crc, data, (size_t)length);
@@ -67,9 +68,9 @@ static void chksum_update(void *ctx, const u8 *data, unsigned int length)
67 mctx->crc = mcrc; 68 mctx->crc = mcrc;
68} 69}
69 70
70static void chksum_final(void *ctx, u8 *out) 71static void chksum_final(struct crypto_tfm *tfm, u8 *out)
71{ 72{
72 struct chksum_ctx *mctx = ctx; 73 struct chksum_ctx *mctx = crypto_tfm_ctx(tfm);
73 u32 mcrc = (mctx->crc ^ ~(u32)0); 74 u32 mcrc = (mctx->crc ^ ~(u32)0);
74 75
75 *(u32 *)out = __le32_to_cpu(mcrc); 76 *(u32 *)out = __le32_to_cpu(mcrc);
diff --git a/crypto/crypto_null.c b/crypto/crypto_null.c
index 3fcf6e887e87..a0d956b52949 100644
--- a/crypto/crypto_null.c
+++ b/crypto/crypto_null.c
@@ -27,8 +27,8 @@
27#define NULL_BLOCK_SIZE 1 27#define NULL_BLOCK_SIZE 1
28#define NULL_DIGEST_SIZE 0 28#define NULL_DIGEST_SIZE 0
29 29
30static int null_compress(void *ctx, const u8 *src, unsigned int slen, 30static int null_compress(struct crypto_tfm *tfm, const u8 *src,
31 u8 *dst, unsigned int *dlen) 31 unsigned int slen, u8 *dst, unsigned int *dlen)
32{ 32{
33 if (slen > *dlen) 33 if (slen > *dlen)
34 return -EINVAL; 34 return -EINVAL;
@@ -37,20 +37,21 @@ static int null_compress(void *ctx, const u8 *src, unsigned int slen,
37 return 0; 37 return 0;
38} 38}
39 39
40static void null_init(void *ctx) 40static void null_init(struct crypto_tfm *tfm)
41{ } 41{ }
42 42
43static void null_update(void *ctx, const u8 *data, unsigned int len) 43static void null_update(struct crypto_tfm *tfm, const u8 *data,
44 unsigned int len)
44{ } 45{ }
45 46
46static void null_final(void *ctx, u8 *out) 47static void null_final(struct crypto_tfm *tfm, u8 *out)
47{ } 48{ }
48 49
49static int null_setkey(void *ctx, const u8 *key, 50static int null_setkey(struct crypto_tfm *tfm, const u8 *key,
50 unsigned int keylen, u32 *flags) 51 unsigned int keylen, u32 *flags)
51{ return 0; } 52{ return 0; }
52 53
53static void null_crypt(void *ctx, u8 *dst, const u8 *src) 54static void null_crypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
54{ 55{
55 memcpy(dst, src, NULL_BLOCK_SIZE); 56 memcpy(dst, src, NULL_BLOCK_SIZE);
56} 57}
diff --git a/crypto/deflate.c b/crypto/deflate.c
index f209368d62ae..5dd2404ae5b2 100644
--- a/crypto/deflate.c
+++ b/crypto/deflate.c
@@ -102,8 +102,9 @@ static void deflate_decomp_exit(struct deflate_ctx *ctx)
102 kfree(ctx->decomp_stream.workspace); 102 kfree(ctx->decomp_stream.workspace);
103} 103}
104 104
105static int deflate_init(void *ctx) 105static int deflate_init(struct crypto_tfm *tfm)
106{ 106{
107 struct deflate_ctx *ctx = crypto_tfm_ctx(tfm);
107 int ret; 108 int ret;
108 109
109 ret = deflate_comp_init(ctx); 110 ret = deflate_comp_init(ctx);
@@ -116,17 +117,19 @@ out:
116 return ret; 117 return ret;
117} 118}
118 119
119static void deflate_exit(void *ctx) 120static void deflate_exit(struct crypto_tfm *tfm)
120{ 121{
122 struct deflate_ctx *ctx = crypto_tfm_ctx(tfm);
123
121 deflate_comp_exit(ctx); 124 deflate_comp_exit(ctx);
122 deflate_decomp_exit(ctx); 125 deflate_decomp_exit(ctx);
123} 126}
124 127
125static int deflate_compress(void *ctx, const u8 *src, unsigned int slen, 128static int deflate_compress(struct crypto_tfm *tfm, const u8 *src,
126 u8 *dst, unsigned int *dlen) 129 unsigned int slen, u8 *dst, unsigned int *dlen)
127{ 130{
128 int ret = 0; 131 int ret = 0;
129 struct deflate_ctx *dctx = ctx; 132 struct deflate_ctx *dctx = crypto_tfm_ctx(tfm);
130 struct z_stream_s *stream = &dctx->comp_stream; 133 struct z_stream_s *stream = &dctx->comp_stream;
131 134
132 ret = zlib_deflateReset(stream); 135 ret = zlib_deflateReset(stream);
@@ -151,12 +154,12 @@ out:
151 return ret; 154 return ret;
152} 155}
153 156
154static int deflate_decompress(void *ctx, const u8 *src, unsigned int slen, 157static int deflate_decompress(struct crypto_tfm *tfm, const u8 *src,
155 u8 *dst, unsigned int *dlen) 158 unsigned int slen, u8 *dst, unsigned int *dlen)
156{ 159{
157 160
158 int ret = 0; 161 int ret = 0;
159 struct deflate_ctx *dctx = ctx; 162 struct deflate_ctx *dctx = crypto_tfm_ctx(tfm);
160 struct z_stream_s *stream = &dctx->decomp_stream; 163 struct z_stream_s *stream = &dctx->decomp_stream;
161 164
162 ret = zlib_inflateReset(stream); 165 ret = zlib_inflateReset(stream);
diff --git a/crypto/des.c b/crypto/des.c
index 2d74cab40c3e..a9d3c235a6af 100644
--- a/crypto/des.c
+++ b/crypto/des.c
@@ -783,9 +783,10 @@ static void dkey(u32 *pe, const u8 *k)
783 } 783 }
784} 784}
785 785
786static int des_setkey(void *ctx, const u8 *key, unsigned int keylen, u32 *flags) 786static int des_setkey(struct crypto_tfm *tfm, const u8 *key,
787 unsigned int keylen, u32 *flags)
787{ 788{
788 struct des_ctx *dctx = ctx; 789 struct des_ctx *dctx = crypto_tfm_ctx(tfm);
789 u32 tmp[DES_EXPKEY_WORDS]; 790 u32 tmp[DES_EXPKEY_WORDS];
790 int ret; 791 int ret;
791 792
@@ -803,9 +804,10 @@ static int des_setkey(void *ctx, const u8 *key, unsigned int keylen, u32 *flags)
803 return 0; 804 return 0;
804} 805}
805 806
806static void des_encrypt(void *ctx, u8 *dst, const u8 *src) 807static void des_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
807{ 808{
808 const u32 *K = ((struct des_ctx *)ctx)->expkey; 809 struct des_ctx *ctx = crypto_tfm_ctx(tfm);
810 const u32 *K = ctx->expkey;
809 const __le32 *s = (const __le32 *)src; 811 const __le32 *s = (const __le32 *)src;
810 __le32 *d = (__le32 *)dst; 812 __le32 *d = (__le32 *)dst;
811 u32 L, R, A, B; 813 u32 L, R, A, B;
@@ -825,9 +827,10 @@ static void des_encrypt(void *ctx, u8 *dst, const u8 *src)
825 d[1] = cpu_to_le32(L); 827 d[1] = cpu_to_le32(L);
826} 828}
827 829
828static void des_decrypt(void *ctx, u8 *dst, const u8 *src) 830static void des_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
829{ 831{
830 const u32 *K = ((struct des_ctx *)ctx)->expkey + DES_EXPKEY_WORDS - 2; 832 struct des_ctx *ctx = crypto_tfm_ctx(tfm);
833 const u32 *K = ctx->expkey + DES_EXPKEY_WORDS - 2;
831 const __le32 *s = (const __le32 *)src; 834 const __le32 *s = (const __le32 *)src;
832 __le32 *d = (__le32 *)dst; 835 __le32 *d = (__le32 *)dst;
833 u32 L, R, A, B; 836 u32 L, R, A, B;
@@ -860,11 +863,11 @@ static void des_decrypt(void *ctx, u8 *dst, const u8 *src)
860 * property. 863 * property.
861 * 864 *
862 */ 865 */
863static int des3_ede_setkey(void *ctx, const u8 *key, 866static int des3_ede_setkey(struct crypto_tfm *tfm, const u8 *key,
864 unsigned int keylen, u32 *flags) 867 unsigned int keylen, u32 *flags)
865{ 868{
866 const u32 *K = (const u32 *)key; 869 const u32 *K = (const u32 *)key;
867 struct des3_ede_ctx *dctx = ctx; 870 struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm);
868 u32 *expkey = dctx->expkey; 871 u32 *expkey = dctx->expkey;
869 872
870 if (unlikely(!((K[0] ^ K[2]) | (K[1] ^ K[3])) || 873 if (unlikely(!((K[0] ^ K[2]) | (K[1] ^ K[3])) ||
@@ -881,9 +884,9 @@ static int des3_ede_setkey(void *ctx, const u8 *key,
881 return 0; 884 return 0;
882} 885}
883 886
884static void des3_ede_encrypt(void *ctx, u8 *dst, const u8 *src) 887static void des3_ede_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
885{ 888{
886 struct des3_ede_ctx *dctx = ctx; 889 struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm);
887 const u32 *K = dctx->expkey; 890 const u32 *K = dctx->expkey;
888 const __le32 *s = (const __le32 *)src; 891 const __le32 *s = (const __le32 *)src;
889 __le32 *d = (__le32 *)dst; 892 __le32 *d = (__le32 *)dst;
@@ -912,9 +915,9 @@ static void des3_ede_encrypt(void *ctx, u8 *dst, const u8 *src)
912 d[1] = cpu_to_le32(L); 915 d[1] = cpu_to_le32(L);
913} 916}
914 917
915static void des3_ede_decrypt(void *ctx, u8 *dst, const u8 *src) 918static void des3_ede_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
916{ 919{
917 struct des3_ede_ctx *dctx = ctx; 920 struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm);
918 const u32 *K = dctx->expkey + DES3_EDE_EXPKEY_WORDS - 2; 921 const u32 *K = dctx->expkey + DES3_EDE_EXPKEY_WORDS - 2;
919 const __le32 *s = (const __le32 *)src; 922 const __le32 *s = (const __le32 *)src;
920 __le32 *d = (__le32 *)dst; 923 __le32 *d = (__le32 *)dst;
diff --git a/crypto/digest.c b/crypto/digest.c
index 062d0a5a2c89..2d9d509c2c51 100644
--- a/crypto/digest.c
+++ b/crypto/digest.c
@@ -20,7 +20,7 @@
20 20
21static void init(struct crypto_tfm *tfm) 21static void init(struct crypto_tfm *tfm)
22{ 22{
23 tfm->__crt_alg->cra_digest.dia_init(crypto_tfm_ctx(tfm)); 23 tfm->__crt_alg->cra_digest.dia_init(tfm);
24} 24}
25 25
26static void update(struct crypto_tfm *tfm, 26static void update(struct crypto_tfm *tfm,
@@ -46,16 +46,14 @@ static void update(struct crypto_tfm *tfm,
46 unsigned int bytes = 46 unsigned int bytes =
47 alignmask + 1 - (offset & alignmask); 47 alignmask + 1 - (offset & alignmask);
48 bytes = min(bytes, bytes_from_page); 48 bytes = min(bytes, bytes_from_page);
49 tfm->__crt_alg->cra_digest.dia_update 49 tfm->__crt_alg->cra_digest.dia_update(tfm, p,
50 (crypto_tfm_ctx(tfm), p, 50 bytes);
51 bytes);
52 p += bytes; 51 p += bytes;
53 bytes_from_page -= bytes; 52 bytes_from_page -= bytes;
54 l -= bytes; 53 l -= bytes;
55 } 54 }
56 tfm->__crt_alg->cra_digest.dia_update 55 tfm->__crt_alg->cra_digest.dia_update(tfm, p,
57 (crypto_tfm_ctx(tfm), p, 56 bytes_from_page);
58 bytes_from_page);
59 crypto_kunmap(src, 0); 57 crypto_kunmap(src, 0);
60 crypto_yield(tfm); 58 crypto_yield(tfm);
61 offset = 0; 59 offset = 0;
@@ -83,8 +81,7 @@ static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
83 u32 flags; 81 u32 flags;
84 if (tfm->__crt_alg->cra_digest.dia_setkey == NULL) 82 if (tfm->__crt_alg->cra_digest.dia_setkey == NULL)
85 return -ENOSYS; 83 return -ENOSYS;
86 return tfm->__crt_alg->cra_digest.dia_setkey(crypto_tfm_ctx(tfm), 84 return tfm->__crt_alg->cra_digest.dia_setkey(tfm, key, keylen, &flags);
87 key, keylen, &flags);
88} 85}
89 86
90static void digest(struct crypto_tfm *tfm, 87static void digest(struct crypto_tfm *tfm,
diff --git a/crypto/khazad.c b/crypto/khazad.c
index 5b8dc9a2d374..d4c9d3657b36 100644
--- a/crypto/khazad.c
+++ b/crypto/khazad.c
@@ -754,10 +754,10 @@ static const u64 c[KHAZAD_ROUNDS + 1] = {
754 0xccc41d14c363da5dULL, 0x5fdc7dcd7f5a6c5cULL, 0xf726ffede89d6f8eULL 754 0xccc41d14c363da5dULL, 0x5fdc7dcd7f5a6c5cULL, 0xf726ffede89d6f8eULL
755}; 755};
756 756
757static int khazad_setkey(void *ctx_arg, const u8 *in_key, 757static int khazad_setkey(struct crypto_tfm *tfm, const u8 *in_key,
758 unsigned int key_len, u32 *flags) 758 unsigned int key_len, u32 *flags)
759{ 759{
760 struct khazad_ctx *ctx = ctx_arg; 760 struct khazad_ctx *ctx = crypto_tfm_ctx(tfm);
761 const __be32 *key = (const __be32 *)in_key; 761 const __be32 *key = (const __be32 *)in_key;
762 int r; 762 int r;
763 const u64 *S = T7; 763 const u64 *S = T7;
@@ -841,15 +841,15 @@ static void khazad_crypt(const u64 roundKey[KHAZAD_ROUNDS + 1],
841 *dst = cpu_to_be64(state); 841 *dst = cpu_to_be64(state);
842} 842}
843 843
844static void khazad_encrypt(void *ctx_arg, u8 *dst, const u8 *src) 844static void khazad_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
845{ 845{
846 struct khazad_ctx *ctx = ctx_arg; 846 struct khazad_ctx *ctx = crypto_tfm_ctx(tfm);
847 khazad_crypt(ctx->E, dst, src); 847 khazad_crypt(ctx->E, dst, src);
848} 848}
849 849
850static void khazad_decrypt(void *ctx_arg, u8 *dst, const u8 *src) 850static void khazad_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
851{ 851{
852 struct khazad_ctx *ctx = ctx_arg; 852 struct khazad_ctx *ctx = crypto_tfm_ctx(tfm);
853 khazad_crypt(ctx->D, dst, src); 853 khazad_crypt(ctx->D, dst, src);
854} 854}
855 855
diff --git a/crypto/md4.c b/crypto/md4.c
index a2d6df5c0f8c..c1bc71bdc16b 100644
--- a/crypto/md4.c
+++ b/crypto/md4.c
@@ -152,9 +152,9 @@ static inline void md4_transform_helper(struct md4_ctx *ctx)
152 md4_transform(ctx->hash, ctx->block); 152 md4_transform(ctx->hash, ctx->block);
153} 153}
154 154
155static void md4_init(void *ctx) 155static void md4_init(struct crypto_tfm *tfm)
156{ 156{
157 struct md4_ctx *mctx = ctx; 157 struct md4_ctx *mctx = crypto_tfm_ctx(tfm);
158 158
159 mctx->hash[0] = 0x67452301; 159 mctx->hash[0] = 0x67452301;
160 mctx->hash[1] = 0xefcdab89; 160 mctx->hash[1] = 0xefcdab89;
@@ -163,9 +163,9 @@ static void md4_init(void *ctx)
163 mctx->byte_count = 0; 163 mctx->byte_count = 0;
164} 164}
165 165
166static void md4_update(void *ctx, const u8 *data, unsigned int len) 166static void md4_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len)
167{ 167{
168 struct md4_ctx *mctx = ctx; 168 struct md4_ctx *mctx = crypto_tfm_ctx(tfm);
169 const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f); 169 const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f);
170 170
171 mctx->byte_count += len; 171 mctx->byte_count += len;
@@ -193,9 +193,9 @@ static void md4_update(void *ctx, const u8 *data, unsigned int len)
193 memcpy(mctx->block, data, len); 193 memcpy(mctx->block, data, len);
194} 194}
195 195
196static void md4_final(void *ctx, u8 *out) 196static void md4_final(struct crypto_tfm *tfm, u8 *out)
197{ 197{
198 struct md4_ctx *mctx = ctx; 198 struct md4_ctx *mctx = crypto_tfm_ctx(tfm);
199 const unsigned int offset = mctx->byte_count & 0x3f; 199 const unsigned int offset = mctx->byte_count & 0x3f;
200 char *p = (char *)mctx->block + offset; 200 char *p = (char *)mctx->block + offset;
201 int padding = 56 - (offset + 1); 201 int padding = 56 - (offset + 1);
diff --git a/crypto/md5.c b/crypto/md5.c
index 7f041aef5da2..93d18e8b3d53 100644
--- a/crypto/md5.c
+++ b/crypto/md5.c
@@ -147,9 +147,9 @@ static inline void md5_transform_helper(struct md5_ctx *ctx)
147 md5_transform(ctx->hash, ctx->block); 147 md5_transform(ctx->hash, ctx->block);
148} 148}
149 149
150static void md5_init(void *ctx) 150static void md5_init(struct crypto_tfm *tfm)
151{ 151{
152 struct md5_ctx *mctx = ctx; 152 struct md5_ctx *mctx = crypto_tfm_ctx(tfm);
153 153
154 mctx->hash[0] = 0x67452301; 154 mctx->hash[0] = 0x67452301;
155 mctx->hash[1] = 0xefcdab89; 155 mctx->hash[1] = 0xefcdab89;
@@ -158,9 +158,9 @@ static void md5_init(void *ctx)
158 mctx->byte_count = 0; 158 mctx->byte_count = 0;
159} 159}
160 160
161static void md5_update(void *ctx, const u8 *data, unsigned int len) 161static void md5_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len)
162{ 162{
163 struct md5_ctx *mctx = ctx; 163 struct md5_ctx *mctx = crypto_tfm_ctx(tfm);
164 const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f); 164 const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f);
165 165
166 mctx->byte_count += len; 166 mctx->byte_count += len;
@@ -188,9 +188,9 @@ static void md5_update(void *ctx, const u8 *data, unsigned int len)
188 memcpy(mctx->block, data, len); 188 memcpy(mctx->block, data, len);
189} 189}
190 190
191static void md5_final(void *ctx, u8 *out) 191static void md5_final(struct crypto_tfm *tfm, u8 *out)
192{ 192{
193 struct md5_ctx *mctx = ctx; 193 struct md5_ctx *mctx = crypto_tfm_ctx(tfm);
194 const unsigned int offset = mctx->byte_count & 0x3f; 194 const unsigned int offset = mctx->byte_count & 0x3f;
195 char *p = (char *)mctx->block + offset; 195 char *p = (char *)mctx->block + offset;
196 int padding = 56 - (offset + 1); 196 int padding = 56 - (offset + 1);
diff --git a/crypto/michael_mic.c b/crypto/michael_mic.c
index 701f859ed767..d061da21cfda 100644
--- a/crypto/michael_mic.c
+++ b/crypto/michael_mic.c
@@ -45,16 +45,17 @@ do { \
45} while (0) 45} while (0)
46 46
47 47
48static void michael_init(void *ctx) 48static void michael_init(struct crypto_tfm *tfm)
49{ 49{
50 struct michael_mic_ctx *mctx = ctx; 50 struct michael_mic_ctx *mctx = crypto_tfm_ctx(tfm);
51 mctx->pending_len = 0; 51 mctx->pending_len = 0;
52} 52}
53 53
54 54
55static void michael_update(void *ctx, const u8 *data, unsigned int len) 55static void michael_update(struct crypto_tfm *tfm, const u8 *data,
56 unsigned int len)
56{ 57{
57 struct michael_mic_ctx *mctx = ctx; 58 struct michael_mic_ctx *mctx = crypto_tfm_ctx(tfm);
58 const __le32 *src; 59 const __le32 *src;
59 60
60 if (mctx->pending_len) { 61 if (mctx->pending_len) {
@@ -90,9 +91,9 @@ static void michael_update(void *ctx, const u8 *data, unsigned int len)
90} 91}
91 92
92 93
93static void michael_final(void *ctx, u8 *out) 94static void michael_final(struct crypto_tfm *tfm, u8 *out)
94{ 95{
95 struct michael_mic_ctx *mctx = ctx; 96 struct michael_mic_ctx *mctx = crypto_tfm_ctx(tfm);
96 u8 *data = mctx->pending; 97 u8 *data = mctx->pending;
97 __le32 *dst = (__le32 *)out; 98 __le32 *dst = (__le32 *)out;
98 99
@@ -121,10 +122,10 @@ static void michael_final(void *ctx, u8 *out)
121} 122}
122 123
123 124
124static int michael_setkey(void *ctx, const u8 *key, unsigned int keylen, 125static int michael_setkey(struct crypto_tfm *tfm, const u8 *key,
125 u32 *flags) 126 unsigned int keylen, u32 *flags)
126{ 127{
127 struct michael_mic_ctx *mctx = ctx; 128 struct michael_mic_ctx *mctx = crypto_tfm_ctx(tfm);
128 const __le32 *data = (const __le32 *)key; 129 const __le32 *data = (const __le32 *)key;
129 130
130 if (keylen != 8) { 131 if (keylen != 8) {
diff --git a/crypto/serpent.c b/crypto/serpent.c
index e366406ab49d..de60cdddbf4a 100644
--- a/crypto/serpent.c
+++ b/crypto/serpent.c
@@ -215,9 +215,11 @@ struct serpent_ctx {
215}; 215};
216 216
217 217
218static int serpent_setkey(void *ctx, const u8 *key, unsigned int keylen, u32 *flags) 218static int serpent_setkey(struct crypto_tfm *tfm, const u8 *key,
219 unsigned int keylen, u32 *flags)
219{ 220{
220 u32 *k = ((struct serpent_ctx *)ctx)->expkey; 221 struct serpent_ctx *ctx = crypto_tfm_ctx(tfm);
222 u32 *k = ctx->expkey;
221 u8 *k8 = (u8 *)k; 223 u8 *k8 = (u8 *)k;
222 u32 r0,r1,r2,r3,r4; 224 u32 r0,r1,r2,r3,r4;
223 int i; 225 int i;
@@ -365,10 +367,11 @@ static int serpent_setkey(void *ctx, const u8 *key, unsigned int keylen, u32 *fl
365 return 0; 367 return 0;
366} 368}
367 369
368static void serpent_encrypt(void *ctx, u8 *dst, const u8 *src) 370static void serpent_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
369{ 371{
372 struct serpent_ctx *ctx = crypto_tfm_ctx(tfm);
370 const u32 373 const u32
371 *k = ((struct serpent_ctx *)ctx)->expkey, 374 *k = ctx->expkey,
372 *s = (const u32 *)src; 375 *s = (const u32 *)src;
373 u32 *d = (u32 *)dst, 376 u32 *d = (u32 *)dst,
374 r0, r1, r2, r3, r4; 377 r0, r1, r2, r3, r4;
@@ -423,8 +426,9 @@ static void serpent_encrypt(void *ctx, u8 *dst, const u8 *src)
423 d[3] = cpu_to_le32(r3); 426 d[3] = cpu_to_le32(r3);
424} 427}
425 428
426static void serpent_decrypt(void *ctx, u8 *dst, const u8 *src) 429static void serpent_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
427{ 430{
431 struct serpent_ctx *ctx = crypto_tfm_ctx(tfm);
428 const u32 432 const u32
429 *k = ((struct serpent_ctx *)ctx)->expkey, 433 *k = ((struct serpent_ctx *)ctx)->expkey,
430 *s = (const u32 *)src; 434 *s = (const u32 *)src;
@@ -492,7 +496,8 @@ static struct crypto_alg serpent_alg = {
492 .cia_decrypt = serpent_decrypt } } 496 .cia_decrypt = serpent_decrypt } }
493}; 497};
494 498
495static int tnepres_setkey(void *ctx, const u8 *key, unsigned int keylen, u32 *flags) 499static int tnepres_setkey(struct crypto_tfm *tfm, const u8 *key,
500 unsigned int keylen, u32 *flags)
496{ 501{
497 u8 rev_key[SERPENT_MAX_KEY_SIZE]; 502 u8 rev_key[SERPENT_MAX_KEY_SIZE];
498 int i; 503 int i;
@@ -506,10 +511,10 @@ static int tnepres_setkey(void *ctx, const u8 *key, unsigned int keylen, u32 *fl
506 for (i = 0; i < keylen; ++i) 511 for (i = 0; i < keylen; ++i)
507 rev_key[keylen - i - 1] = key[i]; 512 rev_key[keylen - i - 1] = key[i];
508 513
509 return serpent_setkey(ctx, rev_key, keylen, flags); 514 return serpent_setkey(tfm, rev_key, keylen, flags);
510} 515}
511 516
512static void tnepres_encrypt(void *ctx, u8 *dst, const u8 *src) 517static void tnepres_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
513{ 518{
514 const u32 * const s = (const u32 * const)src; 519 const u32 * const s = (const u32 * const)src;
515 u32 * const d = (u32 * const)dst; 520 u32 * const d = (u32 * const)dst;
@@ -521,7 +526,7 @@ static void tnepres_encrypt(void *ctx, u8 *dst, const u8 *src)
521 rs[2] = swab32(s[1]); 526 rs[2] = swab32(s[1]);
522 rs[3] = swab32(s[0]); 527 rs[3] = swab32(s[0]);
523 528
524 serpent_encrypt(ctx, (u8 *)rd, (u8 *)rs); 529 serpent_encrypt(tfm, (u8 *)rd, (u8 *)rs);
525 530
526 d[0] = swab32(rd[3]); 531 d[0] = swab32(rd[3]);
527 d[1] = swab32(rd[2]); 532 d[1] = swab32(rd[2]);
@@ -529,7 +534,7 @@ static void tnepres_encrypt(void *ctx, u8 *dst, const u8 *src)
529 d[3] = swab32(rd[0]); 534 d[3] = swab32(rd[0]);
530} 535}
531 536
532static void tnepres_decrypt(void *ctx, u8 *dst, const u8 *src) 537static void tnepres_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
533{ 538{
534 const u32 * const s = (const u32 * const)src; 539 const u32 * const s = (const u32 * const)src;
535 u32 * const d = (u32 * const)dst; 540 u32 * const d = (u32 * const)dst;
@@ -541,7 +546,7 @@ static void tnepres_decrypt(void *ctx, u8 *dst, const u8 *src)
541 rs[2] = swab32(s[1]); 546 rs[2] = swab32(s[1]);
542 rs[3] = swab32(s[0]); 547 rs[3] = swab32(s[0]);
543 548
544 serpent_decrypt(ctx, (u8 *)rd, (u8 *)rs); 549 serpent_decrypt(tfm, (u8 *)rd, (u8 *)rs);
545 550
546 d[0] = swab32(rd[3]); 551 d[0] = swab32(rd[3]);
547 d[1] = swab32(rd[2]); 552 d[1] = swab32(rd[2]);
diff --git a/crypto/sha1.c b/crypto/sha1.c
index b96f57d95a82..6c77b689f87e 100644
--- a/crypto/sha1.c
+++ b/crypto/sha1.c
@@ -34,9 +34,9 @@ struct sha1_ctx {
34 u8 buffer[64]; 34 u8 buffer[64];
35}; 35};
36 36
37static void sha1_init(void *ctx) 37static void sha1_init(struct crypto_tfm *tfm)
38{ 38{
39 struct sha1_ctx *sctx = ctx; 39 struct sha1_ctx *sctx = crypto_tfm_ctx(tfm);
40 static const struct sha1_ctx initstate = { 40 static const struct sha1_ctx initstate = {
41 0, 41 0,
42 { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 }, 42 { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 },
@@ -46,9 +46,10 @@ static void sha1_init(void *ctx)
46 *sctx = initstate; 46 *sctx = initstate;
47} 47}
48 48
49static void sha1_update(void *ctx, const u8 *data, unsigned int len) 49static void sha1_update(struct crypto_tfm *tfm, const u8 *data,
50 unsigned int len)
50{ 51{
51 struct sha1_ctx *sctx = ctx; 52 struct sha1_ctx *sctx = crypto_tfm_ctx(tfm);
52 unsigned int partial, done; 53 unsigned int partial, done;
53 const u8 *src; 54 const u8 *src;
54 55
@@ -80,9 +81,9 @@ static void sha1_update(void *ctx, const u8 *data, unsigned int len)
80 81
81 82
82/* Add padding and return the message digest. */ 83/* Add padding and return the message digest. */
83static void sha1_final(void* ctx, u8 *out) 84static void sha1_final(struct crypto_tfm *tfm, u8 *out)
84{ 85{
85 struct sha1_ctx *sctx = ctx; 86 struct sha1_ctx *sctx = crypto_tfm_ctx(tfm);
86 __be32 *dst = (__be32 *)out; 87 __be32 *dst = (__be32 *)out;
87 u32 i, index, padlen; 88 u32 i, index, padlen;
88 __be64 bits; 89 __be64 bits;
@@ -93,10 +94,10 @@ static void sha1_final(void* ctx, u8 *out)
93 /* Pad out to 56 mod 64 */ 94 /* Pad out to 56 mod 64 */
94 index = sctx->count & 0x3f; 95 index = sctx->count & 0x3f;
95 padlen = (index < 56) ? (56 - index) : ((64+56) - index); 96 padlen = (index < 56) ? (56 - index) : ((64+56) - index);
96 sha1_update(sctx, padding, padlen); 97 sha1_update(tfm, padding, padlen);
97 98
98 /* Append length */ 99 /* Append length */
99 sha1_update(sctx, (const u8 *)&bits, sizeof(bits)); 100 sha1_update(tfm, (const u8 *)&bits, sizeof(bits));
100 101
101 /* Store state in digest */ 102 /* Store state in digest */
102 for (i = 0; i < 5; i++) 103 for (i = 0; i < 5; i++)
diff --git a/crypto/sha256.c b/crypto/sha256.c
index 4533a0564895..bc71d85a7d02 100644
--- a/crypto/sha256.c
+++ b/crypto/sha256.c
@@ -230,9 +230,9 @@ static void sha256_transform(u32 *state, const u8 *input)
230 memset(W, 0, 64 * sizeof(u32)); 230 memset(W, 0, 64 * sizeof(u32));
231} 231}
232 232
233static void sha256_init(void *ctx) 233static void sha256_init(struct crypto_tfm *tfm)
234{ 234{
235 struct sha256_ctx *sctx = ctx; 235 struct sha256_ctx *sctx = crypto_tfm_ctx(tfm);
236 sctx->state[0] = H0; 236 sctx->state[0] = H0;
237 sctx->state[1] = H1; 237 sctx->state[1] = H1;
238 sctx->state[2] = H2; 238 sctx->state[2] = H2;
@@ -244,9 +244,10 @@ static void sha256_init(void *ctx)
244 sctx->count[0] = sctx->count[1] = 0; 244 sctx->count[0] = sctx->count[1] = 0;
245} 245}
246 246
247static void sha256_update(void *ctx, const u8 *data, unsigned int len) 247static void sha256_update(struct crypto_tfm *tfm, const u8 *data,
248 unsigned int len)
248{ 249{
249 struct sha256_ctx *sctx = ctx; 250 struct sha256_ctx *sctx = crypto_tfm_ctx(tfm);
250 unsigned int i, index, part_len; 251 unsigned int i, index, part_len;
251 252
252 /* Compute number of bytes mod 128 */ 253 /* Compute number of bytes mod 128 */
@@ -276,9 +277,9 @@ static void sha256_update(void *ctx, const u8 *data, unsigned int len)
276 memcpy(&sctx->buf[index], &data[i], len-i); 277 memcpy(&sctx->buf[index], &data[i], len-i);
277} 278}
278 279
279static void sha256_final(void* ctx, u8 *out) 280static void sha256_final(struct crypto_tfm *tfm, u8 *out)
280{ 281{
281 struct sha256_ctx *sctx = ctx; 282 struct sha256_ctx *sctx = crypto_tfm_ctx(tfm);
282 __be32 *dst = (__be32 *)out; 283 __be32 *dst = (__be32 *)out;
283 __be32 bits[2]; 284 __be32 bits[2];
284 unsigned int index, pad_len; 285 unsigned int index, pad_len;
@@ -292,10 +293,10 @@ static void sha256_final(void* ctx, u8 *out)
292 /* Pad out to 56 mod 64. */ 293 /* Pad out to 56 mod 64. */
293 index = (sctx->count[0] >> 3) & 0x3f; 294 index = (sctx->count[0] >> 3) & 0x3f;
294 pad_len = (index < 56) ? (56 - index) : ((64+56) - index); 295 pad_len = (index < 56) ? (56 - index) : ((64+56) - index);
295 sha256_update(sctx, padding, pad_len); 296 sha256_update(tfm, padding, pad_len);
296 297
297 /* Append length (before padding) */ 298 /* Append length (before padding) */
298 sha256_update(sctx, (const u8 *)bits, sizeof(bits)); 299 sha256_update(tfm, (const u8 *)bits, sizeof(bits));
299 300
300 /* Store state in digest */ 301 /* Store state in digest */
301 for (i = 0; i < 8; i++) 302 for (i = 0; i < 8; i++)
diff --git a/crypto/sha512.c b/crypto/sha512.c
index bc77a66d9de2..2dfe7f170b48 100644
--- a/crypto/sha512.c
+++ b/crypto/sha512.c
@@ -161,9 +161,9 @@ sha512_transform(u64 *state, u64 *W, const u8 *input)
161} 161}
162 162
163static void 163static void
164sha512_init(void *ctx) 164sha512_init(struct crypto_tfm *tfm)
165{ 165{
166 struct sha512_ctx *sctx = ctx; 166 struct sha512_ctx *sctx = crypto_tfm_ctx(tfm);
167 sctx->state[0] = H0; 167 sctx->state[0] = H0;
168 sctx->state[1] = H1; 168 sctx->state[1] = H1;
169 sctx->state[2] = H2; 169 sctx->state[2] = H2;
@@ -176,9 +176,9 @@ sha512_init(void *ctx)
176} 176}
177 177
178static void 178static void
179sha384_init(void *ctx) 179sha384_init(struct crypto_tfm *tfm)
180{ 180{
181 struct sha512_ctx *sctx = ctx; 181 struct sha512_ctx *sctx = crypto_tfm_ctx(tfm);
182 sctx->state[0] = HP0; 182 sctx->state[0] = HP0;
183 sctx->state[1] = HP1; 183 sctx->state[1] = HP1;
184 sctx->state[2] = HP2; 184 sctx->state[2] = HP2;
@@ -191,9 +191,9 @@ sha384_init(void *ctx)
191} 191}
192 192
193static void 193static void
194sha512_update(void *ctx, const u8 *data, unsigned int len) 194sha512_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len)
195{ 195{
196 struct sha512_ctx *sctx = ctx; 196 struct sha512_ctx *sctx = crypto_tfm_ctx(tfm);
197 197
198 unsigned int i, index, part_len; 198 unsigned int i, index, part_len;
199 199
@@ -231,9 +231,9 @@ sha512_update(void *ctx, const u8 *data, unsigned int len)
231} 231}
232 232
233static void 233static void
234sha512_final(void *ctx, u8 *hash) 234sha512_final(struct crypto_tfm *tfm, u8 *hash)
235{ 235{
236 struct sha512_ctx *sctx = ctx; 236 struct sha512_ctx *sctx = crypto_tfm_ctx(tfm);
237 static u8 padding[128] = { 0x80, }; 237 static u8 padding[128] = { 0x80, };
238 __be64 *dst = (__be64 *)hash; 238 __be64 *dst = (__be64 *)hash;
239 __be32 bits[4]; 239 __be32 bits[4];
@@ -249,10 +249,10 @@ sha512_final(void *ctx, u8 *hash)
249 /* Pad out to 112 mod 128. */ 249 /* Pad out to 112 mod 128. */
250 index = (sctx->count[0] >> 3) & 0x7f; 250 index = (sctx->count[0] >> 3) & 0x7f;
251 pad_len = (index < 112) ? (112 - index) : ((128+112) - index); 251 pad_len = (index < 112) ? (112 - index) : ((128+112) - index);
252 sha512_update(sctx, padding, pad_len); 252 sha512_update(tfm, padding, pad_len);
253 253
254 /* Append length (before padding) */ 254 /* Append length (before padding) */
255 sha512_update(sctx, (const u8 *)bits, sizeof(bits)); 255 sha512_update(tfm, (const u8 *)bits, sizeof(bits));
256 256
257 /* Store state in digest */ 257 /* Store state in digest */
258 for (i = 0; i < 8; i++) 258 for (i = 0; i < 8; i++)
@@ -262,12 +262,11 @@ sha512_final(void *ctx, u8 *hash)
262 memset(sctx, 0, sizeof(struct sha512_ctx)); 262 memset(sctx, 0, sizeof(struct sha512_ctx));
263} 263}
264 264
265static void sha384_final(void *ctx, u8 *hash) 265static void sha384_final(struct crypto_tfm *tfm, u8 *hash)
266{ 266{
267 struct sha512_ctx *sctx = ctx;
268 u8 D[64]; 267 u8 D[64];
269 268
270 sha512_final(sctx, D); 269 sha512_final(tfm, D);
271 270
272 memcpy(hash, D, 48); 271 memcpy(hash, D, 48);
273 memset(D, 0, 64); 272 memset(D, 0, 64);
diff --git a/crypto/tea.c b/crypto/tea.c
index a6a02b30e470..5367adc82fc9 100644
--- a/crypto/tea.c
+++ b/crypto/tea.c
@@ -45,10 +45,10 @@ struct xtea_ctx {
45 u32 KEY[4]; 45 u32 KEY[4];
46}; 46};
47 47
48static int tea_setkey(void *ctx_arg, const u8 *in_key, 48static int tea_setkey(struct crypto_tfm *tfm, const u8 *in_key,
49 unsigned int key_len, u32 *flags) 49 unsigned int key_len, u32 *flags)
50{ 50{
51 struct tea_ctx *ctx = ctx_arg; 51 struct tea_ctx *ctx = crypto_tfm_ctx(tfm);
52 const __le32 *key = (const __le32 *)in_key; 52 const __le32 *key = (const __le32 *)in_key;
53 53
54 if (key_len != 16) 54 if (key_len != 16)
@@ -66,12 +66,11 @@ static int tea_setkey(void *ctx_arg, const u8 *in_key,
66 66
67} 67}
68 68
69static void tea_encrypt(void *ctx_arg, u8 *dst, const u8 *src) 69static void tea_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
70{ 70{
71 u32 y, z, n, sum = 0; 71 u32 y, z, n, sum = 0;
72 u32 k0, k1, k2, k3; 72 u32 k0, k1, k2, k3;
73 73 struct tea_ctx *ctx = crypto_tfm_ctx(tfm);
74 struct tea_ctx *ctx = ctx_arg;
75 const __le32 *in = (const __le32 *)src; 74 const __le32 *in = (const __le32 *)src;
76 __le32 *out = (__le32 *)dst; 75 __le32 *out = (__le32 *)dst;
77 76
@@ -95,11 +94,11 @@ static void tea_encrypt(void *ctx_arg, u8 *dst, const u8 *src)
95 out[1] = cpu_to_le32(z); 94 out[1] = cpu_to_le32(z);
96} 95}
97 96
98static void tea_decrypt(void *ctx_arg, u8 *dst, const u8 *src) 97static void tea_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
99{ 98{
100 u32 y, z, n, sum; 99 u32 y, z, n, sum;
101 u32 k0, k1, k2, k3; 100 u32 k0, k1, k2, k3;
102 struct tea_ctx *ctx = ctx_arg; 101 struct tea_ctx *ctx = crypto_tfm_ctx(tfm);
103 const __le32 *in = (const __le32 *)src; 102 const __le32 *in = (const __le32 *)src;
104 __le32 *out = (__le32 *)dst; 103 __le32 *out = (__le32 *)dst;
105 104
@@ -125,10 +124,10 @@ static void tea_decrypt(void *ctx_arg, u8 *dst, const u8 *src)
125 out[1] = cpu_to_le32(z); 124 out[1] = cpu_to_le32(z);
126} 125}
127 126
128static int xtea_setkey(void *ctx_arg, const u8 *in_key, 127static int xtea_setkey(struct crypto_tfm *tfm, const u8 *in_key,
129 unsigned int key_len, u32 *flags) 128 unsigned int key_len, u32 *flags)
130{ 129{
131 struct xtea_ctx *ctx = ctx_arg; 130 struct xtea_ctx *ctx = crypto_tfm_ctx(tfm);
132 const __le32 *key = (const __le32 *)in_key; 131 const __le32 *key = (const __le32 *)in_key;
133 132
134 if (key_len != 16) 133 if (key_len != 16)
@@ -146,12 +145,11 @@ static int xtea_setkey(void *ctx_arg, const u8 *in_key,
146 145
147} 146}
148 147
149static void xtea_encrypt(void *ctx_arg, u8 *dst, const u8 *src) 148static void xtea_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
150{ 149{
151 u32 y, z, sum = 0; 150 u32 y, z, sum = 0;
152 u32 limit = XTEA_DELTA * XTEA_ROUNDS; 151 u32 limit = XTEA_DELTA * XTEA_ROUNDS;
153 152 struct xtea_ctx *ctx = crypto_tfm_ctx(tfm);
154 struct xtea_ctx *ctx = ctx_arg;
155 const __le32 *in = (const __le32 *)src; 153 const __le32 *in = (const __le32 *)src;
156 __le32 *out = (__le32 *)dst; 154 __le32 *out = (__le32 *)dst;
157 155
@@ -168,10 +166,10 @@ static void xtea_encrypt(void *ctx_arg, u8 *dst, const u8 *src)
168 out[1] = cpu_to_le32(z); 166 out[1] = cpu_to_le32(z);
169} 167}
170 168
171static void xtea_decrypt(void *ctx_arg, u8 *dst, const u8 *src) 169static void xtea_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
172{ 170{
173 u32 y, z, sum; 171 u32 y, z, sum;
174 struct tea_ctx *ctx = ctx_arg; 172 struct tea_ctx *ctx = crypto_tfm_ctx(tfm);
175 const __le32 *in = (const __le32 *)src; 173 const __le32 *in = (const __le32 *)src;
176 __le32 *out = (__le32 *)dst; 174 __le32 *out = (__le32 *)dst;
177 175
@@ -191,12 +189,11 @@ static void xtea_decrypt(void *ctx_arg, u8 *dst, const u8 *src)
191} 189}
192 190
193 191
194static void xeta_encrypt(void *ctx_arg, u8 *dst, const u8 *src) 192static void xeta_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
195{ 193{
196 u32 y, z, sum = 0; 194 u32 y, z, sum = 0;
197 u32 limit = XTEA_DELTA * XTEA_ROUNDS; 195 u32 limit = XTEA_DELTA * XTEA_ROUNDS;
198 196 struct xtea_ctx *ctx = crypto_tfm_ctx(tfm);
199 struct xtea_ctx *ctx = ctx_arg;
200 const __le32 *in = (const __le32 *)src; 197 const __le32 *in = (const __le32 *)src;
201 __le32 *out = (__le32 *)dst; 198 __le32 *out = (__le32 *)dst;
202 199
@@ -213,10 +210,10 @@ static void xeta_encrypt(void *ctx_arg, u8 *dst, const u8 *src)
213 out[1] = cpu_to_le32(z); 210 out[1] = cpu_to_le32(z);
214} 211}
215 212
216static void xeta_decrypt(void *ctx_arg, u8 *dst, const u8 *src) 213static void xeta_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
217{ 214{
218 u32 y, z, sum; 215 u32 y, z, sum;
219 struct tea_ctx *ctx = ctx_arg; 216 struct tea_ctx *ctx = crypto_tfm_ctx(tfm);
220 const __le32 *in = (const __le32 *)src; 217 const __le32 *in = (const __le32 *)src;
221 __le32 *out = (__le32 *)dst; 218 __le32 *out = (__le32 *)dst;
222 219
diff --git a/crypto/tgr192.c b/crypto/tgr192.c
index 004bb841cc5b..a0fadf3dd3e2 100644
--- a/crypto/tgr192.c
+++ b/crypto/tgr192.c
@@ -496,9 +496,9 @@ static void tgr192_transform(struct tgr192_ctx *tctx, const u8 * data)
496 tctx->c = c; 496 tctx->c = c;
497} 497}
498 498
499static void tgr192_init(void *ctx) 499static void tgr192_init(struct crypto_tfm *tfm)
500{ 500{
501 struct tgr192_ctx *tctx = ctx; 501 struct tgr192_ctx *tctx = crypto_tfm_ctx(tfm);
502 502
503 tctx->a = 0x0123456789abcdefULL; 503 tctx->a = 0x0123456789abcdefULL;
504 tctx->b = 0xfedcba9876543210ULL; 504 tctx->b = 0xfedcba9876543210ULL;
@@ -510,9 +510,10 @@ static void tgr192_init(void *ctx)
510 510
511/* Update the message digest with the contents 511/* Update the message digest with the contents
512 * of INBUF with length INLEN. */ 512 * of INBUF with length INLEN. */
513static void tgr192_update(void *ctx, const u8 * inbuf, unsigned int len) 513static void tgr192_update(struct crypto_tfm *tfm, const u8 *inbuf,
514 unsigned int len)
514{ 515{
515 struct tgr192_ctx *tctx = ctx; 516 struct tgr192_ctx *tctx = crypto_tfm_ctx(tfm);
516 517
517 if (tctx->count == 64) { /* flush the buffer */ 518 if (tctx->count == 64) { /* flush the buffer */
518 tgr192_transform(tctx, tctx->hash); 519 tgr192_transform(tctx, tctx->hash);
@@ -526,7 +527,7 @@ static void tgr192_update(void *ctx, const u8 * inbuf, unsigned int len)
526 for (; len && tctx->count < 64; len--) { 527 for (; len && tctx->count < 64; len--) {
527 tctx->hash[tctx->count++] = *inbuf++; 528 tctx->hash[tctx->count++] = *inbuf++;
528 } 529 }
529 tgr192_update(tctx, NULL, 0); 530 tgr192_update(tfm, NULL, 0);
530 if (!len) { 531 if (!len) {
531 return; 532 return;
532 } 533 }
@@ -548,15 +549,15 @@ static void tgr192_update(void *ctx, const u8 * inbuf, unsigned int len)
548 549
549 550
550/* The routine terminates the computation */ 551/* The routine terminates the computation */
551static void tgr192_final(void *ctx, u8 * out) 552static void tgr192_final(struct crypto_tfm *tfm, u8 * out)
552{ 553{
553 struct tgr192_ctx *tctx = ctx; 554 struct tgr192_ctx *tctx = crypto_tfm_ctx(tfm);
554 __be64 *dst = (__be64 *)out; 555 __be64 *dst = (__be64 *)out;
555 __be64 *be64p; 556 __be64 *be64p;
556 __le32 *le32p; 557 __le32 *le32p;
557 u32 t, msb, lsb; 558 u32 t, msb, lsb;
558 559
559 tgr192_update(tctx, NULL, 0); /* flush */ ; 560 tgr192_update(tfm, NULL, 0); /* flush */ ;
560 561
561 msb = 0; 562 msb = 0;
562 t = tctx->nblocks; 563 t = tctx->nblocks;
@@ -584,7 +585,7 @@ static void tgr192_final(void *ctx, u8 * out)
584 while (tctx->count < 64) { 585 while (tctx->count < 64) {
585 tctx->hash[tctx->count++] = 0; 586 tctx->hash[tctx->count++] = 0;
586 } 587 }
587 tgr192_update(tctx, NULL, 0); /* flush */ ; 588 tgr192_update(tfm, NULL, 0); /* flush */ ;
588 memset(tctx->hash, 0, 56); /* fill next block with zeroes */ 589 memset(tctx->hash, 0, 56); /* fill next block with zeroes */
589 } 590 }
590 /* append the 64 bit count */ 591 /* append the 64 bit count */
@@ -600,22 +601,20 @@ static void tgr192_final(void *ctx, u8 * out)
600 dst[2] = be64p[2] = cpu_to_be64(tctx->c); 601 dst[2] = be64p[2] = cpu_to_be64(tctx->c);
601} 602}
602 603
603static void tgr160_final(void *ctx, u8 * out) 604static void tgr160_final(struct crypto_tfm *tfm, u8 * out)
604{ 605{
605 struct tgr192_ctx *wctx = ctx;
606 u8 D[64]; 606 u8 D[64];
607 607
608 tgr192_final(wctx, D); 608 tgr192_final(tfm, D);
609 memcpy(out, D, TGR160_DIGEST_SIZE); 609 memcpy(out, D, TGR160_DIGEST_SIZE);
610 memset(D, 0, TGR192_DIGEST_SIZE); 610 memset(D, 0, TGR192_DIGEST_SIZE);
611} 611}
612 612
613static void tgr128_final(void *ctx, u8 * out) 613static void tgr128_final(struct crypto_tfm *tfm, u8 * out)
614{ 614{
615 struct tgr192_ctx *wctx = ctx;
616 u8 D[64]; 615 u8 D[64];
617 616
618 tgr192_final(wctx, D); 617 tgr192_final(tfm, D);
619 memcpy(out, D, TGR128_DIGEST_SIZE); 618 memcpy(out, D, TGR128_DIGEST_SIZE);
620 memset(D, 0, TGR192_DIGEST_SIZE); 619 memset(D, 0, TGR192_DIGEST_SIZE);
621} 620}
diff --git a/crypto/twofish.c b/crypto/twofish.c
index ddfd5a3fcc5f..ec2488242e2d 100644
--- a/crypto/twofish.c
+++ b/crypto/twofish.c
@@ -643,11 +643,11 @@ struct twofish_ctx {
643}; 643};
644 644
645/* Perform the key setup. */ 645/* Perform the key setup. */
646static int twofish_setkey(void *cx, const u8 *key, 646static int twofish_setkey(struct crypto_tfm *tfm, const u8 *key,
647 unsigned int key_len, u32 *flags) 647 unsigned int key_len, u32 *flags)
648{ 648{
649 649
650 struct twofish_ctx *ctx = cx; 650 struct twofish_ctx *ctx = crypto_tfm_ctx(tfm);
651 651
652 int i, j, k; 652 int i, j, k;
653 653
@@ -802,9 +802,9 @@ static int twofish_setkey(void *cx, const u8 *key,
802} 802}
803 803
804/* Encrypt one block. in and out may be the same. */ 804/* Encrypt one block. in and out may be the same. */
805static void twofish_encrypt(void *cx, u8 *out, const u8 *in) 805static void twofish_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
806{ 806{
807 struct twofish_ctx *ctx = cx; 807 struct twofish_ctx *ctx = crypto_tfm_ctx(tfm);
808 const __le32 *src = (const __le32 *)in; 808 const __le32 *src = (const __le32 *)in;
809 __le32 *dst = (__le32 *)out; 809 __le32 *dst = (__le32 *)out;
810 810
@@ -839,9 +839,9 @@ static void twofish_encrypt(void *cx, u8 *out, const u8 *in)
839} 839}
840 840
841/* Decrypt one block. in and out may be the same. */ 841/* Decrypt one block. in and out may be the same. */
842static void twofish_decrypt(void *cx, u8 *out, const u8 *in) 842static void twofish_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
843{ 843{
844 struct twofish_ctx *ctx = cx; 844 struct twofish_ctx *ctx = crypto_tfm_ctx(tfm);
845 const __le32 *src = (const __le32 *)in; 845 const __le32 *src = (const __le32 *)in;
846 __le32 *dst = (__le32 *)out; 846 __le32 *dst = (__le32 *)out;
847 847
diff --git a/crypto/wp512.c b/crypto/wp512.c
index b226a126cfae..727d05a19ff4 100644
--- a/crypto/wp512.c
+++ b/crypto/wp512.c
@@ -981,9 +981,9 @@ static void wp512_process_buffer(struct wp512_ctx *wctx) {
981 981
982} 982}
983 983
984static void wp512_init (void *ctx) { 984static void wp512_init(struct crypto_tfm *tfm) {
985 struct wp512_ctx *wctx = crypto_tfm_ctx(tfm);
985 int i; 986 int i;
986 struct wp512_ctx *wctx = ctx;
987 987
988 memset(wctx->bitLength, 0, 32); 988 memset(wctx->bitLength, 0, 32);
989 wctx->bufferBits = wctx->bufferPos = 0; 989 wctx->bufferBits = wctx->bufferPos = 0;
@@ -993,10 +993,10 @@ static void wp512_init (void *ctx) {
993 } 993 }
994} 994}
995 995
996static void wp512_update(void *ctx, const u8 *source, unsigned int len) 996static void wp512_update(struct crypto_tfm *tfm, const u8 *source,
997 unsigned int len)
997{ 998{
998 999 struct wp512_ctx *wctx = crypto_tfm_ctx(tfm);
999 struct wp512_ctx *wctx = ctx;
1000 int sourcePos = 0; 1000 int sourcePos = 0;
1001 unsigned int bits_len = len * 8; // convert to number of bits 1001 unsigned int bits_len = len * 8; // convert to number of bits
1002 int sourceGap = (8 - ((int)bits_len & 7)) & 7; 1002 int sourceGap = (8 - ((int)bits_len & 7)) & 7;
@@ -1054,9 +1054,9 @@ static void wp512_update(void *ctx, const u8 *source, unsigned int len)
1054 1054
1055} 1055}
1056 1056
1057static void wp512_final(void *ctx, u8 *out) 1057static void wp512_final(struct crypto_tfm *tfm, u8 *out)
1058{ 1058{
1059 struct wp512_ctx *wctx = ctx; 1059 struct wp512_ctx *wctx = crypto_tfm_ctx(tfm);
1060 int i; 1060 int i;
1061 u8 *buffer = wctx->buffer; 1061 u8 *buffer = wctx->buffer;
1062 u8 *bitLength = wctx->bitLength; 1062 u8 *bitLength = wctx->bitLength;
@@ -1087,22 +1087,20 @@ static void wp512_final(void *ctx, u8 *out)
1087 wctx->bufferPos = bufferPos; 1087 wctx->bufferPos = bufferPos;
1088} 1088}
1089 1089
1090static void wp384_final(void *ctx, u8 *out) 1090static void wp384_final(struct crypto_tfm *tfm, u8 *out)
1091{ 1091{
1092 struct wp512_ctx *wctx = ctx;
1093 u8 D[64]; 1092 u8 D[64];
1094 1093
1095 wp512_final (wctx, D); 1094 wp512_final(tfm, D);
1096 memcpy (out, D, WP384_DIGEST_SIZE); 1095 memcpy (out, D, WP384_DIGEST_SIZE);
1097 memset (D, 0, WP512_DIGEST_SIZE); 1096 memset (D, 0, WP512_DIGEST_SIZE);
1098} 1097}
1099 1098
1100static void wp256_final(void *ctx, u8 *out) 1099static void wp256_final(struct crypto_tfm *tfm, u8 *out)
1101{ 1100{
1102 struct wp512_ctx *wctx = ctx;
1103 u8 D[64]; 1101 u8 D[64];
1104 1102
1105 wp512_final (wctx, D); 1103 wp512_final(tfm, D);
1106 memcpy (out, D, WP256_DIGEST_SIZE); 1104 memcpy (out, D, WP256_DIGEST_SIZE);
1107 memset (D, 0, WP512_DIGEST_SIZE); 1105 memset (D, 0, WP512_DIGEST_SIZE);
1108} 1106}