1 Merge master.kernel.org:/pub/scm/linux/kernel/git/herbert/crypto-2.6
3 * master.kernel.org:/pub/scm/linux/kernel/git/herbert/crypto-2.6:
4 [CRYPTO] aes: Fixed array boundary violation
5 [CRYPTO] tcrypt: Fix key alignment
6 [CRYPTO] all: Add missing cra_alignmask
7 [CRYPTO] all: Use kzalloc where possible
8 [CRYPTO] api: Align tfm context as wide as possible
9 [CRYPTO] twofish: Use rol32/ror32 where appropriate
11 Index: linux-2.6.16.50/arch/x86_64/crypto/aes.c
12 ===================================================================
13 --- linux-2.6.16.50.orig/arch/x86_64/crypto/aes.c 2006-07-14 18:09:26.335435750 +1200
14 +++ linux-2.6.16.50/arch/x86_64/crypto/aes.c 2006-07-14 18:10:31.083482250 +1200
26 +#define E_KEY (&ctx->buf[0])
27 +#define D_KEY (&ctx->buf[60])
29 static u8 pow_tab[256] __initdata;
30 static u8 log_tab[256] __initdata;
32 t ^= E_KEY[8 * i + 7]; E_KEY[8 * i + 15] = t; \
35 -static int aes_set_key(void *ctx_arg, const u8 *in_key, unsigned int key_len,
37 +static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
38 + unsigned int key_len, u32 *flags)
40 - struct aes_ctx *ctx = ctx_arg;
41 + struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
42 const __le32 *key = (const __le32 *)in_key;
49 -extern void aes_encrypt(void *ctx_arg, u8 *out, const u8 *in);
50 -extern void aes_decrypt(void *ctx_arg, u8 *out, const u8 *in);
51 +asmlinkage void aes_enc_blk(struct crypto_tfm *tfm, u8 *out, const u8 *in);
52 +asmlinkage void aes_dec_blk(struct crypto_tfm *tfm, u8 *out, const u8 *in);
54 +static void aes_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
56 + aes_enc_blk(tfm, dst, src);
59 +static void aes_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
61 + aes_dec_blk(tfm, dst, src);
64 static struct crypto_alg aes_alg = {
66 Index: linux-2.6.16.50/crypto/aes.c
67 ===================================================================
68 --- linux-2.6.16.50.orig/crypto/aes.c 2006-07-14 18:09:26.351436750 +1200
69 +++ linux-2.6.16.50/crypto/aes.c 2006-07-14 18:10:31.087482500 +1200
81 +#define E_KEY (&ctx->buf[0])
82 +#define D_KEY (&ctx->buf[60])
84 static u8 pow_tab[256] __initdata;
85 static u8 log_tab[256] __initdata;
87 t ^= E_KEY[8 * i + 7]; E_KEY[8 * i + 15] = t; \
91 -aes_set_key(void *ctx_arg, const u8 *in_key, unsigned int key_len, u32 *flags)
92 +static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
93 + unsigned int key_len, u32 *flags)
95 - struct aes_ctx *ctx = ctx_arg;
96 + struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
97 const __le32 *key = (const __le32 *)in_key;
101 f_rl(bo, bi, 2, k); \
104 -static void aes_encrypt(void *ctx_arg, u8 *out, const u8 *in)
105 +static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
107 - const struct aes_ctx *ctx = ctx_arg;
108 + const struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
109 const __le32 *src = (const __le32 *)in;
110 __le32 *dst = (__le32 *)out;
113 i_rl(bo, bi, 2, k); \
116 -static void aes_decrypt(void *ctx_arg, u8 *out, const u8 *in)
117 +static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
119 - const struct aes_ctx *ctx = ctx_arg;
120 + const struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
121 const __le32 *src = (const __le32 *)in;
122 __le32 *dst = (__le32 *)out;
124 Index: linux-2.6.16.50/crypto/api.c
125 ===================================================================
126 --- linux-2.6.16.50.orig/crypto/api.c 2006-07-14 18:09:26.351436750 +1200
127 +++ linux-2.6.16.50/crypto/api.c 2006-07-14 18:10:31.091482750 +1200
132 - return len + alg->cra_alignmask;
133 + return len + (alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1));
136 struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags)
137 @@ -179,24 +179,25 @@
140 tfm_size = sizeof(*tfm) + crypto_ctxsize(alg, flags);
141 - tfm = kmalloc(tfm_size, GFP_KERNEL);
142 + tfm = kzalloc(tfm_size, GFP_KERNEL);
146 - memset(tfm, 0, tfm_size);
148 tfm->__crt_alg = alg;
150 if (crypto_init_flags(tfm, flags))
153 - if (crypto_init_ops(tfm)) {
154 - crypto_exit_ops(tfm);
155 + if (crypto_init_ops(tfm))
159 + if (alg->cra_init && alg->cra_init(tfm))
160 + goto cra_init_failed;
165 + crypto_exit_ops(tfm);
170 alg = tfm->__crt_alg;
171 size = sizeof(*tfm) + alg->cra_ctxsize;
174 + alg->cra_exit(tfm);
175 crypto_exit_ops(tfm);
177 memset(tfm, 0, size);
179 static inline int crypto_set_driver_name(struct crypto_alg *alg)
181 static const char suffix[] = "-generic";
182 - char *driver_name = (char *)alg->cra_driver_name;
183 + char *driver_name = alg->cra_driver_name;
187 @@ -264,13 +267,13 @@
188 down_write(&crypto_alg_sem);
190 list_for_each_entry(q, &crypto_alg_list, cra_list) {
191 - if (!strcmp(q->cra_driver_name, alg->cra_driver_name)) {
198 - list_add_tail(&alg->cra_list, &crypto_alg_list);
199 + list_add(&alg->cra_list, &crypto_alg_list);
201 up_write(&crypto_alg_sem);
203 Index: linux-2.6.16.50/crypto/deflate.c
204 ===================================================================
205 --- linux-2.6.16.50.orig/crypto/deflate.c 2006-07-14 18:09:26.351436750 +1200
206 +++ linux-2.6.16.50/crypto/deflate.c 2006-07-14 18:10:31.091482750 +1200
209 struct z_stream_s *stream = &ctx->decomp_stream;
211 - stream->workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
212 + stream->workspace = kzalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
213 if (!stream->workspace ) {
217 - memset(stream->workspace, 0, zlib_inflate_workspacesize());
218 ret = zlib_inflateInit2(stream, -DEFLATE_DEF_WINBITS);
222 kfree(ctx->decomp_stream.workspace);
225 -static int deflate_init(void *ctx)
226 +static int deflate_init(struct crypto_tfm *tfm)
228 + struct deflate_ctx *ctx = crypto_tfm_ctx(tfm);
231 ret = deflate_comp_init(ctx);
232 @@ -117,17 +117,19 @@
236 -static void deflate_exit(void *ctx)
237 +static void deflate_exit(struct crypto_tfm *tfm)
239 + struct deflate_ctx *ctx = crypto_tfm_ctx(tfm);
241 deflate_comp_exit(ctx);
242 deflate_decomp_exit(ctx);
245 -static int deflate_compress(void *ctx, const u8 *src, unsigned int slen,
246 - u8 *dst, unsigned int *dlen)
247 +static int deflate_compress(struct crypto_tfm *tfm, const u8 *src,
248 + unsigned int slen, u8 *dst, unsigned int *dlen)
251 - struct deflate_ctx *dctx = ctx;
252 + struct deflate_ctx *dctx = crypto_tfm_ctx(tfm);
253 struct z_stream_s *stream = &dctx->comp_stream;
255 ret = zlib_deflateReset(stream);
256 @@ -152,12 +154,12 @@
260 -static int deflate_decompress(void *ctx, const u8 *src, unsigned int slen,
261 - u8 *dst, unsigned int *dlen)
262 +static int deflate_decompress(struct crypto_tfm *tfm, const u8 *src,
263 + unsigned int slen, u8 *dst, unsigned int *dlen)
267 - struct deflate_ctx *dctx = ctx;
268 + struct deflate_ctx *dctx = crypto_tfm_ctx(tfm);
269 struct z_stream_s *stream = &dctx->decomp_stream;
271 ret = zlib_inflateReset(stream);
273 .cra_ctxsize = sizeof(struct deflate_ctx),
274 .cra_module = THIS_MODULE,
275 .cra_list = LIST_HEAD_INIT(alg.cra_list),
276 + .cra_init = deflate_init,
277 + .cra_exit = deflate_exit,
278 .cra_u = { .compress = {
279 - .coa_init = deflate_init,
280 - .coa_exit = deflate_exit,
281 .coa_compress = deflate_compress,
282 .coa_decompress = deflate_decompress } }
284 Index: linux-2.6.16.50/crypto/des.c
285 ===================================================================
286 --- linux-2.6.16.50.orig/crypto/des.c 2006-07-14 18:09:26.355437000 +1200
287 +++ linux-2.6.16.50/crypto/des.c 2006-07-14 18:10:31.099483250 +1200
292 -static int des_setkey(void *ctx, const u8 *key, unsigned int keylen, u32 *flags)
293 +static int des_setkey(struct crypto_tfm *tfm, const u8 *key,
294 + unsigned int keylen, u32 *flags)
296 - struct des_ctx *dctx = ctx;
297 + struct des_ctx *dctx = crypto_tfm_ctx(tfm);
298 u32 tmp[DES_EXPKEY_WORDS];
305 -static void des_encrypt(void *ctx, u8 *dst, const u8 *src)
306 +static void des_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
308 - const u32 *K = ((struct des_ctx *)ctx)->expkey;
309 + struct des_ctx *ctx = crypto_tfm_ctx(tfm);
310 + const u32 *K = ctx->expkey;
311 const __le32 *s = (const __le32 *)src;
312 __le32 *d = (__le32 *)dst;
315 d[1] = cpu_to_le32(L);
318 -static void des_decrypt(void *ctx, u8 *dst, const u8 *src)
319 +static void des_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
321 - const u32 *K = ((struct des_ctx *)ctx)->expkey + DES_EXPKEY_WORDS - 2;
322 + struct des_ctx *ctx = crypto_tfm_ctx(tfm);
323 + const u32 *K = ctx->expkey + DES_EXPKEY_WORDS - 2;
324 const __le32 *s = (const __le32 *)src;
325 __le32 *d = (__le32 *)dst;
327 @@ -860,11 +863,11 @@
331 -static int des3_ede_setkey(void *ctx, const u8 *key,
332 +static int des3_ede_setkey(struct crypto_tfm *tfm, const u8 *key,
333 unsigned int keylen, u32 *flags)
335 const u32 *K = (const u32 *)key;
336 - struct des3_ede_ctx *dctx = ctx;
337 + struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm);
338 u32 *expkey = dctx->expkey;
340 if (unlikely(!((K[0] ^ K[2]) | (K[1] ^ K[3])) ||
345 -static void des3_ede_encrypt(void *ctx, u8 *dst, const u8 *src)
346 +static void des3_ede_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
348 - struct des3_ede_ctx *dctx = ctx;
349 + struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm);
350 const u32 *K = dctx->expkey;
351 const __le32 *s = (const __le32 *)src;
352 __le32 *d = (__le32 *)dst;
354 d[1] = cpu_to_le32(L);
357 -static void des3_ede_decrypt(void *ctx, u8 *dst, const u8 *src)
358 +static void des3_ede_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
360 - struct des3_ede_ctx *dctx = ctx;
361 + struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm);
362 const u32 *K = dctx->expkey + DES3_EDE_EXPKEY_WORDS - 2;
363 const __le32 *s = (const __le32 *)src;
364 __le32 *d = (__le32 *)dst;
366 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
367 .cra_ctxsize = sizeof(struct des3_ede_ctx),
368 .cra_module = THIS_MODULE,
369 + .cra_alignmask = 3,
370 .cra_list = LIST_HEAD_INIT(des3_ede_alg.cra_list),
371 .cra_u = { .cipher = {
372 .cia_min_keysize = DES3_EDE_KEY_SIZE,
373 Index: linux-2.6.16.50/crypto/serpent.c
374 ===================================================================
375 --- linux-2.6.16.50.orig/crypto/serpent.c 2006-07-14 18:09:26.355437000 +1200
376 +++ linux-2.6.16.50/crypto/serpent.c 2006-07-14 18:10:31.103483500 +1200
381 -static int serpent_setkey(void *ctx, const u8 *key, unsigned int keylen, u32 *flags)
382 +static int serpent_setkey(struct crypto_tfm *tfm, const u8 *key,
383 + unsigned int keylen, u32 *flags)
385 - u32 *k = ((struct serpent_ctx *)ctx)->expkey;
386 + struct serpent_ctx *ctx = crypto_tfm_ctx(tfm);
387 + u32 *k = ctx->expkey;
391 @@ -365,10 +367,11 @@
395 -static void serpent_encrypt(void *ctx, u8 *dst, const u8 *src)
396 +static void serpent_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
398 + struct serpent_ctx *ctx = crypto_tfm_ctx(tfm);
400 - *k = ((struct serpent_ctx *)ctx)->expkey,
402 *s = (const u32 *)src;
406 d[3] = cpu_to_le32(r3);
409 -static void serpent_decrypt(void *ctx, u8 *dst, const u8 *src)
410 +static void serpent_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
412 + struct serpent_ctx *ctx = crypto_tfm_ctx(tfm);
414 *k = ((struct serpent_ctx *)ctx)->expkey,
415 *s = (const u32 *)src;
417 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
418 .cra_blocksize = SERPENT_BLOCK_SIZE,
419 .cra_ctxsize = sizeof(struct serpent_ctx),
420 + .cra_alignmask = 3,
421 .cra_module = THIS_MODULE,
422 .cra_list = LIST_HEAD_INIT(serpent_alg.cra_list),
423 .cra_u = { .cipher = {
425 .cia_decrypt = serpent_decrypt } }
428 -static int tnepres_setkey(void *ctx, const u8 *key, unsigned int keylen, u32 *flags)
429 +static int tnepres_setkey(struct crypto_tfm *tfm, const u8 *key,
430 + unsigned int keylen, u32 *flags)
432 u8 rev_key[SERPENT_MAX_KEY_SIZE];
434 @@ -505,10 +511,10 @@
435 for (i = 0; i < keylen; ++i)
436 rev_key[keylen - i - 1] = key[i];
438 - return serpent_setkey(ctx, rev_key, keylen, flags);
439 + return serpent_setkey(tfm, rev_key, keylen, flags);
442 -static void tnepres_encrypt(void *ctx, u8 *dst, const u8 *src)
443 +static void tnepres_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
445 const u32 * const s = (const u32 * const)src;
446 u32 * const d = (u32 * const)dst;
448 rs[2] = swab32(s[1]);
449 rs[3] = swab32(s[0]);
451 - serpent_encrypt(ctx, (u8 *)rd, (u8 *)rs);
452 + serpent_encrypt(tfm, (u8 *)rd, (u8 *)rs);
454 d[0] = swab32(rd[3]);
455 d[1] = swab32(rd[2]);
457 d[3] = swab32(rd[0]);
460 -static void tnepres_decrypt(void *ctx, u8 *dst, const u8 *src)
461 +static void tnepres_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
463 const u32 * const s = (const u32 * const)src;
464 u32 * const d = (u32 * const)dst;
466 rs[2] = swab32(s[1]);
467 rs[3] = swab32(s[0]);
469 - serpent_decrypt(ctx, (u8 *)rd, (u8 *)rs);
470 + serpent_decrypt(tfm, (u8 *)rd, (u8 *)rs);
472 d[0] = swab32(rd[3]);
473 d[1] = swab32(rd[2]);
474 Index: linux-2.6.16.50/crypto/tcrypt.h
475 ===================================================================
476 --- linux-2.6.16.50.orig/crypto/tcrypt.h 2006-07-14 18:09:26.355437000 +1200
477 +++ linux-2.6.16.50/crypto/tcrypt.h 2006-07-14 18:10:31.111484000 +1200
481 struct hash_testvec {
482 + /* only used with keyed hash algorithms */
483 + char key[128] __attribute__ ((__aligned__(4)));
485 - unsigned char psize;
486 char digest[MAX_DIGEST_SIZE];
488 unsigned char tap[MAX_TAP];
489 - char key[128]; /* only used with keyed hash algorithms */
490 + unsigned char psize;
495 struct hmac_testvec {
497 - unsigned char ksize;
499 - unsigned char psize;
500 char digest[MAX_DIGEST_SIZE];
502 unsigned char tap[MAX_TAP];
503 + unsigned char ksize;
504 + unsigned char psize;
508 struct cipher_testvec {
509 + char key[MAX_KEYLEN] __attribute__ ((__aligned__(4)));
510 + char iv[MAX_IVLEN];
513 + unsigned char tap[MAX_TAP];
516 unsigned char wk; /* weak key flag */
517 - char key[MAX_KEYLEN];
519 - char iv[MAX_IVLEN];
525 - unsigned char tap[MAX_TAP];
528 struct cipher_speed {
533 +struct digest_speed {
534 + unsigned int blen; /* buffer length */
535 + unsigned int plen; /* per-update length */
539 * MD4 test vectors from RFC1320
541 @@ -2974,4 +2980,35 @@
542 { .klen = 0, .blen = 0, }
546 + * Digest speed tests
548 +static struct digest_speed generic_digest_speed_template[] = {
549 + { .blen = 16, .plen = 16, },
550 + { .blen = 64, .plen = 16, },
551 + { .blen = 64, .plen = 64, },
552 + { .blen = 256, .plen = 16, },
553 + { .blen = 256, .plen = 64, },
554 + { .blen = 256, .plen = 256, },
555 + { .blen = 1024, .plen = 16, },
556 + { .blen = 1024, .plen = 256, },
557 + { .blen = 1024, .plen = 1024, },
558 + { .blen = 2048, .plen = 16, },
559 + { .blen = 2048, .plen = 256, },
560 + { .blen = 2048, .plen = 1024, },
561 + { .blen = 2048, .plen = 2048, },
562 + { .blen = 4096, .plen = 16, },
563 + { .blen = 4096, .plen = 256, },
564 + { .blen = 4096, .plen = 1024, },
565 + { .blen = 4096, .plen = 4096, },
566 + { .blen = 8192, .plen = 16, },
567 + { .blen = 8192, .plen = 256, },
568 + { .blen = 8192, .plen = 1024, },
569 + { .blen = 8192, .plen = 4096, },
570 + { .blen = 8192, .plen = 8192, },
573 + { .blen = 0, .plen = 0, }
576 #endif /* _CRYPTO_TCRYPT_H */
577 Index: linux-2.6.16.50/crypto/twofish.c
578 ===================================================================
579 --- linux-2.6.16.50.orig/crypto/twofish.c 2006-07-14 18:09:26.359437250 +1200
580 +++ linux-2.6.16.50/crypto/twofish.c 2006-07-14 18:10:31.119484500 +1200
582 #include <linux/types.h>
583 #include <linux/errno.h>
584 #include <linux/crypto.h>
585 +#include <linux/bitops.h>
588 /* The large precomputed tables for the Twofish cipher (twofish.c)
590 #define CALC_K(a, j, k, l, m, n) \
591 x = CALC_K_2 (k, l, k, l, 0); \
592 y = CALC_K_2 (m, n, m, n, 4); \
593 - y = (y << 8) + (y >> 24); \
595 x += y; y += x; ctx->a[j] = x; \
596 - ctx->a[(j) + 1] = (y << 9) + (y >> 23)
597 + ctx->a[(j) + 1] = rol32(y, 9)
599 #define CALC_K192_2(a, b, c, d, j) \
600 CALC_K_2 (q0[a ^ key[(j) + 16]], \
602 #define CALC_K192(a, j, k, l, m, n) \
603 x = CALC_K192_2 (l, l, k, k, 0); \
604 y = CALC_K192_2 (n, n, m, m, 4); \
605 - y = (y << 8) + (y >> 24); \
607 x += y; y += x; ctx->a[j] = x; \
608 - ctx->a[(j) + 1] = (y << 9) + (y >> 23)
609 + ctx->a[(j) + 1] = rol32(y, 9)
611 #define CALC_K256_2(a, b, j) \
612 CALC_K192_2 (q1[b ^ key[(j) + 24]], \
614 #define CALC_K256(a, j, k, l, m, n) \
615 x = CALC_K256_2 (k, l, 0); \
616 y = CALC_K256_2 (m, n, 4); \
617 - y = (y << 8) + (y >> 24); \
619 x += y; y += x; ctx->a[j] = x; \
620 - ctx->a[(j) + 1] = (y << 9) + (y >> 23)
621 + ctx->a[(j) + 1] = rol32(y, 9)
624 /* Macros to compute the g() function in the encryption and decryption
625 @@ -594,15 +595,15 @@
626 x = G1 (a); y = G2 (b); \
627 x += y; y += x + ctx->k[2 * (n) + 1]; \
628 (c) ^= x + ctx->k[2 * (n)]; \
629 - (c) = ((c) >> 1) + ((c) << 31); \
630 - (d) = (((d) << 1)+((d) >> 31)) ^ y
631 + (c) = ror32((c), 1); \
632 + (d) = rol32((d), 1) ^ y
634 #define DECROUND(n, a, b, c, d) \
635 x = G1 (a); y = G2 (b); \
637 (d) ^= y + ctx->k[2 * (n) + 1]; \
638 - (d) = ((d) >> 1) + ((d) << 31); \
639 - (c) = (((c) << 1)+((c) >> 31)); \
640 + (d) = ror32((d), 1); \
641 + (c) = rol32((c), 1); \
642 (c) ^= (x + ctx->k[2 * (n)])
644 /* Encryption and decryption cycles; each one is simply two Feistel rounds
645 @@ -642,11 +643,11 @@
648 /* Perform the key setup. */
649 -static int twofish_setkey(void *cx, const u8 *key,
650 - unsigned int key_len, u32 *flags)
651 +static int twofish_setkey(struct crypto_tfm *tfm, const u8 *key,
652 + unsigned int key_len, u32 *flags)
655 - struct twofish_ctx *ctx = cx;
656 + struct twofish_ctx *ctx = crypto_tfm_ctx(tfm);
663 /* Encrypt one block. in and out may be the same. */
664 -static void twofish_encrypt(void *cx, u8 *out, const u8 *in)
665 +static void twofish_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
667 - struct twofish_ctx *ctx = cx;
668 + struct twofish_ctx *ctx = crypto_tfm_ctx(tfm);
669 const __le32 *src = (const __le32 *)in;
670 __le32 *dst = (__le32 *)out;
675 /* Decrypt one block. in and out may be the same. */
676 -static void twofish_decrypt(void *cx, u8 *out, const u8 *in)
677 +static void twofish_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
679 - struct twofish_ctx *ctx = cx;
680 + struct twofish_ctx *ctx = crypto_tfm_ctx(tfm);
681 const __le32 *src = (const __le32 *)in;
682 __le32 *dst = (__le32 *)out;
684 Index: linux-2.6.16.50/drivers/crypto/padlock-aes.c
685 ===================================================================
686 --- linux-2.6.16.50.orig/drivers/crypto/padlock-aes.c 2006-07-14 18:09:26.387439000 +1200
687 +++ linux-2.6.16.50/drivers/crypto/padlock-aes.c 2006-07-18 01:35:50.305291201 +1200
689 #define AES_EXTENDED_KEY_SIZE 64 /* in uint32_t units */
690 #define AES_EXTENDED_KEY_SIZE_B (AES_EXTENDED_KEY_SIZE * sizeof(uint32_t))
692 +/* Whenever making any changes to the following
693 + * structure *make sure* you keep E, d_data
694 + * and cword aligned on 16 Bytes boundaries!!! */
696 - uint32_t e_data[AES_EXTENDED_KEY_SIZE];
697 - uint32_t d_data[AES_EXTENDED_KEY_SIZE];
699 struct cword encrypt;
700 struct cword decrypt;
706 + u32 E[AES_EXTENDED_KEY_SIZE]
707 + __attribute__ ((__aligned__(PADLOCK_ALIGNMENT)));
708 + u32 d_data[AES_EXTENDED_KEY_SIZE]
709 + __attribute__ ((__aligned__(PADLOCK_ALIGNMENT)));
712 /* ====== Key management routines ====== */
713 @@ -282,15 +286,20 @@
717 -static inline struct aes_ctx *aes_ctx(void *ctx)
718 +static inline struct aes_ctx *aes_ctx(struct crypto_tfm *tfm)
720 - return (struct aes_ctx *)ALIGN((unsigned long)ctx, PADLOCK_ALIGNMENT);
721 + unsigned long addr = (unsigned long)crypto_tfm_ctx(tfm);
722 + unsigned long align = PADLOCK_ALIGNMENT;
724 + if (align <= crypto_tfm_ctx_alignment())
726 + return (struct aes_ctx *)ALIGN(addr, align);
730 -aes_set_key(void *ctx_arg, const uint8_t *in_key, unsigned int key_len, uint32_t *flags)
731 +static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
732 + unsigned int key_len, u32 *flags)
734 - struct aes_ctx *ctx = aes_ctx(ctx_arg);
735 + struct aes_ctx *ctx = aes_ctx(tfm);
736 const __le32 *key = (const __le32 *)in_key;
737 uint32_t i, t, u, v, w;
738 uint32_t P[AES_EXTENDED_KEY_SIZE];
740 * itself we must supply the plain key for both encryption
743 - ctx->E = ctx->e_data;
744 - ctx->D = ctx->e_data;
747 E_KEY[0] = le32_to_cpu(key[0]);
748 E_KEY[1] = le32_to_cpu(key[1]);
749 @@ -410,24 +418,22 @@
754 -aes_encrypt(void *ctx_arg, uint8_t *out, const uint8_t *in)
755 +static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
757 - struct aes_ctx *ctx = aes_ctx(ctx_arg);
758 + struct aes_ctx *ctx = aes_ctx(tfm);
759 padlock_xcrypt_ecb(in, out, ctx->E, &ctx->cword.encrypt, 1);
763 -aes_decrypt(void *ctx_arg, uint8_t *out, const uint8_t *in)
764 +static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
766 - struct aes_ctx *ctx = aes_ctx(ctx_arg);
767 + struct aes_ctx *ctx = aes_ctx(tfm);
768 padlock_xcrypt_ecb(in, out, ctx->D, &ctx->cword.decrypt, 1);
771 static unsigned int aes_encrypt_ecb(const struct cipher_desc *desc, u8 *out,
772 const u8 *in, unsigned int nbytes)
774 - struct aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(desc->tfm));
775 + struct aes_ctx *ctx = aes_ctx(desc->tfm);
776 padlock_xcrypt_ecb(in, out, ctx->E, &ctx->cword.encrypt,
777 nbytes / AES_BLOCK_SIZE);
778 return nbytes & ~(AES_BLOCK_SIZE - 1);
780 static unsigned int aes_decrypt_ecb(const struct cipher_desc *desc, u8 *out,
781 const u8 *in, unsigned int nbytes)
783 - struct aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(desc->tfm));
784 + struct aes_ctx *ctx = aes_ctx(desc->tfm);
785 padlock_xcrypt_ecb(in, out, ctx->D, &ctx->cword.decrypt,
786 nbytes / AES_BLOCK_SIZE);
787 return nbytes & ~(AES_BLOCK_SIZE - 1);
789 static unsigned int aes_encrypt_cbc(const struct cipher_desc *desc, u8 *out,
790 const u8 *in, unsigned int nbytes)
792 - struct aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(desc->tfm));
793 + struct aes_ctx *ctx = aes_ctx(desc->tfm);
796 iv = padlock_xcrypt_cbc(in, out, ctx->E, desc->info,
798 static unsigned int aes_decrypt_cbc(const struct cipher_desc *desc, u8 *out,
799 const u8 *in, unsigned int nbytes)
801 - struct aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(desc->tfm));
802 + struct aes_ctx *ctx = aes_ctx(desc->tfm);
803 padlock_xcrypt_cbc(in, out, ctx->D, desc->info, &ctx->cword.decrypt,
804 nbytes / AES_BLOCK_SIZE);
805 return nbytes & ~(AES_BLOCK_SIZE - 1);
806 Index: linux-2.6.16.50/include/linux/crypto.h
807 ===================================================================
808 --- linux-2.6.16.50.orig/include/linux/crypto.h 2006-07-14 18:09:26.387439000 +1200
809 +++ linux-2.6.16.50/include/linux/crypto.h 2006-07-18 01:35:17.475239451 +1200
813 struct crypto_tfm *tfm;
814 - void (*crfn)(void *ctx, u8 *dst, const u8 *src);
815 + void (*crfn)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
816 unsigned int (*prfn)(const struct cipher_desc *desc, u8 *dst,
817 const u8 *src, unsigned int nbytes);
821 unsigned int cia_min_keysize;
822 unsigned int cia_max_keysize;
823 - int (*cia_setkey)(void *ctx, const u8 *key,
824 + int (*cia_setkey)(struct crypto_tfm *tfm, const u8 *key,
825 unsigned int keylen, u32 *flags);
826 - void (*cia_encrypt)(void *ctx, u8 *dst, const u8 *src);
827 - void (*cia_decrypt)(void *ctx, u8 *dst, const u8 *src);
828 + void (*cia_encrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
829 + void (*cia_decrypt)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
831 unsigned int (*cia_encrypt_ecb)(const struct cipher_desc *desc,
832 u8 *dst, const u8 *src,
833 @@ -101,20 +101,19 @@
836 unsigned int dia_digestsize;
837 - void (*dia_init)(void *ctx);
838 - void (*dia_update)(void *ctx, const u8 *data, unsigned int len);
839 - void (*dia_final)(void *ctx, u8 *out);
840 - int (*dia_setkey)(void *ctx, const u8 *key,
841 + void (*dia_init)(struct crypto_tfm *tfm);
842 + void (*dia_update)(struct crypto_tfm *tfm, const u8 *data,
844 + void (*dia_final)(struct crypto_tfm *tfm, u8 *out);
845 + int (*dia_setkey)(struct crypto_tfm *tfm, const u8 *key,
846 unsigned int keylen, u32 *flags);
849 struct compress_alg {
850 - int (*coa_init)(void *ctx);
851 - void (*coa_exit)(void *ctx);
852 - int (*coa_compress)(void *ctx, const u8 *src, unsigned int slen,
853 - u8 *dst, unsigned int *dlen);
854 - int (*coa_decompress)(void *ctx, const u8 *src, unsigned int slen,
855 - u8 *dst, unsigned int *dlen);
856 + int (*coa_compress)(struct crypto_tfm *tfm, const u8 *src,
857 + unsigned int slen, u8 *dst, unsigned int *dlen);
858 + int (*coa_decompress)(struct crypto_tfm *tfm, const u8 *src,
859 + unsigned int slen, u8 *dst, unsigned int *dlen);
862 #define cra_cipher cra_u.cipher
863 @@ -130,14 +129,17 @@
867 - const char cra_name[CRYPTO_MAX_ALG_NAME];
868 - const char cra_driver_name[CRYPTO_MAX_ALG_NAME];
869 + char cra_name[CRYPTO_MAX_ALG_NAME];
870 + char cra_driver_name[CRYPTO_MAX_ALG_NAME];
873 struct cipher_alg cipher;
874 struct digest_alg digest;
875 struct compress_alg compress;
878 + int (*cra_init)(struct crypto_tfm *tfm);
879 + void (*cra_exit)(struct crypto_tfm *tfm);
881 struct module *cra_module;
886 struct crypto_alg *__crt_alg;
888 + char __crt_ctx[] __attribute__ ((__aligned__));
894 static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm)
896 - return (void *)&tfm[1];
897 + return tfm->__crt_ctx;
900 +static inline unsigned int crypto_tfm_ctx_alignment(void)
902 + struct crypto_tfm *tfm;
903 + return __alignof__(tfm->__crt_ctx);
907 Index: linux-2.6.16.50/arch/i386/crypto/aes-i586-asm.S
908 ===================================================================
909 --- linux-2.6.16.50.orig/arch/i386/crypto/aes-i586-asm.S 2006-07-14 18:09:26.339436000 +1200
910 +++ linux-2.6.16.50/arch/i386/crypto/aes-i586-asm.S 2006-07-14 18:10:31.131485250 +1200
912 .file "aes-i586-asm.S"
915 -// aes_rval aes_enc_blk(const unsigned char in_blk[], unsigned char out_blk[], const aes_ctx cx[1])//
916 -// aes_rval aes_dec_blk(const unsigned char in_blk[], unsigned char out_blk[], const aes_ctx cx[1])//
918 -#define tlen 1024 // length of each of 4 'xor' arrays (256 32-bit words)
920 -// offsets to parameters with one register pushed onto stack
921 +#include <asm/asm-offsets.h>
923 -#define in_blk 8 // input byte array address parameter
924 -#define out_blk 12 // output byte array address parameter
925 -#define ctx 16 // AES context structure
927 -// offsets in context structure
928 +#define tlen 1024 // length of each of 4 'xor' arrays (256 32-bit words)
930 -#define ekey 0 // encryption key schedule base address
931 -#define nrnd 256 // number of rounds
932 -#define dkey 260 // decryption key schedule base address
933 +/* offsets to parameters with one register pushed onto stack */
938 +/* offsets in crypto_tfm structure */
939 +#define ekey (crypto_tfm_ctx_offset + 0)
940 +#define nrnd (crypto_tfm_ctx_offset + 256)
941 +#define dkey (crypto_tfm_ctx_offset + 260)
943 // register mapping for encrypt and decrypt subroutines
946 do_col (table, r5,r0,r1,r4, r2,r3); /* idx=r5 */
948 // AES (Rijndael) Encryption Subroutine
949 +/* void aes_enc_blk(struct crypto_tfm *tfm, u8 *out_blk, const u8 *in_blk) */
957 - mov ctx(%esp),%ebp // pointer to context
960 // CAUTION: the order and the values used in these assigns
961 // rely on the register mappings
965 // AES (Rijndael) Decryption Subroutine
966 +/* void aes_dec_blk(struct crypto_tfm *tfm, u8 *out_blk, const u8 *in_blk) */
974 - mov ctx(%esp),%ebp // pointer to context
977 // CAUTION: the order and the values used in these assigns
978 // rely on the register mappings
979 Index: linux-2.6.16.50/arch/i386/crypto/aes.c
980 ===================================================================
981 --- linux-2.6.16.50.orig/arch/i386/crypto/aes.c 2006-07-14 18:09:26.343436250 +1200
982 +++ linux-2.6.16.50/arch/i386/crypto/aes.c 2006-07-14 18:10:31.135485500 +1200
984 #include <linux/crypto.h>
985 #include <linux/linkage.h>
987 -asmlinkage void aes_enc_blk(const u8 *src, u8 *dst, void *ctx);
988 -asmlinkage void aes_dec_blk(const u8 *src, u8 *dst, void *ctx);
989 +asmlinkage void aes_enc_blk(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
990 +asmlinkage void aes_dec_blk(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
992 #define AES_MIN_KEY_SIZE 16
993 #define AES_MAX_KEY_SIZE 32
994 @@ -378,12 +378,12 @@
995 k[8*(i)+11] = ss[3]; \
999 -aes_set_key(void *ctx_arg, const u8 *in_key, unsigned int key_len, u32 *flags)
1000 +static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
1001 + unsigned int key_len, u32 *flags)
1005 - struct aes_ctx *ctx = ctx_arg;
1006 + struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
1007 const __le32 *key = (const __le32 *)in_key;
1009 /* encryption schedule */
1010 @@ -464,16 +464,16 @@
1014 -static inline void aes_encrypt(void *ctx, u8 *dst, const u8 *src)
1015 +static void aes_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
1017 - aes_enc_blk(src, dst, ctx);
1018 + aes_enc_blk(tfm, dst, src);
1020 -static inline void aes_decrypt(void *ctx, u8 *dst, const u8 *src)
1022 +static void aes_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
1024 - aes_dec_blk(src, dst, ctx);
1025 + aes_dec_blk(tfm, dst, src);
1029 static struct crypto_alg aes_alg = {
1031 .cra_driver_name = "aes-i586",
1032 Index: linux-2.6.16.50/arch/i386/kernel/asm-offsets.c
1033 ===================================================================
1034 --- linux-2.6.16.50.orig/arch/i386/kernel/asm-offsets.c 2006-07-14 18:09:26.343436250 +1200
1035 +++ linux-2.6.16.50/arch/i386/kernel/asm-offsets.c 2006-07-14 18:10:31.139485750 +1200
1037 #include <linux/signal.h>
1038 #include <linux/personality.h>
1039 #include <linux/suspend.h>
1040 +#include <linux/crypto.h>
1041 #include <asm/ucontext.h>
1042 #include "sigframe.h"
1043 #include <asm/fixmap.h>
1046 DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
1047 DEFINE(VSYSCALL_BASE, __fix_to_virt(FIX_VSYSCALL));
1049 + OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
1051 Index: linux-2.6.16.50/arch/s390/crypto/aes_s390.c
1052 ===================================================================
1053 --- linux-2.6.16.50.orig/arch/s390/crypto/aes_s390.c 2006-07-14 18:09:26.343436250 +1200
1054 +++ linux-2.6.16.50/arch/s390/crypto/aes_s390.c 2006-07-14 18:10:31.139485750 +1200
1059 -static int aes_set_key(void *ctx, const u8 *in_key, unsigned int key_len,
1061 +static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
1062 + unsigned int key_len, u32 *flags)
1064 - struct s390_aes_ctx *sctx = ctx;
1065 + struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm);
1073 -static void aes_encrypt(void *ctx, u8 *out, const u8 *in)
1074 +static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
1076 - const struct s390_aes_ctx *sctx = ctx;
1077 + const struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm);
1079 switch (sctx->key_len) {
1085 -static void aes_decrypt(void *ctx, u8 *out, const u8 *in)
1086 +static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
1088 - const struct s390_aes_ctx *sctx = ctx;
1089 + const struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm);
1091 switch (sctx->key_len) {
1093 Index: linux-2.6.16.50/arch/s390/crypto/des_s390.c
1094 ===================================================================
1095 --- linux-2.6.16.50.orig/arch/s390/crypto/des_s390.c 2006-07-14 18:09:26.347436500 +1200
1096 +++ linux-2.6.16.50/arch/s390/crypto/des_s390.c 2006-07-14 18:10:31.147486250 +1200
1098 u8 key[DES3_192_KEY_SIZE];
1101 -static int des_setkey(void *ctx, const u8 *key, unsigned int keylen,
1103 +static int des_setkey(struct crypto_tfm *tfm, const u8 *key,
1104 + unsigned int keylen, u32 *flags)
1106 - struct crypt_s390_des_ctx *dctx = ctx;
1107 + struct crypt_s390_des_ctx *dctx = crypto_tfm_ctx(tfm);
1110 /* test if key is valid (not a weak key) */
1115 -static void des_encrypt(void *ctx, u8 *out, const u8 *in)
1116 +static void des_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
1118 - struct crypt_s390_des_ctx *dctx = ctx;
1119 + struct crypt_s390_des_ctx *dctx = crypto_tfm_ctx(tfm);
1121 crypt_s390_km(KM_DEA_ENCRYPT, dctx->key, out, in, DES_BLOCK_SIZE);
1124 -static void des_decrypt(void *ctx, u8 *out, const u8 *in)
1125 +static void des_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
1127 - struct crypt_s390_des_ctx *dctx = ctx;
1128 + struct crypt_s390_des_ctx *dctx = crypto_tfm_ctx(tfm);
1130 crypt_s390_km(KM_DEA_DECRYPT, dctx->key, out, in, DES_BLOCK_SIZE);
1132 @@ -166,11 +166,11 @@
1133 * Implementers MUST reject keys that exhibit this property.
1136 -static int des3_128_setkey(void *ctx, const u8 *key, unsigned int keylen,
1138 +static int des3_128_setkey(struct crypto_tfm *tfm, const u8 *key,
1139 + unsigned int keylen, u32 *flags)
1142 - struct crypt_s390_des3_128_ctx *dctx = ctx;
1143 + struct crypt_s390_des3_128_ctx *dctx = crypto_tfm_ctx(tfm);
1144 const u8* temp_key = key;
1146 if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE))) {
1147 @@ -186,17 +186,17 @@
1151 -static void des3_128_encrypt(void *ctx, u8 *dst, const u8 *src)
1152 +static void des3_128_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
1154 - struct crypt_s390_des3_128_ctx *dctx = ctx;
1155 + struct crypt_s390_des3_128_ctx *dctx = crypto_tfm_ctx(tfm);
1157 crypt_s390_km(KM_TDEA_128_ENCRYPT, dctx->key, dst, (void*)src,
1158 DES3_128_BLOCK_SIZE);
1161 -static void des3_128_decrypt(void *ctx, u8 *dst, const u8 *src)
1162 +static void des3_128_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
1164 - struct crypt_s390_des3_128_ctx *dctx = ctx;
1165 + struct crypt_s390_des3_128_ctx *dctx = crypto_tfm_ctx(tfm);
1167 crypt_s390_km(KM_TDEA_128_DECRYPT, dctx->key, dst, (void*)src,
1168 DES3_128_BLOCK_SIZE);
1169 @@ -302,11 +302,11 @@
1173 -static int des3_192_setkey(void *ctx, const u8 *key, unsigned int keylen,
1175 +static int des3_192_setkey(struct crypto_tfm *tfm, const u8 *key,
1176 + unsigned int keylen, u32 *flags)
1179 - struct crypt_s390_des3_192_ctx *dctx = ctx;
1180 + struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm);
1181 const u8* temp_key = key;
1183 if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) &&
1184 @@ -325,17 +325,17 @@
1188 -static void des3_192_encrypt(void *ctx, u8 *dst, const u8 *src)
1189 +static void des3_192_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
1191 - struct crypt_s390_des3_192_ctx *dctx = ctx;
1192 + struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm);
1194 crypt_s390_km(KM_TDEA_192_ENCRYPT, dctx->key, dst, (void*)src,
1195 DES3_192_BLOCK_SIZE);
1198 -static void des3_192_decrypt(void *ctx, u8 *dst, const u8 *src)
1199 +static void des3_192_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
1201 - struct crypt_s390_des3_192_ctx *dctx = ctx;
1202 + struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm);
1204 crypt_s390_km(KM_TDEA_192_DECRYPT, dctx->key, dst, (void*)src,
1205 DES3_192_BLOCK_SIZE);
1206 Index: linux-2.6.16.50/arch/s390/crypto/sha1_s390.c
1207 ===================================================================
1208 --- linux-2.6.16.50.orig/arch/s390/crypto/sha1_s390.c 2006-07-14 18:09:26.347436500 +1200
1209 +++ linux-2.6.16.50/arch/s390/crypto/sha1_s390.c 2006-07-14 18:10:31.147486250 +1200
1211 u8 buffer[2 * SHA1_BLOCK_SIZE];
1215 -sha1_init(void *ctx)
1216 +static void sha1_init(struct crypto_tfm *tfm)
1218 - static const struct crypt_s390_sha1_ctx initstate = {
1226 + struct crypt_s390_sha1_ctx *ctx = crypto_tfm_ctx(tfm);
1227 + static const u32 initstate[5] = {
1234 - memcpy(ctx, &initstate, sizeof(initstate));
1237 + memcpy(ctx->state, &initstate, sizeof(initstate));
1242 -sha1_update(void *ctx, const u8 *data, unsigned int len)
1243 +static void sha1_update(struct crypto_tfm *tfm, const u8 *data,
1246 struct crypt_s390_sha1_ctx *sctx;
1250 + sctx = crypto_tfm_ctx(tfm);
1251 sctx->count += len * 8; //message bit length
1253 //anything in buffer yet? -> must be completed
1254 @@ -110,10 +111,9 @@
1257 /* Add padding and return the message digest. */
1259 -sha1_final(void* ctx, u8 *out)
1260 +static void sha1_final(struct crypto_tfm *tfm, u8 *out)
1262 - struct crypt_s390_sha1_ctx *sctx = ctx;
1263 + struct crypt_s390_sha1_ctx *sctx = crypto_tfm_ctx(tfm);
1265 //must perform manual padding
1267 Index: linux-2.6.16.50/arch/s390/crypto/sha256_s390.c
1268 ===================================================================
1269 --- linux-2.6.16.50.orig/arch/s390/crypto/sha256_s390.c 2006-07-14 18:09:26.347436500 +1200
1270 +++ linux-2.6.16.50/arch/s390/crypto/sha256_s390.c 2006-07-14 18:10:31.151486500 +1200
1272 u8 buf[2 * SHA256_BLOCK_SIZE];
1275 -static void sha256_init(void *ctx)
1276 +static void sha256_init(struct crypto_tfm *tfm)
1278 - struct s390_sha256_ctx *sctx = ctx;
1279 + struct s390_sha256_ctx *sctx = crypto_tfm_ctx(tfm);
1281 sctx->state[0] = 0x6a09e667;
1282 sctx->state[1] = 0xbb67ae85;
1284 sctx->state[6] = 0x1f83d9ab;
1285 sctx->state[7] = 0x5be0cd19;
1287 - memset(sctx->buf, 0, sizeof(sctx->buf));
1290 -static void sha256_update(void *ctx, const u8 *data, unsigned int len)
1291 +static void sha256_update(struct crypto_tfm *tfm, const u8 *data,
1294 - struct s390_sha256_ctx *sctx = ctx;
1295 + struct s390_sha256_ctx *sctx = crypto_tfm_ctx(tfm);
1302 /* Add padding and return the message digest */
1303 -static void sha256_final(void* ctx, u8 *out)
1304 +static void sha256_final(struct crypto_tfm *tfm, u8 *out)
1306 - struct s390_sha256_ctx *sctx = ctx;
1307 + struct s390_sha256_ctx *sctx = crypto_tfm_ctx(tfm);
1309 /* must perform manual padding */
1311 Index: linux-2.6.16.50/arch/x86_64/crypto/aes-x86_64-asm.S
1312 ===================================================================
1313 --- linux-2.6.16.50.orig/arch/x86_64/crypto/aes-x86_64-asm.S 2006-07-14 18:09:26.339436000 +1200
1314 +++ linux-2.6.16.50/arch/x86_64/crypto/aes-x86_64-asm.S 2006-07-14 18:10:31.151486500 +1200
1319 +#include <asm/asm-offsets.h>
1321 +#define BASE crypto_tfm_ctx_offset
1330 -#define prologue(FUNC,BASE,B128,B192,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11) \
1331 +#define prologue(FUNC,KEY,B128,B192,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11) \
1333 .type FUNC,@function; \
1337 - leaq BASE+52(r8),r9; \
1338 + leaq BASE+KEY+52(r8),r9; \
1340 movl (r7),r5 ## E; \
1341 movl 4(r7),r1 ## E; \
1342 movl 8(r7),r6 ## E; \
1343 movl 12(r7),r7 ## E; \
1344 - movl (r8),r10 ## E; \
1345 + movl BASE(r8),r10 ## E; \
1346 xorl -48(r9),r5 ## E; \
1347 xorl -44(r9),r1 ## E; \
1348 xorl -40(r9),r6 ## E; \
1350 movl r3 ## E,r1 ## E; \
1351 movl r4 ## E,r2 ## E;
1353 -#define entry(FUNC,BASE,B128,B192) \
1354 - prologue(FUNC,BASE,B128,B192,R2,R8,R7,R9,R1,R3,R4,R6,R10,R5,R11)
1355 +#define entry(FUNC,KEY,B128,B192) \
1356 + prologue(FUNC,KEY,B128,B192,R2,R8,R7,R9,R1,R3,R4,R6,R10,R5,R11)
1358 #define return epilogue(R8,R2,R9,R7,R5,R6,R3,R4,R11)
1361 #define decrypt_final(TAB,OFFSET) \
1362 round(TAB,OFFSET,R2,R1,R4,R3,R6,R5,R7,R10,R5,R6,R3,R4)
1364 -/* void aes_encrypt(void *ctx, u8 *out, const u8 *in) */
1365 +/* void aes_enc_blk(stuct crypto_tfm *tfm, u8 *out, const u8 *in) */
1367 - entry(aes_encrypt,0,enc128,enc192)
1368 + entry(aes_enc_blk,0,enc128,enc192)
1369 encrypt_round(aes_ft_tab,-96)
1370 encrypt_round(aes_ft_tab,-80)
1371 enc192: encrypt_round(aes_ft_tab,-64)
1373 encrypt_final(aes_fl_tab,112)
1376 -/* void aes_decrypt(void *ctx, u8 *out, const u8 *in) */
1377 +/* void aes_dec_blk(struct crypto_tfm *tfm, u8 *out, const u8 *in) */
1379 - entry(aes_decrypt,240,dec128,dec192)
1380 + entry(aes_dec_blk,240,dec128,dec192)
1381 decrypt_round(aes_it_tab,-96)
1382 decrypt_round(aes_it_tab,-80)
1383 dec192: decrypt_round(aes_it_tab,-64)
1384 Index: linux-2.6.16.50/arch/x86_64/kernel/asm-offsets.c
1385 ===================================================================
1386 --- linux-2.6.16.50.orig/arch/x86_64/kernel/asm-offsets.c 2006-07-14 18:09:26.339436000 +1200
1387 +++ linux-2.6.16.50/arch/x86_64/kernel/asm-offsets.c 2006-07-14 18:10:31.155486750 +1200
1389 DEFINE(pbe_next, offsetof(struct pbe, next));
1391 DEFINE(TSS_ist, offsetof(struct tss_struct, ist));
1393 + DEFINE(crypto_tfm_ctx_offset, offsetof(struct crypto_tfm, __crt_ctx));
1396 Index: linux-2.6.16.50/crypto/Kconfig
1397 ===================================================================
1398 --- linux-2.6.16.50.orig/crypto/Kconfig 2006-07-14 18:09:26.359437250 +1200
1399 +++ linux-2.6.16.50/crypto/Kconfig 2006-07-14 18:10:31.159487000 +1200
1403 tristate "Testing module"
1405 + depends on CRYPTO && m
1407 Quick & dirty crypto test module.
1409 Index: linux-2.6.16.50/crypto/anubis.c
1410 ===================================================================
1411 --- linux-2.6.16.50.orig/crypto/anubis.c 2006-07-14 18:09:26.359437250 +1200
1412 +++ linux-2.6.16.50/crypto/anubis.c 2006-07-14 18:10:31.163487250 +1200
1413 @@ -460,16 +460,15 @@
1414 0xf726ffedU, 0xe89d6f8eU, 0x19a0f089U,
1417 -static int anubis_setkey(void *ctx_arg, const u8 *in_key,
1418 +static int anubis_setkey(struct crypto_tfm *tfm, const u8 *in_key,
1419 unsigned int key_len, u32 *flags)
1421 + struct anubis_ctx *ctx = crypto_tfm_ctx(tfm);
1422 const __be32 *key = (const __be32 *)in_key;
1424 u32 kappa[ANUBIS_MAX_N];
1425 u32 inter[ANUBIS_MAX_N];
1427 - struct anubis_ctx *ctx = ctx_arg;
1431 case 16: case 20: case 24: case 28:
1432 @@ -660,15 +659,15 @@
1433 dst[i] = cpu_to_be32(inter[i]);
1436 -static void anubis_encrypt(void *ctx_arg, u8 *dst, const u8 *src)
1437 +static void anubis_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
1439 - struct anubis_ctx *ctx = ctx_arg;
1440 + struct anubis_ctx *ctx = crypto_tfm_ctx(tfm);
1441 anubis_crypt(ctx->E, dst, src, ctx->R);
1444 -static void anubis_decrypt(void *ctx_arg, u8 *dst, const u8 *src)
1445 +static void anubis_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
1447 - struct anubis_ctx *ctx = ctx_arg;
1448 + struct anubis_ctx *ctx = crypto_tfm_ctx(tfm);
1449 anubis_crypt(ctx->D, dst, src, ctx->R);
1452 Index: linux-2.6.16.50/crypto/arc4.c
1453 ===================================================================
1454 --- linux-2.6.16.50.orig/crypto/arc4.c 2006-07-14 18:09:26.359437250 +1200
1455 +++ linux-2.6.16.50/crypto/arc4.c 2006-07-14 18:10:31.163487250 +1200
1460 -static int arc4_set_key(void *ctx_arg, const u8 *in_key, unsigned int key_len, u32 *flags)
1461 +static int arc4_set_key(struct crypto_tfm *tfm, const u8 *in_key,
1462 + unsigned int key_len, u32 *flags)
1464 - struct arc4_ctx *ctx = ctx_arg;
1465 + struct arc4_ctx *ctx = crypto_tfm_ctx(tfm);
1466 int i, j = 0, k = 0;
1473 -static void arc4_crypt(void *ctx_arg, u8 *out, const u8 *in)
1474 +static void arc4_crypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
1476 - struct arc4_ctx *ctx = ctx_arg;
1477 + struct arc4_ctx *ctx = crypto_tfm_ctx(tfm);
1479 u8 *const S = ctx->S;
1481 Index: linux-2.6.16.50/crypto/blowfish.c
1482 ===================================================================
1483 --- linux-2.6.16.50.orig/crypto/blowfish.c 2006-07-14 18:09:26.363437500 +1200
1484 +++ linux-2.6.16.50/crypto/blowfish.c 2006-07-14 18:10:31.167487500 +1200
1489 -static void bf_encrypt(void *ctx, u8 *dst, const u8 *src)
1490 +static void bf_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
1492 const __be32 *in_blk = (const __be32 *)src;
1493 __be32 *const out_blk = (__be32 *)dst;
1494 @@ -357,17 +357,18 @@
1496 in32[0] = be32_to_cpu(in_blk[0]);
1497 in32[1] = be32_to_cpu(in_blk[1]);
1498 - encrypt_block(ctx, out32, in32);
1499 + encrypt_block(crypto_tfm_ctx(tfm), out32, in32);
1500 out_blk[0] = cpu_to_be32(out32[0]);
1501 out_blk[1] = cpu_to_be32(out32[1]);
1504 -static void bf_decrypt(void *ctx, u8 *dst, const u8 *src)
1505 +static void bf_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
1507 + struct bf_ctx *ctx = crypto_tfm_ctx(tfm);
1508 const __be32 *in_blk = (const __be32 *)src;
1509 __be32 *const out_blk = (__be32 *)dst;
1510 - const u32 *P = ((struct bf_ctx *)ctx)->p;
1511 - const u32 *S = ((struct bf_ctx *)ctx)->s;
1512 + const u32 *P = ctx->p;
1513 + const u32 *S = ctx->s;
1514 u32 yl = be32_to_cpu(in_blk[0]);
1515 u32 yr = be32_to_cpu(in_blk[1]);
1517 @@ -398,12 +399,14 @@
1519 * Calculates the blowfish S and P boxes for encryption and decryption.
1521 -static int bf_setkey(void *ctx, const u8 *key, unsigned int keylen, u32 *flags)
1522 +static int bf_setkey(struct crypto_tfm *tfm, const u8 *key,
1523 + unsigned int keylen, u32 *flags)
1525 + struct bf_ctx *ctx = crypto_tfm_ctx(tfm);
1530 - u32 *P = ((struct bf_ctx *)ctx)->p;
1531 - u32 *S = ((struct bf_ctx *)ctx)->s;
1533 /* Copy the initialization s-boxes */
1534 for (i = 0, count = 0; i < 256; i++)
1535 Index: linux-2.6.16.50/crypto/cast5.c
1536 ===================================================================
1537 --- linux-2.6.16.50.orig/crypto/cast5.c 2006-07-14 18:09:26.363437500 +1200
1538 +++ linux-2.6.16.50/crypto/cast5.c 2006-07-14 18:10:31.171487750 +1200
1540 (((s1[I >> 24] + s2[(I>>16)&0xff]) ^ s3[(I>>8)&0xff]) - s4[I&0xff]) )
1543 -static void cast5_encrypt(void *ctx, u8 * outbuf, const u8 * inbuf)
1544 +static void cast5_encrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf)
1546 - struct cast5_ctx *c = (struct cast5_ctx *) ctx;
1547 + struct cast5_ctx *c = crypto_tfm_ctx(tfm);
1548 const __be32 *src = (const __be32 *)inbuf;
1549 __be32 *dst = (__be32 *)outbuf;
1552 dst[1] = cpu_to_be32(l);
1555 -static void cast5_decrypt(void *ctx, u8 * outbuf, const u8 * inbuf)
1556 +static void cast5_decrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf)
1558 - struct cast5_ctx *c = (struct cast5_ctx *) ctx;
1559 + struct cast5_ctx *c = crypto_tfm_ctx(tfm);
1560 const __be32 *src = (const __be32 *)inbuf;
1561 __be32 *dst = (__be32 *)outbuf;
1563 @@ -769,15 +769,15 @@
1568 -cast5_setkey(void *ctx, const u8 * key, unsigned key_len, u32 * flags)
1569 +static int cast5_setkey(struct crypto_tfm *tfm, const u8 *key,
1570 + unsigned key_len, u32 *flags)
1572 + struct cast5_ctx *c = crypto_tfm_ctx(tfm);
1578 - struct cast5_ctx *c = (struct cast5_ctx *) ctx;
1580 if (key_len < 5 || key_len > 16) {
1581 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
1582 Index: linux-2.6.16.50/crypto/cast6.c
1583 ===================================================================
1584 --- linux-2.6.16.50.orig/crypto/cast6.c 2006-07-14 18:09:26.363437500 +1200
1585 +++ linux-2.6.16.50/crypto/cast6.c 2006-07-14 18:10:31.175488000 +1200
1586 @@ -381,13 +381,13 @@
1587 key[7] ^= F2(key[0], Tr[i % 4][7], Tm[i][7]);
1591 -cast6_setkey(void *ctx, const u8 * in_key, unsigned key_len, u32 * flags)
1592 +static int cast6_setkey(struct crypto_tfm *tfm, const u8 *in_key,
1593 + unsigned key_len, u32 *flags)
1597 __be32 p_key[8]; /* padded key */
1598 - struct cast6_ctx *c = (struct cast6_ctx *) ctx;
1599 + struct cast6_ctx *c = crypto_tfm_ctx(tfm);
1601 if (key_len < 16 || key_len > 32 || key_len % 4 != 0) {
1602 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
1604 block[2] ^= F1(block[3], Kr[0], Km[0]);
1607 -static void cast6_encrypt (void * ctx, u8 * outbuf, const u8 * inbuf) {
1608 - struct cast6_ctx * c = (struct cast6_ctx *)ctx;
1609 +static void cast6_encrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf)
1611 + struct cast6_ctx *c = crypto_tfm_ctx(tfm);
1612 const __be32 *src = (const __be32 *)inbuf;
1613 __be32 *dst = (__be32 *)outbuf;
1616 dst[3] = cpu_to_be32(block[3]);
1619 -static void cast6_decrypt (void * ctx, u8 * outbuf, const u8 * inbuf) {
1620 - struct cast6_ctx * c = (struct cast6_ctx *)ctx;
1621 +static void cast6_decrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf) {
1622 + struct cast6_ctx * c = crypto_tfm_ctx(tfm);
1623 const __be32 *src = (const __be32 *)inbuf;
1624 __be32 *dst = (__be32 *)outbuf;
1626 Index: linux-2.6.16.50/crypto/cipher.c
1627 ===================================================================
1628 --- linux-2.6.16.50.orig/crypto/cipher.c 2006-07-14 18:09:26.367437750 +1200
1629 +++ linux-2.6.16.50/crypto/cipher.c 2006-07-14 18:10:31.179488250 +1200
1631 void (*xor)(u8 *, const u8 *) = tfm->crt_u.cipher.cit_xor_block;
1632 int bsize = crypto_tfm_alg_blocksize(tfm);
1634 - void (*fn)(void *, u8 *, const u8 *) = desc->crfn;
1635 + void (*fn)(struct crypto_tfm *, u8 *, const u8 *) = desc->crfn;
1636 u8 *iv = desc->info;
1637 unsigned int done = 0;
1643 - fn(crypto_tfm_ctx(tfm), dst, iv);
1645 memcpy(iv, dst, bsize);
1649 u8 *buf = (u8 *)ALIGN((unsigned long)stack, alignmask + 1);
1650 u8 **dst_p = src == dst ? &buf : &dst;
1652 - void (*fn)(void *, u8 *, const u8 *) = desc->crfn;
1653 + void (*fn)(struct crypto_tfm *, u8 *, const u8 *) = desc->crfn;
1654 u8 *iv = desc->info;
1655 unsigned int done = 0;
1659 u8 *tmp_dst = *dst_p;
1661 - fn(crypto_tfm_ctx(tfm), tmp_dst, src);
1662 + fn(tfm, tmp_dst, src);
1664 memcpy(iv, src, bsize);
1666 @@ -245,13 +245,13 @@
1668 struct crypto_tfm *tfm = desc->tfm;
1669 int bsize = crypto_tfm_alg_blocksize(tfm);
1670 - void (*fn)(void *, u8 *, const u8 *) = desc->crfn;
1671 + void (*fn)(struct crypto_tfm *, u8 *, const u8 *) = desc->crfn;
1672 unsigned int done = 0;
1677 - fn(crypto_tfm_ctx(tfm), dst, src);
1678 + fn(tfm, dst, src);
1683 tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
1686 - return cia->cia_setkey(crypto_tfm_ctx(tfm), key, keylen,
1687 + return cia->cia_setkey(tfm, key, keylen,
1691 Index: linux-2.6.16.50/crypto/compress.c
1692 ===================================================================
1693 --- linux-2.6.16.50.orig/crypto/compress.c 2006-07-14 18:09:26.367437750 +1200
1694 +++ linux-2.6.16.50/crypto/compress.c 2006-07-14 18:10:31.183488500 +1200
1696 const u8 *src, unsigned int slen,
1697 u8 *dst, unsigned int *dlen)
1699 - return tfm->__crt_alg->cra_compress.coa_compress(crypto_tfm_ctx(tfm),
1701 + return tfm->__crt_alg->cra_compress.coa_compress(tfm, src, slen, dst,
1706 const u8 *src, unsigned int slen,
1707 u8 *dst, unsigned int *dlen)
1709 - return tfm->__crt_alg->cra_compress.coa_decompress(crypto_tfm_ctx(tfm),
1711 + return tfm->__crt_alg->cra_compress.coa_decompress(tfm, src, slen, dst,
1717 int crypto_init_compress_ops(struct crypto_tfm *tfm)
1720 struct compress_tfm *ops = &tfm->crt_compress;
1722 - ret = tfm->__crt_alg->cra_compress.coa_init(crypto_tfm_ctx(tfm));
1726 ops->cot_compress = crypto_compress;
1727 ops->cot_decompress = crypto_decompress;
1734 void crypto_exit_compress_ops(struct crypto_tfm *tfm)
1736 - tfm->__crt_alg->cra_compress.coa_exit(crypto_tfm_ctx(tfm));
1738 Index: linux-2.6.16.50/crypto/crc32c.c
1739 ===================================================================
1740 --- linux-2.6.16.50.orig/crypto/crc32c.c 2006-07-14 18:09:26.367437750 +1200
1741 +++ linux-2.6.16.50/crypto/crc32c.c 2006-07-14 18:10:31.183488500 +1200
1746 -static void chksum_init(void *ctx)
1747 +static void chksum_init(struct crypto_tfm *tfm)
1749 - struct chksum_ctx *mctx = ctx;
1750 + struct chksum_ctx *mctx = crypto_tfm_ctx(tfm);
1752 mctx->crc = ~(u32)0; /* common usage */
1755 * If your algorithm starts with ~0, then XOR with ~0 before you set
1758 -static int chksum_setkey(void *ctx, const u8 *key, unsigned int keylen,
1760 +static int chksum_setkey(struct crypto_tfm *tfm, const u8 *key,
1761 + unsigned int keylen, u32 *flags)
1763 - struct chksum_ctx *mctx = ctx;
1764 + struct chksum_ctx *mctx = crypto_tfm_ctx(tfm);
1766 if (keylen != sizeof(mctx->crc)) {
1772 -static void chksum_update(void *ctx, const u8 *data, unsigned int length)
1773 +static void chksum_update(struct crypto_tfm *tfm, const u8 *data,
1774 + unsigned int length)
1776 - struct chksum_ctx *mctx = ctx;
1777 + struct chksum_ctx *mctx = crypto_tfm_ctx(tfm);
1780 mcrc = crc32c(mctx->crc, data, (size_t)length);
1785 -static void chksum_final(void *ctx, u8 *out)
1786 +static void chksum_final(struct crypto_tfm *tfm, u8 *out)
1788 - struct chksum_ctx *mctx = ctx;
1789 + struct chksum_ctx *mctx = crypto_tfm_ctx(tfm);
1790 u32 mcrc = (mctx->crc ^ ~(u32)0);
1792 *(u32 *)out = __le32_to_cpu(mcrc);
1793 Index: linux-2.6.16.50/crypto/crypto_null.c
1794 ===================================================================
1795 --- linux-2.6.16.50.orig/crypto/crypto_null.c 2006-07-14 18:09:26.371438000 +1200
1796 +++ linux-2.6.16.50/crypto/crypto_null.c 2006-07-14 18:10:31.187488750 +1200
1798 #define NULL_BLOCK_SIZE 1
1799 #define NULL_DIGEST_SIZE 0
1801 -static int null_compress(void *ctx, const u8 *src, unsigned int slen,
1802 - u8 *dst, unsigned int *dlen)
1803 +static int null_compress(struct crypto_tfm *tfm, const u8 *src,
1804 + unsigned int slen, u8 *dst, unsigned int *dlen)
1812 -static void null_init(void *ctx)
1813 +static void null_init(struct crypto_tfm *tfm)
1816 -static void null_update(void *ctx, const u8 *data, unsigned int len)
1817 +static void null_update(struct crypto_tfm *tfm, const u8 *data,
1821 -static void null_final(void *ctx, u8 *out)
1822 +static void null_final(struct crypto_tfm *tfm, u8 *out)
1825 -static int null_setkey(void *ctx, const u8 *key,
1826 - unsigned int keylen, u32 *flags)
1827 +static int null_setkey(struct crypto_tfm *tfm, const u8 *key,
1828 + unsigned int keylen, u32 *flags)
1831 -static void null_crypt(void *ctx, u8 *dst, const u8 *src)
1832 +static void null_crypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
1834 memcpy(dst, src, NULL_BLOCK_SIZE);
1836 Index: linux-2.6.16.50/crypto/digest.c
1837 ===================================================================
1838 --- linux-2.6.16.50.orig/crypto/digest.c 2006-07-14 18:09:26.371438000 +1200
1839 +++ linux-2.6.16.50/crypto/digest.c 2006-07-14 18:10:31.191489000 +1200
1842 static void init(struct crypto_tfm *tfm)
1844 - tfm->__crt_alg->cra_digest.dia_init(crypto_tfm_ctx(tfm));
1845 + tfm->__crt_alg->cra_digest.dia_init(tfm);
1848 static void update(struct crypto_tfm *tfm,
1849 struct scatterlist *sg, unsigned int nsg)
1852 + unsigned int alignmask = crypto_tfm_alg_alignmask(tfm);
1854 for (i = 0; i < nsg; i++) {
1857 unsigned int bytes_from_page = min(l, ((unsigned int)
1860 - char *p = crypto_kmap(pg, 0) + offset;
1861 + char *src = crypto_kmap(pg, 0);
1862 + char *p = src + offset;
1864 - tfm->__crt_alg->cra_digest.dia_update
1865 - (crypto_tfm_ctx(tfm), p,
1867 - crypto_kunmap(p, 0);
1868 + if (unlikely(offset & alignmask)) {
1869 + unsigned int bytes =
1870 + alignmask + 1 - (offset & alignmask);
1871 + bytes = min(bytes, bytes_from_page);
1872 + tfm->__crt_alg->cra_digest.dia_update(tfm, p,
1875 + bytes_from_page -= bytes;
1878 + tfm->__crt_alg->cra_digest.dia_update(tfm, p,
1880 + crypto_kunmap(src, 0);
1886 static void final(struct crypto_tfm *tfm, u8 *out)
1888 - tfm->__crt_alg->cra_digest.dia_final(crypto_tfm_ctx(tfm), out);
1889 + unsigned long alignmask = crypto_tfm_alg_alignmask(tfm);
1890 + if (unlikely((unsigned long)out & alignmask)) {
1891 + unsigned int size = crypto_tfm_alg_digestsize(tfm);
1892 + u8 buffer[size + alignmask];
1893 + u8 *dst = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
1894 + tfm->__crt_alg->cra_digest.dia_final(tfm, dst);
1895 + memcpy(out, dst, size);
1897 + tfm->__crt_alg->cra_digest.dia_final(tfm, out);
1900 static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
1903 if (tfm->__crt_alg->cra_digest.dia_setkey == NULL)
1905 - return tfm->__crt_alg->cra_digest.dia_setkey(crypto_tfm_ctx(tfm),
1906 - key, keylen, &flags);
1907 + return tfm->__crt_alg->cra_digest.dia_setkey(tfm, key, keylen, &flags);
1910 static void digest(struct crypto_tfm *tfm,
1911 struct scatterlist *sg, unsigned int nsg, u8 *out)
1915 - tfm->crt_digest.dit_init(tfm);
1917 - for (i = 0; i < nsg; i++) {
1918 - char *p = crypto_kmap(sg[i].page, 0) + sg[i].offset;
1919 - tfm->__crt_alg->cra_digest.dia_update(crypto_tfm_ctx(tfm),
1921 - crypto_kunmap(p, 0);
1922 - crypto_yield(tfm);
1924 - crypto_digest_final(tfm, out);
1926 + update(tfm, sg, nsg);
1930 int crypto_init_digest_flags(struct crypto_tfm *tfm, u32 flags)
1931 Index: linux-2.6.16.50/crypto/khazad.c
1932 ===================================================================
1933 --- linux-2.6.16.50.orig/crypto/khazad.c 2006-07-14 18:09:26.371438000 +1200
1934 +++ linux-2.6.16.50/crypto/khazad.c 2006-07-14 18:10:31.195489250 +1200
1935 @@ -754,11 +754,11 @@
1936 0xccc41d14c363da5dULL, 0x5fdc7dcd7f5a6c5cULL, 0xf726ffede89d6f8eULL
1939 -static int khazad_setkey(void *ctx_arg, const u8 *in_key,
1940 - unsigned int key_len, u32 *flags)
1941 +static int khazad_setkey(struct crypto_tfm *tfm, const u8 *in_key,
1942 + unsigned int key_len, u32 *flags)
1944 - struct khazad_ctx *ctx = ctx_arg;
1945 - const __be64 *key = (const __be64 *)in_key;
1946 + struct khazad_ctx *ctx = crypto_tfm_ctx(tfm);
1947 + const __be32 *key = (const __be32 *)in_key;
1955 - K2 = be64_to_cpu(key[0]);
1956 - K1 = be64_to_cpu(key[1]);
1957 + /* key is supposed to be 32-bit aligned */
1958 + K2 = ((u64)be32_to_cpu(key[0]) << 32) | be32_to_cpu(key[1]);
1959 + K1 = ((u64)be32_to_cpu(key[2]) << 32) | be32_to_cpu(key[3]);
1961 /* setup the encrypt key */
1962 for (r = 0; r <= KHAZAD_ROUNDS; r++) {
1963 @@ -840,15 +841,15 @@
1964 *dst = cpu_to_be64(state);
1967 -static void khazad_encrypt(void *ctx_arg, u8 *dst, const u8 *src)
1968 +static void khazad_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
1970 - struct khazad_ctx *ctx = ctx_arg;
1971 + struct khazad_ctx *ctx = crypto_tfm_ctx(tfm);
1972 khazad_crypt(ctx->E, dst, src);
1975 -static void khazad_decrypt(void *ctx_arg, u8 *dst, const u8 *src)
1976 +static void khazad_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
1978 - struct khazad_ctx *ctx = ctx_arg;
1979 + struct khazad_ctx *ctx = crypto_tfm_ctx(tfm);
1980 khazad_crypt(ctx->D, dst, src);
1983 Index: linux-2.6.16.50/crypto/md4.c
1984 ===================================================================
1985 --- linux-2.6.16.50.orig/crypto/md4.c 2006-07-14 18:09:26.375438250 +1200
1986 +++ linux-2.6.16.50/crypto/md4.c 2006-07-14 18:10:31.199489500 +1200
1988 md4_transform(ctx->hash, ctx->block);
1991 -static void md4_init(void *ctx)
1992 +static void md4_init(struct crypto_tfm *tfm)
1994 - struct md4_ctx *mctx = ctx;
1995 + struct md4_ctx *mctx = crypto_tfm_ctx(tfm);
1997 mctx->hash[0] = 0x67452301;
1998 mctx->hash[1] = 0xefcdab89;
2000 mctx->byte_count = 0;
2003 -static void md4_update(void *ctx, const u8 *data, unsigned int len)
2004 +static void md4_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len)
2006 - struct md4_ctx *mctx = ctx;
2007 + struct md4_ctx *mctx = crypto_tfm_ctx(tfm);
2008 const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f);
2010 mctx->byte_count += len;
2012 memcpy(mctx->block, data, len);
2015 -static void md4_final(void *ctx, u8 *out)
2016 +static void md4_final(struct crypto_tfm *tfm, u8 *out)
2018 - struct md4_ctx *mctx = ctx;
2019 + struct md4_ctx *mctx = crypto_tfm_ctx(tfm);
2020 const unsigned int offset = mctx->byte_count & 0x3f;
2021 char *p = (char *)mctx->block + offset;
2022 int padding = 56 - (offset + 1);
2023 Index: linux-2.6.16.50/crypto/md5.c
2024 ===================================================================
2025 --- linux-2.6.16.50.orig/crypto/md5.c 2006-07-14 18:09:26.375438250 +1200
2026 +++ linux-2.6.16.50/crypto/md5.c 2006-07-14 18:10:31.199489500 +1200
2028 md5_transform(ctx->hash, ctx->block);
2031 -static void md5_init(void *ctx)
2032 +static void md5_init(struct crypto_tfm *tfm)
2034 - struct md5_ctx *mctx = ctx;
2035 + struct md5_ctx *mctx = crypto_tfm_ctx(tfm);
2037 mctx->hash[0] = 0x67452301;
2038 mctx->hash[1] = 0xefcdab89;
2040 mctx->byte_count = 0;
2043 -static void md5_update(void *ctx, const u8 *data, unsigned int len)
2044 +static void md5_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len)
2046 - struct md5_ctx *mctx = ctx;
2047 + struct md5_ctx *mctx = crypto_tfm_ctx(tfm);
2048 const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f);
2050 mctx->byte_count += len;
2052 memcpy(mctx->block, data, len);
2055 -static void md5_final(void *ctx, u8 *out)
2056 +static void md5_final(struct crypto_tfm *tfm, u8 *out)
2058 - struct md5_ctx *mctx = ctx;
2059 + struct md5_ctx *mctx = crypto_tfm_ctx(tfm);
2060 const unsigned int offset = mctx->byte_count & 0x3f;
2061 char *p = (char *)mctx->block + offset;
2062 int padding = 56 - (offset + 1);
2063 Index: linux-2.6.16.50/crypto/michael_mic.c
2064 ===================================================================
2065 --- linux-2.6.16.50.orig/crypto/michael_mic.c 2006-07-14 18:09:26.375438250 +1200
2066 +++ linux-2.6.16.50/crypto/michael_mic.c 2006-07-14 18:10:31.203489750 +1200
2071 -static void michael_init(void *ctx)
2072 +static void michael_init(struct crypto_tfm *tfm)
2074 - struct michael_mic_ctx *mctx = ctx;
2075 + struct michael_mic_ctx *mctx = crypto_tfm_ctx(tfm);
2076 mctx->pending_len = 0;
2080 -static void michael_update(void *ctx, const u8 *data, unsigned int len)
2081 +static void michael_update(struct crypto_tfm *tfm, const u8 *data,
2084 - struct michael_mic_ctx *mctx = ctx;
2085 + struct michael_mic_ctx *mctx = crypto_tfm_ctx(tfm);
2088 if (mctx->pending_len) {
2093 -static void michael_final(void *ctx, u8 *out)
2094 +static void michael_final(struct crypto_tfm *tfm, u8 *out)
2096 - struct michael_mic_ctx *mctx = ctx;
2097 + struct michael_mic_ctx *mctx = crypto_tfm_ctx(tfm);
2098 u8 *data = mctx->pending;
2099 __le32 *dst = (__le32 *)out;
2101 @@ -121,10 +122,10 @@
2105 -static int michael_setkey(void *ctx, const u8 *key, unsigned int keylen,
2107 +static int michael_setkey(struct crypto_tfm *tfm, const u8 *key,
2108 + unsigned int keylen, u32 *flags)
2110 - struct michael_mic_ctx *mctx = ctx;
2111 + struct michael_mic_ctx *mctx = crypto_tfm_ctx(tfm);
2112 const __le32 *data = (const __le32 *)key;
2117 .cra_ctxsize = sizeof(struct michael_mic_ctx),
2118 .cra_module = THIS_MODULE,
2119 + .cra_alignmask = 3,
2120 .cra_list = LIST_HEAD_INIT(michael_mic_alg.cra_list),
2121 .cra_u = { .digest = {
2122 .dia_digestsize = 8,
2123 Index: linux-2.6.16.50/crypto/sha1.c
2124 ===================================================================
2125 --- linux-2.6.16.50.orig/crypto/sha1.c 2006-07-14 18:09:26.379438500 +1200
2126 +++ linux-2.6.16.50/crypto/sha1.c 2006-07-18 01:35:17.455238201 +1200
2131 -static void sha1_init(void *ctx)
2132 +static void sha1_init(struct crypto_tfm *tfm)
2134 - struct sha1_ctx *sctx = ctx;
2135 + struct sha1_ctx *sctx = crypto_tfm_ctx(tfm);
2136 static const struct sha1_ctx initstate = {
2138 { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 },
2143 -static void sha1_update(void *ctx, const u8 *data, unsigned int len)
2144 +static void sha1_update(struct crypto_tfm *tfm, const u8 *data,
2147 - struct sha1_ctx *sctx = ctx;
2148 + struct sha1_ctx *sctx = crypto_tfm_ctx(tfm);
2149 unsigned int partial, done;
2155 /* Add padding and return the message digest. */
2156 -static void sha1_final(void* ctx, u8 *out)
2157 +static void sha1_final(struct crypto_tfm *tfm, u8 *out)
2159 - struct sha1_ctx *sctx = ctx;
2160 + struct sha1_ctx *sctx = crypto_tfm_ctx(tfm);
2161 __be32 *dst = (__be32 *)out;
2162 u32 i, index, padlen;
2165 /* Pad out to 56 mod 64 */
2166 index = sctx->count & 0x3f;
2167 padlen = (index < 56) ? (56 - index) : ((64+56) - index);
2168 - sha1_update(sctx, padding, padlen);
2169 + sha1_update(tfm, padding, padlen);
2172 - sha1_update(sctx, (const u8 *)&bits, sizeof(bits));
2173 + sha1_update(tfm, (const u8 *)&bits, sizeof(bits));
2175 /* Store state in digest */
2176 for (i = 0; i < 5; i++)
2178 .cra_blocksize = SHA1_HMAC_BLOCK_SIZE,
2179 .cra_ctxsize = sizeof(struct sha1_ctx),
2180 .cra_module = THIS_MODULE,
2181 + .cra_alignmask = 3,
2182 .cra_list = LIST_HEAD_INIT(alg.cra_list),
2183 .cra_u = { .digest = {
2184 .dia_digestsize = SHA1_DIGEST_SIZE,
2185 Index: linux-2.6.16.50/crypto/sha256.c
2186 ===================================================================
2187 --- linux-2.6.16.50.orig/crypto/sha256.c 2006-07-14 18:09:26.379438500 +1200
2188 +++ linux-2.6.16.50/crypto/sha256.c 2006-07-18 01:35:17.455238201 +1200
2190 memset(W, 0, 64 * sizeof(u32));
2193 -static void sha256_init(void *ctx)
2194 +static void sha256_init(struct crypto_tfm *tfm)
2196 - struct sha256_ctx *sctx = ctx;
2197 + struct sha256_ctx *sctx = crypto_tfm_ctx(tfm);
2198 sctx->state[0] = H0;
2199 sctx->state[1] = H1;
2200 sctx->state[2] = H2;
2201 @@ -242,12 +242,12 @@
2202 sctx->state[6] = H6;
2203 sctx->state[7] = H7;
2204 sctx->count[0] = sctx->count[1] = 0;
2205 - memset(sctx->buf, 0, sizeof(sctx->buf));
2208 -static void sha256_update(void *ctx, const u8 *data, unsigned int len)
2209 +static void sha256_update(struct crypto_tfm *tfm, const u8 *data,
2212 - struct sha256_ctx *sctx = ctx;
2213 + struct sha256_ctx *sctx = crypto_tfm_ctx(tfm);
2214 unsigned int i, index, part_len;
2216 /* Compute number of bytes mod 128 */
2218 memcpy(&sctx->buf[index], &data[i], len-i);
2221 -static void sha256_final(void* ctx, u8 *out)
2222 +static void sha256_final(struct crypto_tfm *tfm, u8 *out)
2224 - struct sha256_ctx *sctx = ctx;
2225 + struct sha256_ctx *sctx = crypto_tfm_ctx(tfm);
2226 __be32 *dst = (__be32 *)out;
2228 unsigned int index, pad_len;
2229 @@ -293,10 +293,10 @@
2230 /* Pad out to 56 mod 64. */
2231 index = (sctx->count[0] >> 3) & 0x3f;
2232 pad_len = (index < 56) ? (56 - index) : ((64+56) - index);
2233 - sha256_update(sctx, padding, pad_len);
2234 + sha256_update(tfm, padding, pad_len);
2236 /* Append length (before padding) */
2237 - sha256_update(sctx, (const u8 *)bits, sizeof(bits));
2238 + sha256_update(tfm, (const u8 *)bits, sizeof(bits));
2240 /* Store state in digest */
2241 for (i = 0; i < 8; i++)
2243 .cra_blocksize = SHA256_HMAC_BLOCK_SIZE,
2244 .cra_ctxsize = sizeof(struct sha256_ctx),
2245 .cra_module = THIS_MODULE,
2246 + .cra_alignmask = 3,
2247 .cra_list = LIST_HEAD_INIT(alg.cra_list),
2248 .cra_u = { .digest = {
2249 .dia_digestsize = SHA256_DIGEST_SIZE,
2250 Index: linux-2.6.16.50/crypto/sha512.c
2251 ===================================================================
2252 --- linux-2.6.16.50.orig/crypto/sha512.c 2006-07-14 18:09:26.379438500 +1200
2253 +++ linux-2.6.16.50/crypto/sha512.c 2006-07-14 18:10:31.211490250 +1200
2258 -sha512_init(void *ctx)
2259 +sha512_init(struct crypto_tfm *tfm)
2261 - struct sha512_ctx *sctx = ctx;
2262 + struct sha512_ctx *sctx = crypto_tfm_ctx(tfm);
2263 sctx->state[0] = H0;
2264 sctx->state[1] = H1;
2265 sctx->state[2] = H2;
2266 @@ -173,13 +173,12 @@
2267 sctx->state[6] = H6;
2268 sctx->state[7] = H7;
2269 sctx->count[0] = sctx->count[1] = sctx->count[2] = sctx->count[3] = 0;
2270 - memset(sctx->buf, 0, sizeof(sctx->buf));
2274 -sha384_init(void *ctx)
2275 +sha384_init(struct crypto_tfm *tfm)
2277 - struct sha512_ctx *sctx = ctx;
2278 + struct sha512_ctx *sctx = crypto_tfm_ctx(tfm);
2279 sctx->state[0] = HP0;
2280 sctx->state[1] = HP1;
2281 sctx->state[2] = HP2;
2282 @@ -189,13 +188,12 @@
2283 sctx->state[6] = HP6;
2284 sctx->state[7] = HP7;
2285 sctx->count[0] = sctx->count[1] = sctx->count[2] = sctx->count[3] = 0;
2286 - memset(sctx->buf, 0, sizeof(sctx->buf));
2290 -sha512_update(void *ctx, const u8 *data, unsigned int len)
2291 +sha512_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len)
2293 - struct sha512_ctx *sctx = ctx;
2294 + struct sha512_ctx *sctx = crypto_tfm_ctx(tfm);
2296 unsigned int i, index, part_len;
2302 -sha512_final(void *ctx, u8 *hash)
2303 +sha512_final(struct crypto_tfm *tfm, u8 *hash)
2305 - struct sha512_ctx *sctx = ctx;
2306 + struct sha512_ctx *sctx = crypto_tfm_ctx(tfm);
2307 static u8 padding[128] = { 0x80, };
2308 __be64 *dst = (__be64 *)hash;
2310 @@ -251,10 +249,10 @@
2311 /* Pad out to 112 mod 128. */
2312 index = (sctx->count[0] >> 3) & 0x7f;
2313 pad_len = (index < 112) ? (112 - index) : ((128+112) - index);
2314 - sha512_update(sctx, padding, pad_len);
2315 + sha512_update(tfm, padding, pad_len);
2317 /* Append length (before padding) */
2318 - sha512_update(sctx, (const u8 *)bits, sizeof(bits));
2319 + sha512_update(tfm, (const u8 *)bits, sizeof(bits));
2321 /* Store state in digest */
2322 for (i = 0; i < 8; i++)
2323 @@ -264,12 +262,11 @@
2324 memset(sctx, 0, sizeof(struct sha512_ctx));
2327 -static void sha384_final(void *ctx, u8 *hash)
2328 +static void sha384_final(struct crypto_tfm *tfm, u8 *hash)
2330 - struct sha512_ctx *sctx = ctx;
2333 - sha512_final(sctx, D);
2334 + sha512_final(tfm, D);
2336 memcpy(hash, D, 48);
2339 .cra_blocksize = SHA512_HMAC_BLOCK_SIZE,
2340 .cra_ctxsize = sizeof(struct sha512_ctx),
2341 .cra_module = THIS_MODULE,
2342 + .cra_alignmask = 3,
2343 .cra_list = LIST_HEAD_INIT(sha512.cra_list),
2344 .cra_u = { .digest = {
2345 .dia_digestsize = SHA512_DIGEST_SIZE,
2347 .cra_flags = CRYPTO_ALG_TYPE_DIGEST,
2348 .cra_blocksize = SHA384_HMAC_BLOCK_SIZE,
2349 .cra_ctxsize = sizeof(struct sha512_ctx),
2350 + .cra_alignmask = 3,
2351 .cra_module = THIS_MODULE,
2352 .cra_list = LIST_HEAD_INIT(sha384.cra_list),
2353 .cra_u = { .digest = {
2354 Index: linux-2.6.16.50/crypto/tcrypt.c
2355 ===================================================================
2356 --- linux-2.6.16.50.orig/crypto/tcrypt.c 2006-07-14 18:09:26.379438500 +1200
2357 +++ linux-2.6.16.50/crypto/tcrypt.c 2006-07-18 01:36:18.591058951 +1200
2358 @@ -570,6 +570,122 @@
2359 crypto_free_tfm(tfm);
2362 +static void test_digest_jiffies(struct crypto_tfm *tfm, char *p, int blen,
2363 + int plen, char *out, int sec)
2365 + struct scatterlist sg[1];
2366 + unsigned long start, end;
2367 + int bcount, pcount;
2369 + for (start = jiffies, end = start + sec * HZ, bcount = 0;
2370 + time_before(jiffies, end); bcount++) {
2371 + crypto_digest_init(tfm);
2372 + for (pcount = 0; pcount < blen; pcount += plen) {
2373 + sg_set_buf(sg, p + pcount, plen);
2374 + crypto_digest_update(tfm, sg, 1);
2376 + /* we assume there is enough space in 'out' for the result */
2377 + crypto_digest_final(tfm, out);
2380 + printk("%6u opers/sec, %9lu bytes/sec\n",
2381 + bcount / sec, ((long)bcount * blen) / sec);
2386 +static void test_digest_cycles(struct crypto_tfm *tfm, char *p, int blen,
2387 + int plen, char *out)
2389 + struct scatterlist sg[1];
2390 + unsigned long cycles = 0;
2393 + local_bh_disable();
2394 + local_irq_disable();
2396 + /* Warm-up run. */
2397 + for (i = 0; i < 4; i++) {
2398 + crypto_digest_init(tfm);
2399 + for (pcount = 0; pcount < blen; pcount += plen) {
2400 + sg_set_buf(sg, p + pcount, plen);
2401 + crypto_digest_update(tfm, sg, 1);
2403 + crypto_digest_final(tfm, out);
2406 + /* The real thing. */
2407 + for (i = 0; i < 8; i++) {
2408 + cycles_t start, end;
2410 + crypto_digest_init(tfm);
2412 + start = get_cycles();
2414 + for (pcount = 0; pcount < blen; pcount += plen) {
2415 + sg_set_buf(sg, p + pcount, plen);
2416 + crypto_digest_update(tfm, sg, 1);
2418 + crypto_digest_final(tfm, out);
2420 + end = get_cycles();
2422 + cycles += end - start;
2425 + local_irq_enable();
2426 + local_bh_enable();
2428 + printk("%6lu cycles/operation, %4lu cycles/byte\n",
2429 + cycles / 8, cycles / (8 * blen));
2434 +static void test_digest_speed(char *algo, unsigned int sec,
2435 + struct digest_speed *speed)
2437 + struct crypto_tfm *tfm;
2438 + char output[1024];
2441 + printk("\ntesting speed of %s\n", algo);
2443 + tfm = crypto_alloc_tfm(algo, 0);
2445 + if (tfm == NULL) {
2446 + printk("failed to load transform for %s\n", algo);
2450 + if (crypto_tfm_alg_digestsize(tfm) > sizeof(output)) {
2451 + printk("digestsize(%u) > outputbuffer(%zu)\n",
2452 + crypto_tfm_alg_digestsize(tfm), sizeof(output));
2456 + for (i = 0; speed[i].blen != 0; i++) {
2457 + if (speed[i].blen > TVMEMSIZE) {
2458 + printk("template (%u) too big for tvmem (%u)\n",
2459 + speed[i].blen, TVMEMSIZE);
2463 + printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
2464 + i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
2466 + memset(tvmem, 0xff, speed[i].blen);
2469 + test_digest_jiffies(tfm, tvmem, speed[i].blen, speed[i].plen, output, sec);
2471 + test_digest_cycles(tfm, tvmem, speed[i].blen, speed[i].plen, output);
2475 + crypto_free_tfm(tfm);
2478 static void test_deflate(void)
2481 @@ -1086,6 +1202,60 @@
2482 des_speed_template);
2486 + /* fall through */
2489 + test_digest_speed("md4", sec, generic_digest_speed_template);
2490 + if (mode > 300 && mode < 400) break;
2493 + test_digest_speed("md5", sec, generic_digest_speed_template);
2494 + if (mode > 300 && mode < 400) break;
2497 + test_digest_speed("sha1", sec, generic_digest_speed_template);
2498 + if (mode > 300 && mode < 400) break;
2501 + test_digest_speed("sha256", sec, generic_digest_speed_template);
2502 + if (mode > 300 && mode < 400) break;
2505 + test_digest_speed("sha384", sec, generic_digest_speed_template);
2506 + if (mode > 300 && mode < 400) break;
2509 + test_digest_speed("sha512", sec, generic_digest_speed_template);
2510 + if (mode > 300 && mode < 400) break;
2513 + test_digest_speed("wp256", sec, generic_digest_speed_template);
2514 + if (mode > 300 && mode < 400) break;
2517 + test_digest_speed("wp384", sec, generic_digest_speed_template);
2518 + if (mode > 300 && mode < 400) break;
2521 + test_digest_speed("wp512", sec, generic_digest_speed_template);
2522 + if (mode > 300 && mode < 400) break;
2525 + test_digest_speed("tgr128", sec, generic_digest_speed_template);
2526 + if (mode > 300 && mode < 400) break;
2529 + test_digest_speed("tgr160", sec, generic_digest_speed_template);
2530 + if (mode > 300 && mode < 400) break;
2533 + test_digest_speed("tgr192", sec, generic_digest_speed_template);
2534 + if (mode > 300 && mode < 400) break;
2542 @@ -1113,7 +1283,14 @@
2548 + /* We intentionaly return -EAGAIN to prevent keeping
2549 + * the module. It does all its work from init()
2550 + * and doesn't offer any runtime functionality
2551 + * => we don't need it in the memory, do we?
2558 Index: linux-2.6.16.50/crypto/tea.c
2559 ===================================================================
2560 --- linux-2.6.16.50.orig/crypto/tea.c 2006-07-14 18:09:26.383438750 +1200
2561 +++ linux-2.6.16.50/crypto/tea.c 2006-07-14 18:10:31.223491000 +1200
2566 -static int tea_setkey(void *ctx_arg, const u8 *in_key,
2567 - unsigned int key_len, u32 *flags)
2569 - struct tea_ctx *ctx = ctx_arg;
2570 +static int tea_setkey(struct crypto_tfm *tfm, const u8 *in_key,
2571 + unsigned int key_len, u32 *flags)
2573 + struct tea_ctx *ctx = crypto_tfm_ctx(tfm);
2574 const __le32 *key = (const __le32 *)in_key;
2581 -static void tea_encrypt(void *ctx_arg, u8 *dst, const u8 *src)
2583 +static void tea_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
2585 u32 y, z, n, sum = 0;
2588 - struct tea_ctx *ctx = ctx_arg;
2589 + struct tea_ctx *ctx = crypto_tfm_ctx(tfm);
2590 const __le32 *in = (const __le32 *)src;
2591 __le32 *out = (__le32 *)dst;
2594 out[1] = cpu_to_le32(z);
2597 -static void tea_decrypt(void *ctx_arg, u8 *dst, const u8 *src)
2599 +static void tea_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
2603 - struct tea_ctx *ctx = ctx_arg;
2604 + struct tea_ctx *ctx = crypto_tfm_ctx(tfm);
2605 const __le32 *in = (const __le32 *)src;
2606 __le32 *out = (__le32 *)dst;
2608 @@ -125,10 +124,10 @@
2609 out[1] = cpu_to_le32(z);
2612 -static int xtea_setkey(void *ctx_arg, const u8 *in_key,
2613 - unsigned int key_len, u32 *flags)
2615 - struct xtea_ctx *ctx = ctx_arg;
2616 +static int xtea_setkey(struct crypto_tfm *tfm, const u8 *in_key,
2617 + unsigned int key_len, u32 *flags)
2619 + struct xtea_ctx *ctx = crypto_tfm_ctx(tfm);
2620 const __le32 *key = (const __le32 *)in_key;
2623 @@ -146,12 +145,11 @@
2627 -static void xtea_encrypt(void *ctx_arg, u8 *dst, const u8 *src)
2629 +static void xtea_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
2632 u32 limit = XTEA_DELTA * XTEA_ROUNDS;
2634 - struct xtea_ctx *ctx = ctx_arg;
2635 + struct xtea_ctx *ctx = crypto_tfm_ctx(tfm);
2636 const __le32 *in = (const __le32 *)src;
2637 __le32 *out = (__le32 *)dst;
2639 @@ -168,10 +166,10 @@
2640 out[1] = cpu_to_le32(z);
2643 -static void xtea_decrypt(void *ctx_arg, u8 *dst, const u8 *src)
2645 +static void xtea_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
2648 - struct tea_ctx *ctx = ctx_arg;
2649 + struct tea_ctx *ctx = crypto_tfm_ctx(tfm);
2650 const __le32 *in = (const __le32 *)src;
2651 __le32 *out = (__le32 *)dst;
2653 @@ -191,12 +189,11 @@
2657 -static void xeta_encrypt(void *ctx_arg, u8 *dst, const u8 *src)
2659 +static void xeta_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
2662 u32 limit = XTEA_DELTA * XTEA_ROUNDS;
2664 - struct xtea_ctx *ctx = ctx_arg;
2665 + struct xtea_ctx *ctx = crypto_tfm_ctx(tfm);
2666 const __le32 *in = (const __le32 *)src;
2667 __le32 *out = (__le32 *)dst;
2669 @@ -213,10 +210,10 @@
2670 out[1] = cpu_to_le32(z);
2673 -static void xeta_decrypt(void *ctx_arg, u8 *dst, const u8 *src)
2675 +static void xeta_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
2678 - struct tea_ctx *ctx = ctx_arg;
2679 + struct tea_ctx *ctx = crypto_tfm_ctx(tfm);
2680 const __le32 *in = (const __le32 *)src;
2681 __le32 *out = (__le32 *)dst;
2683 Index: linux-2.6.16.50/crypto/tgr192.c
2684 ===================================================================
2685 --- linux-2.6.16.50.orig/crypto/tgr192.c 2006-07-14 18:09:26.383438750 +1200
2686 +++ linux-2.6.16.50/crypto/tgr192.c 2006-07-14 18:10:31.227491250 +1200
2687 @@ -496,11 +496,10 @@
2691 -static void tgr192_init(void *ctx)
2692 +static void tgr192_init(struct crypto_tfm *tfm)
2694 - struct tgr192_ctx *tctx = ctx;
2695 + struct tgr192_ctx *tctx = crypto_tfm_ctx(tfm);
2697 - memset (tctx->hash, 0, 64);
2698 tctx->a = 0x0123456789abcdefULL;
2699 tctx->b = 0xfedcba9876543210ULL;
2700 tctx->c = 0xf096a5b4c3b2e187ULL;
2701 @@ -511,9 +510,10 @@
2703 /* Update the message digest with the contents
2704 * of INBUF with length INLEN. */
2705 -static void tgr192_update(void *ctx, const u8 * inbuf, unsigned int len)
2706 +static void tgr192_update(struct crypto_tfm *tfm, const u8 *inbuf,
2709 - struct tgr192_ctx *tctx = ctx;
2710 + struct tgr192_ctx *tctx = crypto_tfm_ctx(tfm);
2712 if (tctx->count == 64) { /* flush the buffer */
2713 tgr192_transform(tctx, tctx->hash);
2715 for (; len && tctx->count < 64; len--) {
2716 tctx->hash[tctx->count++] = *inbuf++;
2718 - tgr192_update(tctx, NULL, 0);
2719 + tgr192_update(tfm, NULL, 0);
2723 @@ -549,15 +549,15 @@
2726 /* The routine terminates the computation */
2727 -static void tgr192_final(void *ctx, u8 * out)
2728 +static void tgr192_final(struct crypto_tfm *tfm, u8 * out)
2730 - struct tgr192_ctx *tctx = ctx;
2731 + struct tgr192_ctx *tctx = crypto_tfm_ctx(tfm);
2732 __be64 *dst = (__be64 *)out;
2737 - tgr192_update(tctx, NULL, 0); /* flush */ ;
2738 + tgr192_update(tfm, NULL, 0); /* flush */ ;
2743 while (tctx->count < 64) {
2744 tctx->hash[tctx->count++] = 0;
2746 - tgr192_update(tctx, NULL, 0); /* flush */ ;
2747 + tgr192_update(tfm, NULL, 0); /* flush */ ;
2748 memset(tctx->hash, 0, 56); /* fill next block with zeroes */
2750 /* append the 64 bit count */
2751 @@ -601,22 +601,20 @@
2752 dst[2] = be64p[2] = cpu_to_be64(tctx->c);
2755 -static void tgr160_final(void *ctx, u8 * out)
2756 +static void tgr160_final(struct crypto_tfm *tfm, u8 * out)
2758 - struct tgr192_ctx *wctx = ctx;
2761 - tgr192_final(wctx, D);
2762 + tgr192_final(tfm, D);
2763 memcpy(out, D, TGR160_DIGEST_SIZE);
2764 memset(D, 0, TGR192_DIGEST_SIZE);
2767 -static void tgr128_final(void *ctx, u8 * out)
2768 +static void tgr128_final(struct crypto_tfm *tfm, u8 * out)
2770 - struct tgr192_ctx *wctx = ctx;
2773 - tgr192_final(wctx, D);
2774 + tgr192_final(tfm, D);
2775 memcpy(out, D, TGR128_DIGEST_SIZE);
2776 memset(D, 0, TGR192_DIGEST_SIZE);
2779 .cra_blocksize = TGR192_BLOCK_SIZE,
2780 .cra_ctxsize = sizeof(struct tgr192_ctx),
2781 .cra_module = THIS_MODULE,
2782 + .cra_alignmask = 7,
2783 .cra_list = LIST_HEAD_INIT(tgr192.cra_list),
2784 .cra_u = {.digest = {
2785 .dia_digestsize = TGR192_DIGEST_SIZE,
2787 .cra_blocksize = TGR192_BLOCK_SIZE,
2788 .cra_ctxsize = sizeof(struct tgr192_ctx),
2789 .cra_module = THIS_MODULE,
2790 + .cra_alignmask = 7,
2791 .cra_list = LIST_HEAD_INIT(tgr160.cra_list),
2792 .cra_u = {.digest = {
2793 .dia_digestsize = TGR160_DIGEST_SIZE,
2795 .cra_blocksize = TGR192_BLOCK_SIZE,
2796 .cra_ctxsize = sizeof(struct tgr192_ctx),
2797 .cra_module = THIS_MODULE,
2798 + .cra_alignmask = 7,
2799 .cra_list = LIST_HEAD_INIT(tgr128.cra_list),
2800 .cra_u = {.digest = {
2801 .dia_digestsize = TGR128_DIGEST_SIZE,
2802 Index: linux-2.6.16.50/crypto/wp512.c
2803 ===================================================================
2804 --- linux-2.6.16.50.orig/crypto/wp512.c 2006-07-14 18:09:26.383438750 +1200
2805 +++ linux-2.6.16.50/crypto/wp512.c 2006-07-14 18:10:31.235491750 +1200
2810 -static void wp512_init (void *ctx) {
2811 +static void wp512_init(struct crypto_tfm *tfm) {
2812 + struct wp512_ctx *wctx = crypto_tfm_ctx(tfm);
2814 - struct wp512_ctx *wctx = ctx;
2816 memset(wctx->bitLength, 0, 32);
2817 wctx->bufferBits = wctx->bufferPos = 0;
2818 @@ -993,10 +993,10 @@
2822 -static void wp512_update(void *ctx, const u8 *source, unsigned int len)
2823 +static void wp512_update(struct crypto_tfm *tfm, const u8 *source,
2827 - struct wp512_ctx *wctx = ctx;
2828 + struct wp512_ctx *wctx = crypto_tfm_ctx(tfm);
2830 unsigned int bits_len = len * 8; // convert to number of bits
2831 int sourceGap = (8 - ((int)bits_len & 7)) & 7;
2832 @@ -1054,9 +1054,9 @@
2836 -static void wp512_final(void *ctx, u8 *out)
2837 +static void wp512_final(struct crypto_tfm *tfm, u8 *out)
2839 - struct wp512_ctx *wctx = ctx;
2840 + struct wp512_ctx *wctx = crypto_tfm_ctx(tfm);
2842 u8 *buffer = wctx->buffer;
2843 u8 *bitLength = wctx->bitLength;
2844 @@ -1087,22 +1087,20 @@
2845 wctx->bufferPos = bufferPos;
2848 -static void wp384_final(void *ctx, u8 *out)
2849 +static void wp384_final(struct crypto_tfm *tfm, u8 *out)
2851 - struct wp512_ctx *wctx = ctx;
2854 - wp512_final (wctx, D);
2855 + wp512_final(tfm, D);
2856 memcpy (out, D, WP384_DIGEST_SIZE);
2857 memset (D, 0, WP512_DIGEST_SIZE);
2860 -static void wp256_final(void *ctx, u8 *out)
2861 +static void wp256_final(struct crypto_tfm *tfm, u8 *out)
2863 - struct wp512_ctx *wctx = ctx;
2866 - wp512_final (wctx, D);
2867 + wp512_final(tfm, D);
2868 memcpy (out, D, WP256_DIGEST_SIZE);
2869 memset (D, 0, WP512_DIGEST_SIZE);
2871 Index: linux-2.6.16.50/arch/i386/kernel/cpu/proc.c
2872 ===================================================================
2873 --- linux-2.6.16.50.orig/arch/i386/kernel/cpu/proc.c 2006-07-15 00:03:51.220033250 +1200
2874 +++ linux-2.6.16.50/arch/i386/kernel/cpu/proc.c 2006-07-15 00:04:02.552741500 +1200
2877 /* VIA/Cyrix/Centaur-defined */
2878 NULL, NULL, "rng", "rng_en", NULL, NULL, "ace", "ace_en",
2879 - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2880 + "ace2", "ace2_en", "phe", "phe_en", "pmm", "pmm_en", NULL, NULL,
2881 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2882 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2884 Index: linux-2.6.16.50/include/asm-i386/cpufeature.h
2885 ===================================================================
2886 --- linux-2.6.16.50.orig/include/asm-i386/cpufeature.h 2006-07-15 00:03:51.648060000 +1200
2887 +++ linux-2.6.16.50/include/asm-i386/cpufeature.h 2006-07-15 00:04:02.552741500 +1200
2889 #define X86_FEATURE_XSTORE_EN (5*32+ 3) /* on-CPU RNG enabled */
2890 #define X86_FEATURE_XCRYPT (5*32+ 6) /* on-CPU crypto (xcrypt insn) */
2891 #define X86_FEATURE_XCRYPT_EN (5*32+ 7) /* on-CPU crypto enabled */
2892 +#define X86_FEATURE_ACE2 (5*32+ 8) /* Advanced Cryptography Engine v2 */
2893 +#define X86_FEATURE_ACE2_EN (5*32+ 9) /* ACE v2 enabled */
2894 +#define X86_FEATURE_PHE (5*32+ 10) /* PadLock Hash Engine */
2895 +#define X86_FEATURE_PHE_EN (5*32+ 11) /* PHE enabled */
2896 +#define X86_FEATURE_PMM (5*32+ 12) /* PadLock Montgomery Multiplier */
2897 +#define X86_FEATURE_PMM_EN (5*32+ 13) /* PMM enabled */
2899 /* More extended AMD flags: CPUID level 0x80000001, ecx, word 6 */
2900 #define X86_FEATURE_LAHF_LM (6*32+ 0) /* LAHF/SAHF in long mode */
2901 @@ -119,6 +125,12 @@
2902 #define cpu_has_xstore_enabled boot_cpu_has(X86_FEATURE_XSTORE_EN)
2903 #define cpu_has_xcrypt boot_cpu_has(X86_FEATURE_XCRYPT)
2904 #define cpu_has_xcrypt_enabled boot_cpu_has(X86_FEATURE_XCRYPT_EN)
2905 +#define cpu_has_ace2 boot_cpu_has(X86_FEATURE_ACE2)
2906 +#define cpu_has_ace2_enabled boot_cpu_has(X86_FEATURE_ACE2_EN)
2907 +#define cpu_has_phe boot_cpu_has(X86_FEATURE_PHE)
2908 +#define cpu_has_phe_enabled boot_cpu_has(X86_FEATURE_PHE_EN)
2909 +#define cpu_has_pmm boot_cpu_has(X86_FEATURE_PMM)
2910 +#define cpu_has_pmm_enabled boot_cpu_has(X86_FEATURE_PMM_EN)
2912 #endif /* __ASM_I386_CPUFEATURE_H */