Fw: Portability changes to mozilla-sha1

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

 



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@xxxxxxxxx> wrote:

> From: Bill Priest <priestwilliaml@xxxxxxxxx>
> Subject: Portability changes to mozilla-sha1
> To: git@xxxxxxxxxxxxxxx
> Date: Friday, July 24, 2009, 12:32 AM
> All,
>     In compiling sha1.c for a micro-controller
> and testing it I noticed that many of the types of the
> fields and local variables aren't portable.  Much of
> git appears to use uint32_t and the like when the size of
> the variable "matters".
>     If a patch was provided to make sha1.[ch]
> portable in terms of the types used would it be
> accepted?  Of course the resulting code would be
> regression tested prior to submission.
>     I google'd a little bit but didn't find any
> prior questions in a similar vein (sorry if I missed it).
> 
> Regards,
> 
> Bill
> 
> 
> 
>       
> --
> To unsubscribe from this list: send the line "unsubscribe
> git" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>


      
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

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]