diff options
Diffstat (limited to 'arch/i386/crypto/aes.c')
-rw-r--r-- | arch/i386/crypto/aes.c | 56 |
1 files changed, 25 insertions, 31 deletions
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), |