{"thread":{"id":"20218","subject":"Fw: Portability changes to mozilla-sha1","startedAt":"2009-07-24T17:17:21Z","lastAt":"2009-07-24T17:17:21Z","messageCount":1,"participants":["Bill Priest"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"118642","messageId":"45093.12936.qm@web55008.mail.re4.yahoo.com","threadId":"20218","inReplyTo":null,"subject":"Fw: Portability changes to mozilla-sha1","fromName":"Bill Priest","fromEmail":"priestwilliaml@yahoo.com","sentAt":"2009-07-24T17:17:21Z","receivedAt":"2009-07-24T17:17:21Z","isPatch":false,"sender":{"key":"priestwilliaml@yahoo.com","avatar":null},"body":"All,\n  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.\n  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.\n\nBill\n\nsplint -exportlocal -fixedformalarray sha1.c\nSplint 3.1.2 --- 08 Nov 2008\n\nFinished checking --- no warnings\n\ndiff --git a/mozilla-sha1/sha1.c b/mozilla-sha1/sha1.c\nindex 95a4ebf..8c6291c 100644\n--- a/mozilla-sha1/sha1.c\n+++ b/mozilla-sha1/sha1.c\n@@ -56,9 +56,9 @@ void moz_SHA1_Init(moz_SHA_CTX *ctx) {\n }\n \n \n-void moz_SHA1_Update(moz_SHA_CTX *ctx, const void *_dataIn, int len) {\n+void moz_SHA1_Update(moz_SHA_CTX *ctx, const void *_dataIn, int32_t len) {\n   const unsigned char *dataIn = _dataIn;\n-  int i;\n+  int32_t i;\n \n   /* Read the data into W and process blocks as they get full\n    */\n@@ -70,14 +70,14 @@ void moz_SHA1_Update(moz_SHA_CTX *ctx, const void *_dataIn, int len) {\n       ctx->lenW = 0;\n     }\n     ctx->sizeLo += 8;\n-    ctx->sizeHi += (ctx->sizeLo < 8);\n+    ctx->sizeHi += (uint32_t) (ctx->sizeLo < 8);\n   }\n }\n \n \n void moz_SHA1_Final(unsigned char hashout[20], moz_SHA_CTX *ctx) {\n-  unsigned char pad0x80 = 0x80;\n-  unsigned char pad0x00 = 0x00;\n+  unsigned char pad0x80 = (unsigned char) 0x80;\n+  unsigned char pad0x00 = (unsigned char) 0x00;\n   unsigned char padlen[8];\n   int i;\n \n@@ -114,7 +114,7 @@ void moz_SHA1_Final(unsigned char hashout[20], moz_SHA_CTX *ctx) {\n \n static void shaHashBlock(moz_SHA_CTX *ctx) {\n   int t;\n-  unsigned int A,B,C,D,E,TEMP;\n+  uint32_t A,B,C,D,E,TEMP;\n \n   for (t = 16; t <= 79; t++)\n     ctx->W[t] =\ndiff --git a/mozilla-sha1/sha1.h b/mozilla-sha1/sha1.h\nindex aa48a46..2cb5e26 100644\n--- a/mozilla-sha1/sha1.h\n+++ b/mozilla-sha1/sha1.h\n@@ -33,15 +33,17 @@\n  * GPL.\n  */\n \n+#include <stdint.h>\n+\n typedef struct {\n-  unsigned int H[5];\n-  unsigned int W[80];\n-  int lenW;\n-  unsigned int sizeHi,sizeLo;\n+  uint32_t H[5];\n+  uint32_t W[80];\n+  int32_t  lenW;\n+  uint32_t sizeHi,sizeLo;\n } moz_SHA_CTX;\n \n void moz_SHA1_Init(moz_SHA_CTX *ctx);\n-void moz_SHA1_Update(moz_SHA_CTX *ctx, const void *dataIn, int len);\n+void moz_SHA1_Update(moz_SHA_CTX *ctx, const void *dataIn, int32_t len);\n void moz_SHA1_Final(unsigned char hashout[20], moz_SHA_CTX *ctx);\n \n #define git_SHA_CTX    moz_SHA_CTX\n\n\n--- On Fri, 7/24/09, Bill Priest <priestwilliaml@yahoo.com> wrote:\n\n> From: Bill Priest <priestwilliaml@yahoo.com>\n> Subject: Portability changes to mozilla-sha1\n> To: git@vger.kernel.org\n> Date: Friday, July 24, 2009, 12:32 AM\n> All,\n>     In compiling sha1.c for a micro-controller\n> and testing it I noticed that many of the types of the\n> fields and local variables aren't portable.  Much of\n> git appears to use uint32_t and the like when the size of\n> the variable \"matters\".\n>     If a patch was provided to make sha1.[ch]\n> portable in terms of the types used would it be\n> accepted?  Of course the resulting code would be\n> regression tested prior to submission.\n>     I google'd a little bit but didn't find any\n> prior questions in a similar vein (sorry if I missed it).\n> \n> Regards,\n> \n> Bill\n> \n> \n> \n>       \n> --\n> To unsubscribe from this list: send the line \"unsubscribe\n> git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n>\n\n\n      \n\ndiff --git a/mozilla-sha1/sha1.c b/mozilla-sha1/sha1.c\nindex 95a4ebf..8c6291c 100644\n--- a/mozilla-sha1/sha1.c\n+++ b/mozilla-sha1/sha1.c\n@@ -56,9 +56,9 @@ void moz_SHA1_Init(moz_SHA_CTX *ctx) {\n }\n \n \n-void moz_SHA1_Update(moz_SHA_CTX *ctx, const void *_dataIn, int len) {\n+void moz_SHA1_Update(moz_SHA_CTX *ctx, const void *_dataIn, int32_t len) {\n   const unsigned char *dataIn = _dataIn;\n-  int i;\n+  int32_t i;\n \n   /* Read the data into W and process blocks as they get full\n    */\n@@ -70,14 +70,14 @@ void moz_SHA1_Update(moz_SHA_CTX *ctx, const void *_dataIn, int len) {\n       ctx->lenW = 0;\n     }\n     ctx->sizeLo += 8;\n-    ctx->sizeHi += (ctx->sizeLo < 8);\n+    ctx->sizeHi += (uint32_t) (ctx->sizeLo < 8);\n   }\n }\n \n \n void moz_SHA1_Final(unsigned char hashout[20], moz_SHA_CTX *ctx) {\n-  unsigned char pad0x80 = 0x80;\n-  unsigned char pad0x00 = 0x00;\n+  unsigned char pad0x80 = (unsigned char) 0x80;\n+  unsigned char pad0x00 = (unsigned char) 0x00;\n   unsigned char padlen[8];\n   int i;\n \n@@ -114,7 +114,7 @@ void moz_SHA1_Final(unsigned char hashout[20], moz_SHA_CTX *ctx) {\n \n static void shaHashBlock(moz_SHA_CTX *ctx) {\n   int t;\n-  unsigned int A,B,C,D,E,TEMP;\n+  uint32_t A,B,C,D,E,TEMP;\n \n   for (t = 16; t <= 79; t++)\n     ctx->W[t] =\ndiff --git a/mozilla-sha1/sha1.h b/mozilla-sha1/sha1.h\nindex aa48a46..2cb5e26 100644\n--- a/mozilla-sha1/sha1.h\n+++ b/mozilla-sha1/sha1.h\n@@ -33,15 +33,17 @@\n  * GPL.\n  */\n \n+#include <stdint.h>\n+\n typedef struct {\n-  unsigned int H[5];\n-  unsigned int W[80];\n-  int lenW;\n-  unsigned int sizeHi,sizeLo;\n+  uint32_t H[5];\n+  uint32_t W[80];\n+  int32_t  lenW;\n+  uint32_t sizeHi,sizeLo;\n } moz_SHA_CTX;\n \n void moz_SHA1_Init(moz_SHA_CTX *ctx);\n-void moz_SHA1_Update(moz_SHA_CTX *ctx, const void *dataIn, int len);\n+void moz_SHA1_Update(moz_SHA_CTX *ctx, const void *dataIn, int32_t len);\n void moz_SHA1_Final(unsigned char hashout[20], moz_SHA_CTX *ctx);\n \n #define git_SHA_CTX\tmoz_SHA_CTX\n"}]}