Attachment "554351.patch" to
ticket [554351ffff]
added by
dgp
2003-12-08 23:27:11.
Index: generic/sample.c
===================================================================
RCS file: /cvsroot/tcl/sampleextension/generic/sample.c,v
retrieving revision 1.1
diff -u -r1.1 sample.c
--- generic/sample.c 12 Mar 2002 04:41:48 -0000 1.1
+++ generic/sample.c 8 Dec 2003 16:25:24 -0000
@@ -35,6 +35,7 @@
#include <stdio.h>
#include <string.h>
+#include <assert.h>
#include "sample.h"
#define Rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
@@ -93,18 +94,19 @@
void
SHA1Transform(state, buffer)
- unsigned long state[5]; /* State variable */
+ sha_uint32_t state[5]; /* State variable */
unsigned char buffer[64]; /* Modified buffer */
{
#if (!defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN))
unsigned char *p;
#endif
- unsigned long a, b, c, d, e;
+ sha_uint32_t a, b, c, d, e;
typedef union {
unsigned char c[64];
- unsigned long l[16];
+ sha_uint32_t l[16];
} CHAR64LONG16;
CHAR64LONG16* block;
+
#ifdef SHA1HANDSOFF
static unsigned char workspace[64];
block = (CHAR64LONG16*)workspace;
@@ -113,6 +115,8 @@
block = (CHAR64LONG16*)buffer;
#endif
+ assert(sizeof(block->c) == sizeof(block->l));
+
/*
* Copy context->state[] to working vars
*/
@@ -275,7 +279,7 @@
SHA1_CTX* context; /* Context to pad */
unsigned char digest[20]; /* Returned message digest */
{
- unsigned long i, j;
+ sha_uint32_t i, j;
unsigned char finalcount[8];
for (i = 0; i < 8; i++) {
@@ -298,7 +302,7 @@
SHA1Update(context, finalcount, 8);
for (i = 0; i < 20; i++) {
digest[i] = (unsigned char)
- ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
+ ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
}
/*
@@ -306,9 +310,7 @@
*/
i = j = 0;
- memset(context->buffer, 0, 64);
- memset(context->state, 0, 20);
- memset(context->count, 0, 8);
+ memset(context, 0, sizeof(SHA1_CTX));
memset(&finalcount, 0, 8);
/*
Index: generic/sample.h
===================================================================
RCS file: /cvsroot/tcl/sampleextension/generic/sample.h,v
retrieving revision 1.2
diff -u -r1.2 sample.h
--- generic/sample.h 3 Dec 2003 08:04:32 -0000 1.2
+++ generic/sample.h 8 Dec 2003 16:25:24 -0000
@@ -27,9 +27,20 @@
#define TCL_STORAGE_CLASS DLLEXPORT
#endif /* BUILD_sample */
+#ifdef HAVE_INTTYPES_H
+# include <inttypes.h>
+typedef uint32_t sha_uint32_t;
+#else
+# if ((1<<31)<0)
+typedef unsigned long sha_uint32_t;
+# else
+typedef unsigned int sha_uint32_t;
+# endif
+#endif
+
typedef struct {
- unsigned long state[5];
- unsigned long count[2];
+ sha_uint32_t state[5];
+ sha_uint32_t count[2];
unsigned char buffer[64];
} SHA1_CTX;