Re: [PATCH 2/7] block-sha1: try to use rol/ror appropriately
- From
Bert Wesarg <bert.wesarg@googlemail.com>
- Date
- Aug 6, 2009, 18:25 UTC
- Message-ID
- <36ca99e90908061125w71c0294wd4c896dc5fb812fc@mail.gmail.com>
- In-Reply-To
- <alpine.LFD.2.01.0908060815430.3390@localhost.localdomain>
Hi,
On Thu, Aug 6, 2009 at 17:16, Linus Torvalds<torvalds@linux-foundation.org> wrote:
Show 18 quoted lines
> diff --git a/block-sha1/sha1.c b/block-sha1/sha1.c
> index eef32f7..a45a3de 100644
> --- a/block-sha1/sha1.c
> +++ b/block-sha1/sha1.c
> @@ -80,7 +80,19 @@ void blk_SHA1_Final(unsigned char hashout[20], blk_SHA_CTX *ctx)
> ((unsigned int *)hashout)[i] = htonl(ctx->H[i]);
> }
>
> -#define SHA_ROT(X,n) (((X) << (n)) | ((X) >> (32-(n))))
> +#if defined(__i386__) || defined(__x86_64__)
> +
> +#define SHA_ASM(op, x, n) ({ unsigned int __res; asm(op " %1,%0":"=r" (__res):"i" (n), "0" (x)); __res; })
> +#define SHA_ROL(x,n) SHA_ASM("rol", x, n)
> +#define SHA_ROR(x,n) SHA_ASM("ror", x, n)
> +
> +#else
> +
> +#define SHA_ROT(X,n) (((X) << (l)) | ((X) >> (r)))I suspect, this should be: #define SHA_ROT(X,l.r) (((X) << (l)) | ((X) >> (r)))
Show 7 quoted lines
> +#define SHA_ROL(X,n) SHA_ROT(X,n,32-(n))
> +#define SHA_ROR(X,n) SHA_ROT(X,32-(n),n)
> +
> +#endif
>
> static void blk_SHA1Block(blk_SHA_CTX *ctx, const unsigned int *data)
> {Bert