Thread (31 messages) 31 messages, 3 authors, 2016-06-15

Re: [PATCH 2/7] block-sha1: try to use rol/ror appropriately

From: Bert Wesarg <hidden>
Date: 2016-06-15 22:47:11

Hi,

On Thu, Aug 6, 2009 at 17:16, Linus
Torvalds[off-list ref] wrote:
quoted hunk ↗ jump to hunk
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)))
+#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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help