diff options
Diffstat (limited to 'crypto/cast5.c')
| -rw-r--r-- | crypto/cast5.c | 47 |
1 files changed, 20 insertions, 27 deletions
diff --git a/crypto/cast5.c b/crypto/cast5.c index bc42f42b4fe3..8834c8580c04 100644 --- a/crypto/cast5.c +++ b/crypto/cast5.c | |||
| @@ -21,11 +21,13 @@ | |||
| 21 | */ | 21 | */ |
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | #include <asm/byteorder.h> | ||
| 24 | #include <linux/init.h> | 25 | #include <linux/init.h> |
| 25 | #include <linux/crypto.h> | 26 | #include <linux/crypto.h> |
| 26 | #include <linux/module.h> | 27 | #include <linux/module.h> |
| 27 | #include <linux/errno.h> | 28 | #include <linux/errno.h> |
| 28 | #include <linux/string.h> | 29 | #include <linux/string.h> |
| 30 | #include <linux/types.h> | ||
| 29 | 31 | ||
| 30 | #define CAST5_BLOCK_SIZE 8 | 32 | #define CAST5_BLOCK_SIZE 8 |
| 31 | #define CAST5_MIN_KEY_SIZE 5 | 33 | #define CAST5_MIN_KEY_SIZE 5 |
| @@ -578,6 +580,8 @@ static const u32 sb8[256] = { | |||
| 578 | static void cast5_encrypt(void *ctx, u8 * outbuf, const u8 * inbuf) | 580 | static void cast5_encrypt(void *ctx, u8 * outbuf, const u8 * inbuf) |
| 579 | { | 581 | { |
| 580 | struct cast5_ctx *c = (struct cast5_ctx *) ctx; | 582 | struct cast5_ctx *c = (struct cast5_ctx *) ctx; |
| 583 | const __be32 *src = (const __be32 *)inbuf; | ||
| 584 | __be32 *dst = (__be32 *)outbuf; | ||
| 581 | u32 l, r, t; | 585 | u32 l, r, t; |
| 582 | u32 I; /* used by the Fx macros */ | 586 | u32 I; /* used by the Fx macros */ |
| 583 | u32 *Km; | 587 | u32 *Km; |
| @@ -589,8 +593,8 @@ static void cast5_encrypt(void *ctx, u8 * outbuf, const u8 * inbuf) | |||
| 589 | /* (L0,R0) <-- (m1...m64). (Split the plaintext into left and | 593 | /* (L0,R0) <-- (m1...m64). (Split the plaintext into left and |
| 590 | * right 32-bit halves L0 = m1...m32 and R0 = m33...m64.) | 594 | * right 32-bit halves L0 = m1...m32 and R0 = m33...m64.) |
| 591 | */ | 595 | */ |
| 592 | l = inbuf[0] << 24 | inbuf[1] << 16 | inbuf[2] << 8 | inbuf[3]; | 596 | l = be32_to_cpu(src[0]); |
| 593 | r = inbuf[4] << 24 | inbuf[5] << 16 | inbuf[6] << 8 | inbuf[7]; | 597 | r = be32_to_cpu(src[1]); |
| 594 | 598 | ||
| 595 | /* (16 rounds) for i from 1 to 16, compute Li and Ri as follows: | 599 | /* (16 rounds) for i from 1 to 16, compute Li and Ri as follows: |
| 596 | * Li = Ri-1; | 600 | * Li = Ri-1; |
| @@ -634,19 +638,15 @@ static void cast5_encrypt(void *ctx, u8 * outbuf, const u8 * inbuf) | |||
| 634 | 638 | ||
| 635 | /* c1...c64 <-- (R16,L16). (Exchange final blocks L16, R16 and | 639 | /* c1...c64 <-- (R16,L16). (Exchange final blocks L16, R16 and |
| 636 | * concatenate to form the ciphertext.) */ | 640 | * concatenate to form the ciphertext.) */ |
| 637 | outbuf[0] = (r >> 24) & 0xff; | 641 | dst[0] = cpu_to_be32(r); |
| 638 | outbuf[1] = (r >> 16) & 0xff; | 642 | dst[1] = cpu_to_be32(l); |
| 639 | outbuf[2] = (r >> 8) & 0xff; | ||
| 640 | outbuf[3] = r & 0xff; | ||
| 641 | outbuf[4] = (l >> 24) & 0xff; | ||
| 642 | outbuf[5] = (l >> 16) & 0xff; | ||
| 643 | outbuf[6] = (l >> 8) & 0xff; | ||
| 644 | outbuf[7] = l & 0xff; | ||
| 645 | } | 643 | } |
| 646 | 644 | ||
| 647 | static void cast5_decrypt(void *ctx, u8 * outbuf, const u8 * inbuf) | 645 | static void cast5_decrypt(void *ctx, u8 * outbuf, const u8 * inbuf) |
| 648 | { | 646 | { |
| 649 | struct cast5_ctx *c = (struct cast5_ctx *) ctx; | 647 | struct cast5_ctx *c = (struct cast5_ctx *) ctx; |
| 648 | const __be32 *src = (const __be32 *)inbuf; | ||
| 649 | __be32 *dst = (__be32 *)outbuf; | ||
| 650 | u32 l, r, t; | 650 | u32 l, r, t; |
| 651 | u32 I; | 651 | u32 I; |
| 652 | u32 *Km; | 652 | u32 *Km; |
| @@ -655,8 +655,8 @@ static void cast5_decrypt(void *ctx, u8 * outbuf, const u8 * inbuf) | |||
| 655 | Km = c->Km; | 655 | Km = c->Km; |
| 656 | Kr = c->Kr; | 656 | Kr = c->Kr; |
| 657 | 657 | ||
| 658 | l = inbuf[0] << 24 | inbuf[1] << 16 | inbuf[2] << 8 | inbuf[3]; | 658 | l = be32_to_cpu(src[0]); |
| 659 | r = inbuf[4] << 24 | inbuf[5] << 16 | inbuf[6] << 8 | inbuf[7]; | 659 | r = be32_to_cpu(src[1]); |
| 660 | 660 | ||
| 661 | if (!(c->rr)) { | 661 | if (!(c->rr)) { |
| 662 | t = l; l = r; r = t ^ F1(r, Km[15], Kr[15]); | 662 | t = l; l = r; r = t ^ F1(r, Km[15], Kr[15]); |
| @@ -690,14 +690,8 @@ static void cast5_decrypt(void *ctx, u8 * outbuf, const u8 * inbuf) | |||
| 690 | t = l; l = r; r = t ^ F1(r, Km[0], Kr[0]); | 690 | t = l; l = r; r = t ^ F1(r, Km[0], Kr[0]); |
| 691 | } | 691 | } |
| 692 | 692 | ||
| 693 | outbuf[0] = (r >> 24) & 0xff; | 693 | dst[0] = cpu_to_be32(r); |
| 694 | outbuf[1] = (r >> 16) & 0xff; | 694 | dst[1] = cpu_to_be32(l); |
| 695 | outbuf[2] = (r >> 8) & 0xff; | ||
| 696 | outbuf[3] = r & 0xff; | ||
| 697 | outbuf[4] = (l >> 24) & 0xff; | ||
| 698 | outbuf[5] = (l >> 16) & 0xff; | ||
| 699 | outbuf[6] = (l >> 8) & 0xff; | ||
| 700 | outbuf[7] = l & 0xff; | ||
| 701 | } | 695 | } |
| 702 | 696 | ||
| 703 | static void key_schedule(u32 * x, u32 * z, u32 * k) | 697 | static void key_schedule(u32 * x, u32 * z, u32 * k) |
| @@ -782,7 +776,7 @@ cast5_setkey(void *ctx, const u8 * key, unsigned key_len, u32 * flags) | |||
| 782 | u32 x[4]; | 776 | u32 x[4]; |
| 783 | u32 z[4]; | 777 | u32 z[4]; |
| 784 | u32 k[16]; | 778 | u32 k[16]; |
| 785 | u8 p_key[16]; | 779 | __be32 p_key[4]; |
| 786 | struct cast5_ctx *c = (struct cast5_ctx *) ctx; | 780 | struct cast5_ctx *c = (struct cast5_ctx *) ctx; |
| 787 | 781 | ||
| 788 | if (key_len < 5 || key_len > 16) { | 782 | if (key_len < 5 || key_len > 16) { |
| @@ -796,12 +790,10 @@ cast5_setkey(void *ctx, const u8 * key, unsigned key_len, u32 * flags) | |||
| 796 | memcpy(p_key, key, key_len); | 790 | memcpy(p_key, key, key_len); |
| 797 | 791 | ||
| 798 | 792 | ||
| 799 | x[0] = p_key[0] << 24 | p_key[1] << 16 | p_key[2] << 8 | p_key[3]; | 793 | x[0] = be32_to_cpu(p_key[0]); |
| 800 | x[1] = p_key[4] << 24 | p_key[5] << 16 | p_key[6] << 8 | p_key[7]; | 794 | x[1] = be32_to_cpu(p_key[1]); |
| 801 | x[2] = | 795 | x[2] = be32_to_cpu(p_key[2]); |
| 802 | p_key[8] << 24 | p_key[9] << 16 | p_key[10] << 8 | p_key[11]; | 796 | x[3] = be32_to_cpu(p_key[3]); |
| 803 | x[3] = | ||
| 804 | p_key[12] << 24 | p_key[13] << 16 | p_key[14] << 8 | p_key[15]; | ||
| 805 | 797 | ||
| 806 | key_schedule(x, z, k); | 798 | key_schedule(x, z, k); |
| 807 | for (i = 0; i < 16; i++) | 799 | for (i = 0; i < 16; i++) |
| @@ -817,6 +809,7 @@ static struct crypto_alg alg = { | |||
| 817 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, | 809 | .cra_flags = CRYPTO_ALG_TYPE_CIPHER, |
| 818 | .cra_blocksize = CAST5_BLOCK_SIZE, | 810 | .cra_blocksize = CAST5_BLOCK_SIZE, |
| 819 | .cra_ctxsize = sizeof(struct cast5_ctx), | 811 | .cra_ctxsize = sizeof(struct cast5_ctx), |
| 812 | .cra_alignmask = 3, | ||
| 820 | .cra_module = THIS_MODULE, | 813 | .cra_module = THIS_MODULE, |
| 821 | .cra_list = LIST_HEAD_INIT(alg.cra_list), | 814 | .cra_list = LIST_HEAD_INIT(alg.cra_list), |
| 822 | .cra_u = { | 815 | .cra_u = { |
