Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
fix ripemd that wasn't appending the size in the correct order.
Browse files Browse the repository at this point in the history
instead of just fixing it, optimise the two step process, into a single
uint64 shift and swap. sz has already been represented as an uint64
compared to the usual representation of 2 uint32_t anyway.
  • Loading branch information
vincenthz committed Jun 21, 2010
1 parent 63ef89c commit cb8d3de
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions cbits/ripemd.c
Expand Up @@ -275,21 +275,20 @@ void ripemd160_update(struct ripemd160_ctx *ctx, uint8_t *data, uint32_t len)
void ripemd160_finalize(struct ripemd160_ctx *ctx, uint8_t *out) void ripemd160_finalize(struct ripemd160_ctx *ctx, uint8_t *out)
{ {
static uint8_t padding[64] = { 0x80, }; static uint8_t padding[64] = { 0x80, };
uint32_t bits[2]; uint64_t bits;
uint32_t index, padlen; uint32_t index, padlen;
uint32_t *p = (uint32_t *) out; uint32_t *p = (uint32_t *) out;


/* add padding and update data with it */ /* add padding and update data with it */
bits[0] = cpu_to_le32((uint32_t) (ctx->sz >> 29)); bits = cpu_to_le64(ctx->sz << 3);
bits[1] = cpu_to_le32((uint32_t) (ctx->sz << 3));


/* pad out to 56 */ /* pad out to 56 */
index = (uint32_t) (ctx->sz & 0x3f); index = (uint32_t) (ctx->sz & 0x3f);
padlen = (index < 56) ? (56 - index) : ((64 + 56) - index); padlen = (index < 56) ? (56 - index) : ((64 + 56) - index);
ripemd160_update(ctx, padding, padlen); ripemd160_update(ctx, padding, padlen);


/* append length */ /* append length */
ripemd160_update(ctx, (uint8_t *) bits, sizeof(bits)); ripemd160_update(ctx, (uint8_t *) &bits, sizeof(bits));


/* output digest */ /* output digest */
p[0] = cpu_to_le32(ctx->h[0]); p[0] = cpu_to_le32(ctx->h[0]);
Expand Down

0 comments on commit cb8d3de

Please sign in to comment.