Commit 2952ff1a598ce300c911d00d82872d00ca8b61ca
Committed by
Herbert Xu
1 parent
c928a0cddd
Exists in
master
and in
7 other branches
[CRYPTO] rmd256: Fix endian issues
This patch fixes endian issues making rmd256 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/rmd256.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 | |
... | ... | @@ -233,28 +233,6 @@ |
233 | 233 | return; |
234 | 234 | } |
235 | 235 | |
236 | -static inline void le32_to_cpu_array(u32 *buf, unsigned int words) | |
237 | -{ | |
238 | - while (words--) { | |
239 | - le32_to_cpus(buf); | |
240 | - buf++; | |
241 | - } | |
242 | -} | |
243 | - | |
244 | -static inline void cpu_to_le32_array(u32 *buf, unsigned int words) | |
245 | -{ | |
246 | - while (words--) { | |
247 | - cpu_to_le32s(buf); | |
248 | - buf++; | |
249 | - } | |
250 | -} | |
251 | - | |
252 | -static inline void rmd256_transform_helper(struct rmd256_ctx *ctx) | |
253 | -{ | |
254 | - le32_to_cpu_array(ctx->buffer, sizeof(ctx->buffer) / sizeof(u32)); | |
255 | - rmd256_transform(ctx->state, ctx->buffer); | |
256 | -} | |
257 | - | |
258 | 236 | static void rmd256_init(struct crypto_tfm *tfm) |
259 | 237 | { |
260 | 238 | struct rmd256_ctx *rctx = crypto_tfm_ctx(tfm); |
261 | 239 | |
... | ... | @@ -291,13 +269,13 @@ |
291 | 269 | memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail), |
292 | 270 | data, avail); |
293 | 271 | |
294 | - rmd256_transform_helper(rctx); | |
272 | + rmd256_transform(rctx->state, rctx->buffer); | |
295 | 273 | data += avail; |
296 | 274 | len -= avail; |
297 | 275 | |
298 | 276 | while (len >= sizeof(rctx->buffer)) { |
299 | 277 | memcpy(rctx->buffer, data, sizeof(rctx->buffer)); |
300 | - rmd256_transform_helper(rctx); | |
278 | + rmd256_transform(rctx->state, rctx->buffer); | |
301 | 279 | data += sizeof(rctx->buffer); |
302 | 280 | len -= sizeof(rctx->buffer); |
303 | 281 | } |
304 | 282 | |
305 | 283 | |
306 | 284 | |
... | ... | @@ -309,11 +287,13 @@ |
309 | 287 | static void rmd256_final(struct crypto_tfm *tfm, u8 *out) |
310 | 288 | { |
311 | 289 | struct rmd256_ctx *rctx = crypto_tfm_ctx(tfm); |
312 | - u32 index, padlen; | |
290 | + u32 i, index, padlen; | |
313 | 291 | u64 bits; |
292 | + u32 *dst = (u32 *)out; | |
314 | 293 | static const u8 padding[64] = { 0x80, }; |
315 | - bits = rctx->byte_count << 3; | |
316 | 294 | |
295 | + bits = cpu_to_le64(rctx->byte_count << 3); | |
296 | + | |
317 | 297 | /* Pad out to 56 mod 64 */ |
318 | 298 | index = rctx->byte_count & 0x3f; |
319 | 299 | padlen = (index < 56) ? (56 - index) : ((64+56) - index); |
... | ... | @@ -323,7 +303,8 @@ |
323 | 303 | rmd256_update(tfm, (const u8 *)&bits, sizeof(bits)); |
324 | 304 | |
325 | 305 | /* Store state in digest */ |
326 | - memcpy(out, rctx->state, sizeof(rctx->state)); | |
306 | + for (i = 0; i < 8; i++) | |
307 | + dst[i] = cpu_to_le32(rctx->state[i]); | |
327 | 308 | |
328 | 309 | /* Wipe context */ |
329 | 310 | memset(rctx, 0, sizeof(*rctx)); |