Fw: Portability changes to mozilla-sha1

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Bill Priest
Date: Friday, July 24, 2009 - 10:17 am

All,
  Here is a patch to mozilla-sha1/sha1.[ch] that makes the files more portable using types from stdint.h.  With gcc 4.3.3 I verified that the assembly produced w/ gcc -O2 -S -c sha1.c before and after the change was identical.  The patch also contains a couple of extra casts that allow splint to be silent.
  In case the webmail botches the patch below; I've also attached the file.  I couldn't find a recommended method for sending in a patch; apologies if this doesn't match the preferred method.

Bill

splint -exportlocal -fixedformalarray sha1.c
Splint 3.1.2 --- 08 Nov 2008

Finished checking --- no warnings

diff --git a/mozilla-sha1/sha1.c b/mozilla-sha1/sha1.c
index 95a4ebf..8c6291c 100644
--- a/mozilla-sha1/sha1.c
+++ b/mozilla-sha1/sha1.c
@@ -56,9 +56,9 @@ void moz_SHA1_Init(moz_SHA_CTX *ctx) {
 }
 
 
-void moz_SHA1_Update(moz_SHA_CTX *ctx, const void *_dataIn, int len) {
+void moz_SHA1_Update(moz_SHA_CTX *ctx, const void *_dataIn, int32_t len) {
   const unsigned char *dataIn = _dataIn;
-  int i;
+  int32_t i;
 
   /* Read the data into W and process blocks as they get full
    */
@@ -70,14 +70,14 @@ void moz_SHA1_Update(moz_SHA_CTX *ctx, const void *_dataIn, int len) {
       ctx->lenW = 0;
     }
     ctx->sizeLo += 8;
-    ctx->sizeHi += (ctx->sizeLo < 8);
+    ctx->sizeHi += (uint32_t) (ctx->sizeLo < 8);
   }
 }
 
 
 void moz_SHA1_Final(unsigned char hashout[20], moz_SHA_CTX *ctx) {
-  unsigned char pad0x80 = 0x80;
-  unsigned char pad0x00 = 0x00;
+  unsigned char pad0x80 = (unsigned char) 0x80;
+  unsigned char pad0x00 = (unsigned char) 0x00;
   unsigned char padlen[8];
   int i;
 
@@ -114,7 +114,7 @@ void moz_SHA1_Final(unsigned char hashout[20], moz_SHA_CTX *ctx) {
 
 static void shaHashBlock(moz_SHA_CTX *ctx) {
   int t;
-  unsigned int A,B,C,D,E,TEMP;
+  uint32_t A,B,C,D,E,TEMP;
 
   for (t = 16; t <= 79; t++)
     ctx->W[t] =
diff --git a/mozilla-sha1/sha1.h b/mozilla-sha1/sha1.h
index aa48a46..2cb5e26 100644
--- a/mozilla-sha1/sha1.h
+++ b/mozilla-sha1/sha1.h
@@ -33,15 +33,17 @@
  * GPL.
  */
 
+#include <stdint.h>
+
 typedef struct {
-  unsigned int H[5];
-  unsigned int W[80];
-  int lenW;
-  unsigned int sizeHi,sizeLo;
+  uint32_t H[5];
+  uint32_t W[80];
+  int32_t  lenW;
+  uint32_t sizeHi,sizeLo;
 } moz_SHA_CTX;
 
 void moz_SHA1_Init(moz_SHA_CTX *ctx);
-void moz_SHA1_Update(moz_SHA_CTX *ctx, const void *dataIn, int len);
+void moz_SHA1_Update(moz_SHA_CTX *ctx, const void *dataIn, int32_t len);
 void moz_SHA1_Final(unsigned char hashout[20], moz_SHA_CTX *ctx);
 
 #define git_SHA_CTX    moz_SHA_CTX


--- On Fri, 7/24/09, Bill Priest <priestwilliaml@yahoo.com> wrote:

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Fw: Portability changes to mozilla-sha1, Bill Priest, (Fri Jul 24, 10:17 am)