Commit 0f923a2aab7baa94c5fef498384151af1cd72cba
Committed by
Herbert Xu
1 parent
0bea3dc1e2
Exists in
master
and in
7 other branches
[CRYPTO] rmd128: Fix endian problems
This patch is based on Sebastian Siewior's patch and fixes endian issues making rmd128 work properly on big-endian machines. Signed-off-by: Adrian-Ken Rueegsegger <rueegsegger@swiss-it.ch> Acked-by: Sebastian Siewior <sebastian@breakpoint.cc> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Showing 1 changed file with 9 additions and 28 deletions Side-by-side Diff
crypto/rmd128.c
... | ... | @@ -44,7 +44,7 @@ |
44 | 44 | #define F4(x, y, z) (y ^ (z & (x ^ y))) /* z ? x : y */ |
45 | 45 | |
46 | 46 | #define ROUND(a, b, c, d, f, k, x, s) { \ |
47 | - (a) += f((b), (c), (d)) + (x) + (k); \ | |
47 | + (a) += f((b), (c), (d)) + le32_to_cpu(x) + (k); \ | |
48 | 48 | (a) = rol32((a), (s)); \ |
49 | 49 | } |
50 | 50 | |
... | ... | @@ -218,28 +218,6 @@ |
218 | 218 | return; |
219 | 219 | } |
220 | 220 | |
221 | -static inline void le32_to_cpu_array(u32 *buf, unsigned int words) | |
222 | -{ | |
223 | - while (words--) { | |
224 | - le32_to_cpus(buf); | |
225 | - buf++; | |
226 | - } | |
227 | -} | |
228 | - | |
229 | -static inline void cpu_to_le32_array(u32 *buf, unsigned int words) | |
230 | -{ | |
231 | - while (words--) { | |
232 | - cpu_to_le32s(buf); | |
233 | - buf++; | |
234 | - } | |
235 | -} | |
236 | - | |
237 | -static inline void rmd128_transform_helper(struct rmd128_ctx *ctx) | |
238 | -{ | |
239 | - le32_to_cpu_array(ctx->buffer, sizeof(ctx->buffer) / sizeof(u32)); | |
240 | - rmd128_transform(ctx->state, ctx->buffer); | |
241 | -} | |
242 | - | |
243 | 221 | static void rmd128_init(struct crypto_tfm *tfm) |
244 | 222 | { |
245 | 223 | struct rmd128_ctx *rctx = crypto_tfm_ctx(tfm); |
246 | 224 | |
... | ... | @@ -272,13 +250,13 @@ |
272 | 250 | memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail), |
273 | 251 | data, avail); |
274 | 252 | |
275 | - rmd128_transform_helper(rctx); | |
253 | + rmd128_transform(rctx->state, rctx->buffer); | |
276 | 254 | data += avail; |
277 | 255 | len -= avail; |
278 | 256 | |
279 | 257 | while (len >= sizeof(rctx->buffer)) { |
280 | 258 | memcpy(rctx->buffer, data, sizeof(rctx->buffer)); |
281 | - rmd128_transform_helper(rctx); | |
259 | + rmd128_transform(rctx->state, rctx->buffer); | |
282 | 260 | data += sizeof(rctx->buffer); |
283 | 261 | len -= sizeof(rctx->buffer); |
284 | 262 | } |
285 | 263 | |
286 | 264 | |
287 | 265 | |
... | ... | @@ -290,11 +268,13 @@ |
290 | 268 | static void rmd128_final(struct crypto_tfm *tfm, u8 *out) |
291 | 269 | { |
292 | 270 | struct rmd128_ctx *rctx = crypto_tfm_ctx(tfm); |
293 | - u32 index, padlen; | |
271 | + u32 i, index, padlen; | |
294 | 272 | u64 bits; |
273 | + u32 *dst = (u32 *)out; | |
295 | 274 | static const u8 padding[64] = { 0x80, }; |
296 | - bits = rctx->byte_count << 3; | |
297 | 275 | |
276 | + bits = cpu_to_le64(rctx->byte_count << 3); | |
277 | + | |
298 | 278 | /* Pad out to 56 mod 64 */ |
299 | 279 | index = rctx->byte_count & 0x3f; |
300 | 280 | padlen = (index < 56) ? (56 - index) : ((64+56) - index); |
... | ... | @@ -304,7 +284,8 @@ |
304 | 284 | rmd128_update(tfm, (const u8 *)&bits, sizeof(bits)); |
305 | 285 | |
306 | 286 | /* Store state in digest */ |
307 | - memcpy(out, rctx->state, sizeof(rctx->state)); | |
287 | + for (i = 0; i < 4; i++) | |
288 | + dst[i] = cpu_to_le32(rctx->state[i]); | |
308 | 289 | |
309 | 290 | /* Wipe context */ |
310 | 291 | memset(rctx, 0, sizeof(*rctx)); |