CVS: crypto/src SHA256.c,1.1,1.2

"A.M. Kuchling" <[email protected]> Fri, 10 Jun 2005 12:18:14 -0700
Newsgroups gmane.comp.python.cryptography.cvs
Message-ID <[email protected]>
Update of /cvsroot/pycrypto/crypto/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2858

Modified Files:
	SHA256.c 
Log Message:
[Bug #1185980] Fix SHA256 on AMD64

Index: SHA256.c
===================================================================
RCS file: /cvsroot/pycrypto/crypto/src/SHA256.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SHA256.c	19 Dec 2003 18:51:28 -0000	1.1
+++ SHA256.c	10 Jun 2005 19:17:58 -0000	1.2
@@ -11,20 +11,25 @@
  * Tom St Denis -- http://tomstdenis.home.dhs.org

  * */

 #include "Python.h"

-#define MODULE_NAME SHA256
+#define MODULE_NAME SHA256

 #define DIGEST_SIZE 32

 

-typedef unsigned char U8;
+typedef unsigned char U8;

+#if defined(__amd64__)

+#include <inttypes.h>

+typedef uint32_t U32;

+#else

 typedef unsigned int U32;

+#endif

 

 typedef struct {

-    unsigned long state[8], length, curlen;

+    U32 state[8], length, curlen;

     unsigned char buf[64];

 }

 hash_state;

 

 /* the K array */

-static const unsigned long K[64] = {

+static const U32 K[64] = {

     0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, 0x3956c25bUL,

     0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, 0xd807aa98UL, 0x12835b01UL,

     0x243185beUL, 0x550c7dc3UL, 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL,

@@ -53,7 +58,7 @@
 /* compress 512-bits */

 static void sha_compress(hash_state * md)

 {

-    unsigned long S[8], W[64], t0, t1;

+    U32 S[8], W[64], t0, t1;

     int i;

 

     /* copy state into S */

@@ -62,10 +67,10 @@
 

     /* copy the state into 512-bits into W[0..15] */

     for (i = 0; i < 16; i++)

-        W[i] = (((unsigned long) md->buf[(4 * i) + 0]) << 24) |

-            (((unsigned long) md->buf[(4 * i) + 1]) << 16) |

-            (((unsigned long) md->buf[(4 * i) + 2]) << 8) |

-            (((unsigned long) md->buf[(4 * i) + 3]));

+        W[i] = (((U32) md->buf[(4 * i) + 0]) << 24) |

+            (((U32) md->buf[(4 * i) + 1]) << 16) |

+            (((U32) md->buf[(4 * i) + 2]) << 8) |

+            (((U32) md->buf[(4 * i) + 3]));

 

     /* fill W[16..63] */

     for (i = 16; i < 64; i++)

@@ -172,14 +177,14 @@
 }

 

 // Done

-static void
+static void

 hash_copy(hash_state *src, hash_state *dest)

 {

 	memcpy(dest,src,sizeof(hash_state));

 }

 

 // Done

-static PyObject *
+static PyObject *

 hash_digest (const hash_state *self)

 {

 	unsigned char digest[32];




-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.  
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20