Commit 8fb04b98 authored by Ulf Möller's avatar Ulf Möller
Browse files

Problems with 64-bit long.

Pointed out by Andy Polyakov <appro@fy.chalmers.se>.
parent 8310d7df
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -5,6 +5,9 @@


 Changes between 0.9.2b and 0.9.3
 Changes between 0.9.2b and 0.9.3


  *) Fix problems with sizeof(long) == 8.
     [Andy Polyakov <appro@fy.chalmers.se>]

  *) Change functions to ANSI C.
  *) Change functions to ANSI C.
     [Ulf Möller]
     [Ulf Möller]


+9 −3
Original line number Original line Diff line number Diff line
@@ -70,11 +70,17 @@ extern "C" {
#define SHA_LENGTH_BLOCK 8
#define SHA_LENGTH_BLOCK 8
#define SHA_DIGEST_LENGTH 20
#define SHA_DIGEST_LENGTH 20


#ifdef WIN16
#define SHA_LONG unsigned long
#else
#define SHA_LONG unsigned int
#endif	

typedef struct SHAstate_st
typedef struct SHAstate_st
	{
	{
	unsigned long h0,h1,h2,h3,h4;
	SHA_LONG h0,h1,h2,h3,h4;
	unsigned long Nl,Nh;
	SHA_LONG Nl,Nh;
	unsigned long data[SHA_LBLOCK];
	SHA_LONG data[SHA_LBLOCK];
	int num;
	int num;
	} SHA_CTX;
	} SHA_CTX;


+23 −23
Original line number Original line Diff line number Diff line
@@ -69,23 +69,23 @@ char *SHA1_version="SHA1" OPENSSL_VERSION_PTEXT;
/* Implemented from SHA-1 document - The Secure Hash Algorithm
/* Implemented from SHA-1 document - The Secure Hash Algorithm
 */
 */


#define INIT_DATA_h0 (unsigned long)0x67452301L
#define INIT_DATA_h0 0x67452301UL
#define INIT_DATA_h1 (unsigned long)0xefcdab89L
#define INIT_DATA_h1 0xefcdab89UL
#define INIT_DATA_h2 (unsigned long)0x98badcfeL
#define INIT_DATA_h2 0x98badcfeUL
#define INIT_DATA_h3 (unsigned long)0x10325476L
#define INIT_DATA_h3 0x10325476UL
#define INIT_DATA_h4 (unsigned long)0xc3d2e1f0L
#define INIT_DATA_h4 0xc3d2e1f0UL


#define K_00_19	0x5a827999L
#define K_00_19	0x5a827999UL
#define K_20_39 0x6ed9eba1L
#define K_20_39 0x6ed9eba1UL
#define K_40_59 0x8f1bbcdcL
#define K_40_59 0x8f1bbcdcUL
#define K_60_79 0xca62c1d6L
#define K_60_79 0xca62c1d6UL


#ifndef NOPROTO
#ifndef NOPROTO
#  ifdef SHA1_ASM
#  ifdef SHA1_ASM
     void sha1_block_x86(SHA_CTX *c, register unsigned long *p, int num);
     void sha1_block_x86(SHA_CTX *c, register unsigned long *p, int num);
#    define sha1_block sha1_block_x86
#    define sha1_block sha1_block_x86
#  else
#  else
     void sha1_block(SHA_CTX *c, register unsigned long *p, int num);
     void sha1_block(SHA_CTX *c, register SHA_LONG *p, int num);
#  endif
#  endif
#else
#else
#  ifdef SHA1_ASM
#  ifdef SHA1_ASM
@@ -126,9 +126,9 @@ void SHA1_Init(SHA_CTX *c)
void SHA1_Update(SHA_CTX *c, register unsigned char *data,
void SHA1_Update(SHA_CTX *c, register unsigned char *data,
	     unsigned long len)
	     unsigned long len)
	{
	{
	register ULONG *p;
	register SHA_LONG *p;
	int ew,ec,sw,sc;
	int ew,ec,sw,sc;
	ULONG l;
	SHA_LONG l;


	if (len == 0) return;
	if (len == 0) return;


@@ -195,13 +195,13 @@ void SHA1_Update(SHA_CTX *c, register unsigned char *data,
	 */
	 */
#if 1
#if 1
#if defined(B_ENDIAN) || defined(SHA1_ASM)
#if defined(B_ENDIAN) || defined(SHA1_ASM)
	if ((((unsigned long)data)%sizeof(ULONG)) == 0)
	if ((((unsigned long)data)%sizeof(SHA_LONG)) == 0)
		{
		{
		sw=len/SHA_CBLOCK;
		sw=len/SHA_CBLOCK;
		if (sw)
		if (sw)
			{
			{
			sw*=SHA_CBLOCK;
			sw*=SHA_CBLOCK;
			sha1_block(c,(ULONG *)data,sw);
			sha1_block(c,(SHA_LONG *)data,sw);
			data+=sw;
			data+=sw;
			len-=sw;
			len-=sw;
			}
			}
@@ -214,7 +214,7 @@ void SHA1_Update(SHA_CTX *c, register unsigned char *data,
	while (len >= SHA_CBLOCK)
	while (len >= SHA_CBLOCK)
		{
		{
#if defined(B_ENDIAN) || defined(L_ENDIAN)
#if defined(B_ENDIAN) || defined(L_ENDIAN)
		if (p != (unsigned long *)data)
		if (p != (SHA_LONG *)data)
			memcpy(p,data,SHA_CBLOCK);
			memcpy(p,data,SHA_CBLOCK);
		data+=SHA_CBLOCK;
		data+=SHA_CBLOCK;
#  ifdef L_ENDIAN
#  ifdef L_ENDIAN
@@ -256,9 +256,9 @@ void SHA1_Update(SHA_CTX *c, register unsigned char *data,


void SHA1_Transform(SHA_CTX *c, unsigned char *b)
void SHA1_Transform(SHA_CTX *c, unsigned char *b)
	{
	{
	ULONG p[16];
	SHA_LONG p[16];
#ifndef B_ENDIAN
#ifndef B_ENDIAN
	ULONG *q;
	SHA_LONG *q;
	int i;
	int i;
#endif
#endif


@@ -279,7 +279,7 @@ void SHA1_Transform(SHA_CTX *c, unsigned char *b)
	q=p;
	q=p;
	for (i=(SHA_LBLOCK/4); i; i--)
	for (i=(SHA_LBLOCK/4); i; i--)
		{
		{
		ULONG l;
		SHA_LONG l;
		c2nl(b,l); *(q++)=l;
		c2nl(b,l); *(q++)=l;
		c2nl(b,l); *(q++)=l;
		c2nl(b,l); *(q++)=l;
		c2nl(b,l); *(q++)=l;
		c2nl(b,l); *(q++)=l;
@@ -291,10 +291,10 @@ void SHA1_Transform(SHA_CTX *c, unsigned char *b)


#ifndef SHA1_ASM
#ifndef SHA1_ASM


void sha1_block(SHA_CTX *c, register unsigned long *W, int num)
void sha1_block(SHA_CTX *c, register SHA_LONG *W, int num)
	{
	{
	register ULONG A,B,C,D,E,T;
	register SHA_LONG A,B,C,D,E,T;
	ULONG X[16];
	SHA_LONG X[16];


	A=c->h0;
	A=c->h0;
	B=c->h1;
	B=c->h1;
@@ -411,8 +411,8 @@ void sha1_block(SHA_CTX *c, register unsigned long *W, int num)
void SHA1_Final(unsigned char *md, SHA_CTX *c)
void SHA1_Final(unsigned char *md, SHA_CTX *c)
	{
	{
	register int i,j;
	register int i,j;
	register ULONG l;
	register SHA_LONG l;
	register ULONG *p;
	register SHA_LONG *p;
	static unsigned char end[4]={0x80,0x00,0x00,0x00};
	static unsigned char end[4]={0x80,0x00,0x00,0x00};
	unsigned char *cp=end;
	unsigned char *cp=end;


+23 −23
Original line number Original line Diff line number Diff line
@@ -69,19 +69,19 @@ char *SHA_version="SHA" OPENSSL_VERSION_PTEXT;
/* Implemented from SHA-0 document - The Secure Hash Algorithm
/* Implemented from SHA-0 document - The Secure Hash Algorithm
 */
 */


#define INIT_DATA_h0 (unsigned long)0x67452301L
#define INIT_DATA_h0 0x67452301UL
#define INIT_DATA_h1 (unsigned long)0xefcdab89L
#define INIT_DATA_h1 0xefcdab89UL
#define INIT_DATA_h2 (unsigned long)0x98badcfeL
#define INIT_DATA_h2 0x98badcfeUL
#define INIT_DATA_h3 (unsigned long)0x10325476L
#define INIT_DATA_h3 0x10325476UL
#define INIT_DATA_h4 (unsigned long)0xc3d2e1f0L
#define INIT_DATA_h4 0xc3d2e1f0UL


#define K_00_19	0x5a827999L
#define K_00_19	0x5a827999UL
#define K_20_39 0x6ed9eba1L
#define K_20_39 0x6ed9eba1UL
#define K_40_59 0x8f1bbcdcL
#define K_40_59 0x8f1bbcdcUL
#define K_60_79 0xca62c1d6L
#define K_60_79 0xca62c1d6UL


#ifndef NOPROTO
#ifndef NOPROTO
   void sha_block(SHA_CTX *c, register unsigned long *p, int num);
   void sha_block(SHA_CTX *c, register SHA_LONG *p, int num);
#else
#else
   void sha_block();
   void sha_block();
#endif
#endif
@@ -106,9 +106,9 @@ void SHA_Init(SHA_CTX *c)


void SHA_Update(SHA_CTX *c, register unsigned char *data, unsigned long len)
void SHA_Update(SHA_CTX *c, register unsigned char *data, unsigned long len)
	{
	{
	register ULONG *p;
	register SHA_LONG *p;
	int ew,ec,sw,sc;
	int ew,ec,sw,sc;
	ULONG l;
	SHA_LONG l;


	if (len == 0) return;
	if (len == 0) return;


@@ -175,13 +175,13 @@ void SHA_Update(SHA_CTX *c, register unsigned char *data, unsigned long len)
	 */
	 */
#if 1
#if 1
#if defined(B_ENDIAN) || defined(SHA_ASM)
#if defined(B_ENDIAN) || defined(SHA_ASM)
	if ((((unsigned long)data)%sizeof(ULONG)) == 0)
	if ((((unsigned long)data)%sizeof(SHA_LONG)) == 0)
		{
		{
		sw=len/SHA_CBLOCK;
		sw=len/SHA_CBLOCK;
		if (sw)
		if (sw)
			{
			{
			sw*=SHA_CBLOCK;
			sw*=SHA_CBLOCK;
			sha_block(c,(ULONG *)data,sw);
			sha_block(c,(SHA_LONG *)data,sw);
			data+=sw;
			data+=sw;
			len-=sw;
			len-=sw;
			}
			}
@@ -194,7 +194,7 @@ void SHA_Update(SHA_CTX *c, register unsigned char *data, unsigned long len)
	while (len >= SHA_CBLOCK)
	while (len >= SHA_CBLOCK)
		{
		{
#if defined(B_ENDIAN) || defined(L_ENDIAN)
#if defined(B_ENDIAN) || defined(L_ENDIAN)
		if (p != (unsigned long *)data)
		if (p != (SHA_LONG *)data)
			memcpy(p,data,SHA_CBLOCK);
			memcpy(p,data,SHA_CBLOCK);
		data+=SHA_CBLOCK;
		data+=SHA_CBLOCK;
#  ifdef L_ENDIAN
#  ifdef L_ENDIAN
@@ -236,9 +236,9 @@ void SHA_Update(SHA_CTX *c, register unsigned char *data, unsigned long len)


void SHA_Transform(SHA_CTX *c, unsigned char *b)
void SHA_Transform(SHA_CTX *c, unsigned char *b)
	{
	{
	ULONG p[16];
	SHA_LONG p[16];
#if !defined(B_ENDIAN)
#if !defined(B_ENDIAN)
	ULONG *q;
	SHA_LONG *q;
	int i;
	int i;
#endif
#endif


@@ -259,7 +259,7 @@ void SHA_Transform(SHA_CTX *c, unsigned char *b)
	q=p;
	q=p;
	for (i=(SHA_LBLOCK/4); i; i--)
	for (i=(SHA_LBLOCK/4); i; i--)
		{
		{
		ULONG l;
		SHA_LONG l;
		c2nl(b,l); *(q++)=l;
		c2nl(b,l); *(q++)=l;
		c2nl(b,l); *(q++)=l;
		c2nl(b,l); *(q++)=l;
		c2nl(b,l); *(q++)=l;
		c2nl(b,l); *(q++)=l;
@@ -269,10 +269,10 @@ void SHA_Transform(SHA_CTX *c, unsigned char *b)
	sha_block(c,p,64);
	sha_block(c,p,64);
	}
	}


void sha_block(SHA_CTX *c, register unsigned long *W, int num)
void sha_block(SHA_CTX *c, register SHA_LONG *W, int num)
	{
	{
	register ULONG A,B,C,D,E,T;
	register SHA_LONG A,B,C,D,E,T;
	ULONG X[16];
	SHA_LONG X[16];


	A=c->h0;
	A=c->h0;
	B=c->h1;
	B=c->h1;
@@ -388,8 +388,8 @@ void sha_block(SHA_CTX *c, register unsigned long *W, int num)
void SHA_Final(unsigned char *md, SHA_CTX *c)
void SHA_Final(unsigned char *md, SHA_CTX *c)
	{
	{
	register int i,j;
	register int i,j;
	register ULONG l;
	register SHA_LONG l;
	register ULONG *p;
	register SHA_LONG *p;
	static unsigned char end[4]={0x80,0x00,0x00,0x00};
	static unsigned char end[4]={0x80,0x00,0x00,0x00};
	unsigned char *cp=end;
	unsigned char *cp=end;


+0 −2
Original line number Original line Diff line number Diff line
@@ -66,8 +66,6 @@
#endif
#endif
#endif
#endif


#define ULONG	unsigned long

#undef c2nl
#undef c2nl
#define c2nl(c,l)	(l =(((unsigned long)(*((c)++)))<<24), \
#define c2nl(c,l)	(l =(((unsigned long)(*((c)++)))<<24), \
			 l|=(((unsigned long)(*((c)++)))<<16), \
			 l|=(((unsigned long)(*((c)++)))<<16), \