diff options
author | Linus Torvalds <torvalds@g5.osdl.org> | 2006-01-09 18:12:52 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-01-09 18:12:52 -0500 |
commit | 1fd5a46dd6bbca3a1275465120caf4748872c2a7 (patch) | |
tree | c24862a43f57974394ebb58a1d9005e4093e3bf7 /arch | |
parent | 2cc6055060d975e8c7601f4a1c68ef2d3050b4e9 (diff) | |
parent | dff2c03534f525813342ab8dec90c5bb1ee07471 (diff) |
Merge master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
Diffstat (limited to 'arch')
-rw-r--r-- | arch/i386/crypto/aes-i586-asm.S | 40 | ||||
-rw-r--r-- | arch/i386/crypto/aes.c | 56 | ||||
-rw-r--r-- | arch/x86_64/crypto/aes.c | 25 |
3 files changed, 57 insertions, 64 deletions
diff --git a/arch/i386/crypto/aes-i586-asm.S b/arch/i386/crypto/aes-i586-asm.S index 7b73c67cb4e8..911b15377f2e 100644 --- a/arch/i386/crypto/aes-i586-asm.S +++ b/arch/i386/crypto/aes-i586-asm.S | |||
@@ -255,18 +255,17 @@ aes_enc_blk: | |||
255 | xor 8(%ebp),%r4 | 255 | xor 8(%ebp),%r4 |
256 | xor 12(%ebp),%r5 | 256 | xor 12(%ebp),%r5 |
257 | 257 | ||
258 | sub $8,%esp // space for register saves on stack | 258 | sub $8,%esp // space for register saves on stack |
259 | add $16,%ebp // increment to next round key | 259 | add $16,%ebp // increment to next round key |
260 | sub $10,%r3 | 260 | cmp $12,%r3 |
261 | je 4f // 10 rounds for 128-bit key | 261 | jb 4f // 10 rounds for 128-bit key |
262 | add $32,%ebp | 262 | lea 32(%ebp),%ebp |
263 | sub $2,%r3 | 263 | je 3f // 12 rounds for 192-bit key |
264 | je 3f // 12 rounds for 128-bit key | 264 | lea 32(%ebp),%ebp |
265 | add $32,%ebp | 265 | |
266 | 266 | 2: fwd_rnd1( -64(%ebp) ,ft_tab) // 14 rounds for 256-bit key | |
267 | 2: fwd_rnd1( -64(%ebp) ,ft_tab) // 14 rounds for 128-bit key | ||
268 | fwd_rnd2( -48(%ebp) ,ft_tab) | 267 | fwd_rnd2( -48(%ebp) ,ft_tab) |
269 | 3: fwd_rnd1( -32(%ebp) ,ft_tab) // 12 rounds for 128-bit key | 268 | 3: fwd_rnd1( -32(%ebp) ,ft_tab) // 12 rounds for 192-bit key |
270 | fwd_rnd2( -16(%ebp) ,ft_tab) | 269 | fwd_rnd2( -16(%ebp) ,ft_tab) |
271 | 4: fwd_rnd1( (%ebp) ,ft_tab) // 10 rounds for 128-bit key | 270 | 4: fwd_rnd1( (%ebp) ,ft_tab) // 10 rounds for 128-bit key |
272 | fwd_rnd2( +16(%ebp) ,ft_tab) | 271 | fwd_rnd2( +16(%ebp) ,ft_tab) |
@@ -334,18 +333,17 @@ aes_dec_blk: | |||
334 | xor 8(%ebp),%r4 | 333 | xor 8(%ebp),%r4 |
335 | xor 12(%ebp),%r5 | 334 | xor 12(%ebp),%r5 |
336 | 335 | ||
337 | sub $8,%esp // space for register saves on stack | 336 | sub $8,%esp // space for register saves on stack |
338 | sub $16,%ebp // increment to next round key | 337 | sub $16,%ebp // increment to next round key |
339 | sub $10,%r3 | 338 | cmp $12,%r3 |
340 | je 4f // 10 rounds for 128-bit key | 339 | jb 4f // 10 rounds for 128-bit key |
341 | sub $32,%ebp | 340 | lea -32(%ebp),%ebp |
342 | sub $2,%r3 | 341 | je 3f // 12 rounds for 192-bit key |
343 | je 3f // 12 rounds for 128-bit key | 342 | lea -32(%ebp),%ebp |
344 | sub $32,%ebp | ||
345 | 343 | ||
346 | 2: inv_rnd1( +64(%ebp), it_tab) // 14 rounds for 128-bit key | 344 | 2: inv_rnd1( +64(%ebp), it_tab) // 14 rounds for 256-bit key |
347 | inv_rnd2( +48(%ebp), it_tab) | 345 | inv_rnd2( +48(%ebp), it_tab) |
348 | 3: inv_rnd1( +32(%ebp), it_tab) // 12 rounds for 128-bit key | 346 | 3: inv_rnd1( +32(%ebp), it_tab) // 12 rounds for 192-bit key |
349 | inv_rnd2( +16(%ebp), it_tab) | 347 | inv_rnd2( +16(%ebp), it_tab) |
350 | 4: inv_rnd1( (%ebp), it_tab) // 10 rounds for 128-bit key | 348 | 4: inv_rnd1( (%ebp), it_tab) // 10 rounds for 128-bit key |
351 | inv_rnd2( -16(%ebp), it_tab) | 349 | inv_rnd2( -16(%ebp), it_tab) |
diff --git a/arch/i386/crypto/aes.c b/arch/i386/crypto/aes.c index 88ee85c3b43b..a50397b1d5c7 100644 --- a/arch/i386/crypto/aes.c +++ b/arch/i386/crypto/aes.c | |||
@@ -36,6 +36,8 @@ | |||
36 | * Copyright (c) 2004 Red Hat, Inc., James Morris <jmorris@redhat.com> | 36 | * Copyright (c) 2004 Red Hat, Inc., James Morris <jmorris@redhat.com> |
37 | * | 37 | * |
38 | */ | 38 | */ |
39 | |||
40 | #include <asm/byteorder.h> | ||
39 | #include <linux/kernel.h> | 41 | #include <linux/kernel.h> |
40 | #include <linux/module.h> | 42 | #include <linux/module.h> |
41 | #include <linux/init.h> | 43 | #include <linux/init.h> |
@@ -59,7 +61,6 @@ struct aes_ctx { | |||
59 | }; | 61 | }; |
60 | 62 | ||
61 | #define WPOLY 0x011b | 63 | #define WPOLY 0x011b |
62 | #define u32_in(x) le32_to_cpup((const __le32 *)(x)) | ||
63 | #define bytes2word(b0, b1, b2, b3) \ | 64 | #define bytes2word(b0, b1, b2, b3) \ |
64 | (((u32)(b3) << 24) | ((u32)(b2) << 16) | ((u32)(b1) << 8) | (b0)) | 65 | (((u32)(b3) << 24) | ((u32)(b2) << 16) | ((u32)(b1) << 8) | (b0)) |
65 | 66 | ||
@@ -93,7 +94,6 @@ static u32 rcon_tab[RC_LENGTH]; | |||
93 | 94 | ||
94 | u32 ft_tab[4][256]; | 95 | u32 ft_tab[4][256]; |
95 | u32 fl_tab[4][256]; | 96 | u32 fl_tab[4][256]; |
96 | static u32 ls_tab[4][256]; | ||
97 | static u32 im_tab[4][256]; | 97 | static u32 im_tab[4][256]; |
98 | u32 il_tab[4][256]; | 98 | u32 il_tab[4][256]; |
99 | u32 it_tab[4][256]; | 99 | u32 it_tab[4][256]; |
@@ -144,15 +144,6 @@ static void gen_tabs(void) | |||
144 | fl_tab[2][i] = upr(w, 2); | 144 | fl_tab[2][i] = upr(w, 2); |
145 | fl_tab[3][i] = upr(w, 3); | 145 | fl_tab[3][i] = upr(w, 3); |
146 | 146 | ||
147 | /* | ||
148 | * table for key schedule if fl_tab above is | ||
149 | * not of the required form | ||
150 | */ | ||
151 | ls_tab[0][i] = w; | ||
152 | ls_tab[1][i] = upr(w, 1); | ||
153 | ls_tab[2][i] = upr(w, 2); | ||
154 | ls_tab[3][i] = upr(w, 3); | ||
155 | |||
156 | b = fi(inv_affine((u8)i)); | 147 | b = fi(inv_affine((u8)i)); |
157 | w = bytes2word(fe(b), f9(b), fd(b), fb(b)); | 148 | w = bytes2word(fe(b), f9(b), fd(b), fb(b)); |
158 | 149 | ||
@@ -393,13 +384,14 @@ aes_set_key(void *ctx_arg, const u8 *in_key, unsigned int key_len, u32 *flags) | |||
393 | int i; | 384 | int i; |
394 | u32 ss[8]; | 385 | u32 ss[8]; |
395 | struct aes_ctx *ctx = ctx_arg; | 386 | struct aes_ctx *ctx = ctx_arg; |
387 | const __le32 *key = (const __le32 *)in_key; | ||
396 | 388 | ||
397 | /* encryption schedule */ | 389 | /* encryption schedule */ |
398 | 390 | ||
399 | ctx->ekey[0] = ss[0] = u32_in(in_key); | 391 | ctx->ekey[0] = ss[0] = le32_to_cpu(key[0]); |
400 | ctx->ekey[1] = ss[1] = u32_in(in_key + 4); | 392 | ctx->ekey[1] = ss[1] = le32_to_cpu(key[1]); |
401 | ctx->ekey[2] = ss[2] = u32_in(in_key + 8); | 393 | ctx->ekey[2] = ss[2] = le32_to_cpu(key[2]); |
402 | ctx->ekey[3] = ss[3] = u32_in(in_key + 12); | 394 | ctx->ekey[3] = ss[3] = le32_to_cpu(key[3]); |
403 | 395 | ||
404 | switch(key_len) { | 396 | switch(key_len) { |
405 | case 16: | 397 | case 16: |
@@ -410,8 +402,8 @@ aes_set_key(void *ctx_arg, const u8 *in_key, unsigned int key_len, u32 *flags) | |||
410 | break; | 402 | break; |
411 | 403 | ||
412 | case 24: | 404 | case 24: |
413 | ctx->ekey[4] = ss[4] = u32_in(in_key + 16); | 405 | ctx->ekey[4] = ss[4] = le32_to_cpu(key[4]); |
414 | ctx->ekey[5] = ss[5] = u32_in(in_key + 20); | 406 | ctx->ekey[5] = ss[5] = le32_to_cpu(key[5]); |
415 | for (i = 0; i < 7; i++) | 407 | for (i = 0; i < 7; i++) |
416 | ke6(ctx->ekey, i); | 408 | ke6(ctx->ekey, i); |
417 | kel6(ctx->ekey, 7); | 409 | kel6(ctx->ekey, 7); |
@@ -419,10 +411,10 @@ aes_set_key(void *ctx_arg, const u8 *in_key, unsigned int key_len, u32 *flags) | |||
419 | break; | 411 | break; |
420 | 412 | ||
421 | case 32: | 413 | case 32: |
422 | ctx->ekey[4] = ss[4] = u32_in(in_key + 16); | 414 | ctx->ekey[4] = ss[4] = le32_to_cpu(key[4]); |
423 | ctx->ekey[5] = ss[5] = u32_in(in_key + 20); | 415 | ctx->ekey[5] = ss[5] = le32_to_cpu(key[5]); |
424 | ctx->ekey[6] = ss[6] = u32_in(in_key + 24); | 416 | ctx->ekey[6] = ss[6] = le32_to_cpu(key[6]); |
425 | ctx->ekey[7] = ss[7] = u32_in(in_key + 28); | 417 | ctx->ekey[7] = ss[7] = le32_to_cpu(key[7]); |
426 | for (i = 0; i < 6; i++) | 418 | for (i = 0; i < 6; i++) |
427 | ke8(ctx->ekey, i); | 419 | ke8(ctx->ekey, i); |
428 | kel8(ctx->ekey, 6); | 420 | kel8(ctx->ekey, 6); |
@@ -436,10 +428,10 @@ aes_set_key(void *ctx_arg, const u8 *in_key, unsigned int key_len, u32 *flags) | |||
436 | 428 | ||
437 | /* decryption schedule */ | 429 | /* decryption schedule */ |
438 | 430 | ||
439 | ctx->dkey[0] = ss[0] = u32_in(in_key); | 431 | ctx->dkey[0] = ss[0] = le32_to_cpu(key[0]); |
440 | ctx->dkey[1] = ss[1] = u32_in(in_key + 4); | 432 | ctx->dkey[1] = ss[1] = le32_to_cpu(key[1]); |
441 | ctx->dkey[2] = ss[2] = u32_in(in_key + 8); | 433 | ctx->dkey[2] = ss[2] = le32_to_cpu(key[2]); |
442 | ctx->dkey[3] = ss[3] = u32_in(in_key + 12); | 434 | ctx->dkey[3] = ss[3] = le32_to_cpu(key[3]); |
443 | 435 | ||
444 | switch (key_len) { | 436 | switch (key_len) { |
445 | case 16: | 437 | case 16: |
@@ -450,8 +442,8 @@ aes_set_key(void *ctx_arg, const u8 *in_key, unsigned int key_len, u32 *flags) | |||
450 | break; | 442 | break; |
451 | 443 | ||
452 | case 24: | 444 | case 24: |
453 | ctx->dkey[4] = ff(ss[4] = u32_in(in_key + 16)); | 445 | ctx->dkey[4] = ff(ss[4] = le32_to_cpu(key[4])); |
454 | ctx->dkey[5] = ff(ss[5] = u32_in(in_key + 20)); | 446 | ctx->dkey[5] = ff(ss[5] = le32_to_cpu(key[5])); |
455 | kdf6(ctx->dkey, 0); | 447 | kdf6(ctx->dkey, 0); |
456 | for (i = 1; i < 7; i++) | 448 | for (i = 1; i < 7; i++) |
457 | kd6(ctx->dkey, i); | 449 | kd6(ctx->dkey, i); |
@@ -459,10 +451,10 @@ aes_set_key(void *ctx_arg, const u8 *in_key, unsigned int key_len, u32 *flags) | |||
459 | break; | 451 | break; |
460 | 452 | ||
461 | case 32: | 453 | case 32: |
462 | ctx->dkey[4] = ff(ss[4] = u32_in(in_key + 16)); | 454 | ctx->dkey[4] = ff(ss[4] = le32_to_cpu(key[4])); |
463 | ctx->dkey[5] = ff(ss[5] = u32_in(in_key + 20)); | 455 | ctx->dkey[5] = ff(ss[5] = le32_to_cpu(key[5])); |
464 | ctx->dkey[6] = ff(ss[6] = u32_in(in_key + 24)); | 456 | ctx->dkey[6] = ff(ss[6] = le32_to_cpu(key[6])); |
465 | ctx->dkey[7] = ff(ss[7] = u32_in(in_key + 28)); | 457 | ctx->dkey[7] = ff(ss[7] = le32_to_cpu(key[7])); |
466 | kdf8(ctx->dkey, 0); | 458 | kdf8(ctx->dkey, 0); |
467 | for (i = 1; i < 6; i++) | 459 | for (i = 1; i < 6; i++) |
468 | kd8(ctx->dkey, i); | 460 | kd8(ctx->dkey, i); |
@@ -484,6 +476,8 @@ static inline void aes_decrypt(void *ctx, u8 *dst, const u8 *src) | |||
484 | 476 | ||
485 | static struct crypto_alg aes_alg = { | 477 | static struct crypto_alg aes_alg = { |
486 | .cra_name = "aes", | 478 | .cra_name = "aes", |
479 | .cra_driver_name = "aes-i586", | ||
480 | .cra_priority = 200, | ||
487 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, | 481 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, |
488 | .cra_blocksize = AES_BLOCK_SIZE, | 482 | .cra_blocksize = AES_BLOCK_SIZE, |
489 | .cra_ctxsize = sizeof(struct aes_ctx), | 483 | .cra_ctxsize = sizeof(struct aes_ctx), |
diff --git a/arch/x86_64/crypto/aes.c b/arch/x86_64/crypto/aes.c index acfdaa28791e..fb1b961a2e2f 100644 --- a/arch/x86_64/crypto/aes.c +++ b/arch/x86_64/crypto/aes.c | |||
@@ -74,8 +74,6 @@ static inline u8 byte(const u32 x, const unsigned n) | |||
74 | return x >> (n << 3); | 74 | return x >> (n << 3); |
75 | } | 75 | } |
76 | 76 | ||
77 | #define u32_in(x) le32_to_cpu(*(const __le32 *)(x)) | ||
78 | |||
79 | struct aes_ctx | 77 | struct aes_ctx |
80 | { | 78 | { |
81 | u32 key_length; | 79 | u32 key_length; |
@@ -234,6 +232,7 @@ static int aes_set_key(void *ctx_arg, const u8 *in_key, unsigned int key_len, | |||
234 | u32 *flags) | 232 | u32 *flags) |
235 | { | 233 | { |
236 | struct aes_ctx *ctx = ctx_arg; | 234 | struct aes_ctx *ctx = ctx_arg; |
235 | const __le32 *key = (const __le32 *)in_key; | ||
237 | u32 i, j, t, u, v, w; | 236 | u32 i, j, t, u, v, w; |
238 | 237 | ||
239 | if (key_len != 16 && key_len != 24 && key_len != 32) { | 238 | if (key_len != 16 && key_len != 24 && key_len != 32) { |
@@ -243,10 +242,10 @@ static int aes_set_key(void *ctx_arg, const u8 *in_key, unsigned int key_len, | |||
243 | 242 | ||
244 | ctx->key_length = key_len; | 243 | ctx->key_length = key_len; |
245 | 244 | ||
246 | D_KEY[key_len + 24] = E_KEY[0] = u32_in(in_key); | 245 | D_KEY[key_len + 24] = E_KEY[0] = le32_to_cpu(key[0]); |
247 | D_KEY[key_len + 25] = E_KEY[1] = u32_in(in_key + 4); | 246 | D_KEY[key_len + 25] = E_KEY[1] = le32_to_cpu(key[1]); |
248 | D_KEY[key_len + 26] = E_KEY[2] = u32_in(in_key + 8); | 247 | D_KEY[key_len + 26] = E_KEY[2] = le32_to_cpu(key[2]); |
249 | D_KEY[key_len + 27] = E_KEY[3] = u32_in(in_key + 12); | 248 | D_KEY[key_len + 27] = E_KEY[3] = le32_to_cpu(key[3]); |
250 | 249 | ||
251 | switch (key_len) { | 250 | switch (key_len) { |
252 | case 16: | 251 | case 16: |
@@ -256,17 +255,17 @@ static int aes_set_key(void *ctx_arg, const u8 *in_key, unsigned int key_len, | |||
256 | break; | 255 | break; |
257 | 256 | ||
258 | case 24: | 257 | case 24: |
259 | E_KEY[4] = u32_in(in_key + 16); | 258 | E_KEY[4] = le32_to_cpu(key[4]); |
260 | t = E_KEY[5] = u32_in(in_key + 20); | 259 | t = E_KEY[5] = le32_to_cpu(key[5]); |
261 | for (i = 0; i < 8; ++i) | 260 | for (i = 0; i < 8; ++i) |
262 | loop6 (i); | 261 | loop6 (i); |
263 | break; | 262 | break; |
264 | 263 | ||
265 | case 32: | 264 | case 32: |
266 | E_KEY[4] = u32_in(in_key + 16); | 265 | E_KEY[4] = le32_to_cpu(key[4]); |
267 | E_KEY[5] = u32_in(in_key + 20); | 266 | E_KEY[5] = le32_to_cpu(key[5]); |
268 | E_KEY[6] = u32_in(in_key + 24); | 267 | E_KEY[6] = le32_to_cpu(key[6]); |
269 | t = E_KEY[7] = u32_in(in_key + 28); | 268 | t = E_KEY[7] = le32_to_cpu(key[7]); |
270 | for (i = 0; i < 7; ++i) | 269 | for (i = 0; i < 7; ++i) |
271 | loop8(i); | 270 | loop8(i); |
272 | break; | 271 | break; |
@@ -290,6 +289,8 @@ extern void aes_decrypt(void *ctx_arg, u8 *out, const u8 *in); | |||
290 | 289 | ||
291 | static struct crypto_alg aes_alg = { | 290 | static struct crypto_alg aes_alg = { |
292 | .cra_name = "aes", | 291 | .cra_name = "aes", |
292 | .cra_driver_name = "aes-x86_64", | ||
293 | .cra_priority = 200, | ||
293 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, | 294 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, |
294 | .cra_blocksize = AES_BLOCK_SIZE, | 295 | .cra_blocksize = AES_BLOCK_SIZE, |
295 | .cra_ctxsize = sizeof(struct aes_ctx), | 296 | .cra_ctxsize = sizeof(struct aes_ctx), |