bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Yet another sha1/md[45] refinement


From: Bruno Haible
Subject: Re: Yet another sha1/md[45] refinement
Date: Thu, 31 Jan 2008 23:44:06 +0100
User-agent: KMail/1.5.4

Jim Meyering wrote:
> +  set_uint32 (r + 0 * sizeof ctx->A, SWAP (ctx->A));
> +  set_uint32 (r + 1 * sizeof ctx->B, SWAP (ctx->B));
> +  set_uint32 (r + 2 * sizeof ctx->C, SWAP (ctx->C));
> +  set_uint32 (r + 3 * sizeof ctx->D, SWAP (ctx->D));

Now this is confusing. If you assume that A, B, C, D all have the same
size, then it's simpler (more symmetry) to write:

     set_uint32 (r + 0 * sizeof ctx->A, SWAP (ctx->A));
     set_uint32 (r + 1 * sizeof ctx->A, SWAP (ctx->B));
     set_uint32 (r + 2 * sizeof ctx->A, SWAP (ctx->C));
     set_uint32 (r + 3 * sizeof ctx->A, SWAP (ctx->D));

If you don't want to assume this, then the code above is incorrect (it
stores the second element at offset sizeof(B) but should store it at the
offset sizeof(A), etc.) and should be corrected like this:

     set_uint32 (r, SWAP (ctx->A));
     set_uint32 (r + sizeof ctx->A, SWAP (ctx->B));
     set_uint32 (r + sizeof ctx->A + sizeof ctx->B, SWAP (ctx->C));
     set_uint32 (r + sizeof ctx->A + sizeof ctx->B + sizeof ctx->C, SWAP 
(ctx->D));

Bruno





reply via email to

[Prev in Thread] Current Thread [Next in Thread]