Portability changes to mozilla-sha1
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
mozilla-sha1/sha1.c +6 -6
@@ -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] =
mozilla-sha1/sha1.h +7 -5
@@ -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
Quoted 23 lines · Bill Priest
From: Bill Priest <[email protected]>
Subject: Portability changes to mozilla-sha1
To: [email protected]
Date: Friday, July 24, 2009, 12:32 AM
All,
In compilingsha1.cfor 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 useuint32_tand 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
Quoted 7 lines
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
mozilla-sha1/sha1.c +6 -6
@@ -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] =
mozilla-sha1/sha1.h +7 -5
@@ -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