aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/michael_mic.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2005-10-30 05:25:15 -0500
committerDavid S. Miller <davem@sunset.davemloft.net>2006-01-09 17:15:34 -0500
commit06ace7a9bafeb9047352707eb79e8eaa0dfdf5f2 (patch)
treefa22bbc2e8ea5bee00b6aec353783144b6f8735a /crypto/michael_mic.c
parent2df15fffc612b53b2c8e4ff3c981a82441bc00ae (diff)
[CRYPTO] Use standard byte order macros wherever possible
A lot of crypto code needs to read/write a 32-bit/64-bit words in a specific gender. Many of them open code them by reading/writing one byte at a time. This patch converts all the applicable usages over to use the standard byte order macros. This is based on a previous patch by Denis Vlasenko. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/michael_mic.c')
-rw-r--r--crypto/michael_mic.c40
1 files changed, 17 insertions, 23 deletions
diff --git a/crypto/michael_mic.c b/crypto/michael_mic.c
index a470bcb3693e..4f6ab23e14ad 100644
--- a/crypto/michael_mic.c
+++ b/crypto/michael_mic.c
@@ -10,10 +10,12 @@
10 * published by the Free Software Foundation. 10 * published by the Free Software Foundation.
11 */ 11 */
12 12
13#include <asm/byteorder.h>
13#include <linux/init.h> 14#include <linux/init.h>
14#include <linux/module.h> 15#include <linux/module.h>
15#include <linux/string.h> 16#include <linux/string.h>
16#include <linux/crypto.h> 17#include <linux/crypto.h>
18#include <linux/types.h>
17 19
18 20
19struct michael_mic_ctx { 21struct michael_mic_ctx {
@@ -43,21 +45,6 @@ do { \
43} while (0) 45} while (0)
44 46
45 47
46static inline u32 get_le32(const u8 *p)
47{
48 return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
49}
50
51
52static inline void put_le32(u8 *p, u32 v)
53{
54 p[0] = v;
55 p[1] = v >> 8;
56 p[2] = v >> 16;
57 p[3] = v >> 24;
58}
59
60
61static void michael_init(void *ctx) 48static void michael_init(void *ctx)
62{ 49{
63 struct michael_mic_ctx *mctx = ctx; 50 struct michael_mic_ctx *mctx = ctx;
@@ -68,6 +55,7 @@ static void michael_init(void *ctx)
68static void michael_update(void *ctx, const u8 *data, unsigned int len) 55static void michael_update(void *ctx, const u8 *data, unsigned int len)
69{ 56{
70 struct michael_mic_ctx *mctx = ctx; 57 struct michael_mic_ctx *mctx = ctx;
58 const __le32 *src;
71 59
72 if (mctx->pending_len) { 60 if (mctx->pending_len) {
73 int flen = 4 - mctx->pending_len; 61 int flen = 4 - mctx->pending_len;
@@ -81,21 +69,23 @@ static void michael_update(void *ctx, const u8 *data, unsigned int len)
81 if (mctx->pending_len < 4) 69 if (mctx->pending_len < 4)
82 return; 70 return;
83 71
84 mctx->l ^= get_le32(mctx->pending); 72 src = (const __le32 *)mctx->pending;
73 mctx->l ^= le32_to_cpup(src);
85 michael_block(mctx->l, mctx->r); 74 michael_block(mctx->l, mctx->r);
86 mctx->pending_len = 0; 75 mctx->pending_len = 0;
87 } 76 }
88 77
78 src = (const __le32 *)data;
79
89 while (len >= 4) { 80 while (len >= 4) {
90 mctx->l ^= get_le32(data); 81 mctx->l ^= le32_to_cpup(src++);
91 michael_block(mctx->l, mctx->r); 82 michael_block(mctx->l, mctx->r);
92 data += 4;
93 len -= 4; 83 len -= 4;
94 } 84 }
95 85
96 if (len > 0) { 86 if (len > 0) {
97 mctx->pending_len = len; 87 mctx->pending_len = len;
98 memcpy(mctx->pending, data, len); 88 memcpy(mctx->pending, src, len);
99 } 89 }
100} 90}
101 91
@@ -104,6 +94,7 @@ static void michael_final(void *ctx, u8 *out)
104{ 94{
105 struct michael_mic_ctx *mctx = ctx; 95 struct michael_mic_ctx *mctx = ctx;
106 u8 *data = mctx->pending; 96 u8 *data = mctx->pending;
97 __le32 *dst = (__le32 *)out;
107 98
108 /* Last block and padding (0x5a, 4..7 x 0) */ 99 /* Last block and padding (0x5a, 4..7 x 0) */
109 switch (mctx->pending_len) { 100 switch (mctx->pending_len) {
@@ -125,8 +116,8 @@ static void michael_final(void *ctx, u8 *out)
125 /* l ^= 0; */ 116 /* l ^= 0; */
126 michael_block(mctx->l, mctx->r); 117 michael_block(mctx->l, mctx->r);
127 118
128 put_le32(out, mctx->l); 119 dst[0] = cpu_to_le32(mctx->l);
129 put_le32(out + 4, mctx->r); 120 dst[1] = cpu_to_le32(mctx->r);
130} 121}
131 122
132 123
@@ -134,13 +125,16 @@ static int michael_setkey(void *ctx, const u8 *key, unsigned int keylen,
134 u32 *flags) 125 u32 *flags)
135{ 126{
136 struct michael_mic_ctx *mctx = ctx; 127 struct michael_mic_ctx *mctx = ctx;
128 const __le32 *data = (const __le32 *)key;
129
137 if (keylen != 8) { 130 if (keylen != 8) {
138 if (flags) 131 if (flags)
139 *flags = CRYPTO_TFM_RES_BAD_KEY_LEN; 132 *flags = CRYPTO_TFM_RES_BAD_KEY_LEN;
140 return -EINVAL; 133 return -EINVAL;
141 } 134 }
142 mctx->l = get_le32(key); 135
143 mctx->r = get_le32(key + 4); 136 mctx->l = le32_to_cpu(data[0]);
137 mctx->r = le32_to_cpu(data[1]);
144 return 0; 138 return 0;
145} 139}
146 140