Hi! Me again:-) Ready for more LP64 woes? Taaaa-daaaa... Turn for sha
this time. Well, I suppose you've already figured with out from the
subject, huh? Same *damn* problem as with blowfish. Namely traversing
array of ints as array of longs. Check it out...
>From sha.h:
> #define SHA_CBLOCK 64
> #define SHA_LBLOCK 16
> ...
> unsigned long data[SHA_LBLOCK];
And then in e.g. sha_dgst.c:
> p=c->data;
> ...
> if (p != (SHA_uint32 *)data)
> memcpy(p,data,SHA_CBLOCK);
> data+=SHA_CBLOCK;
> ...
> sha_block(c,p,64);
> len-=SHA_CBLOCK;
i.e. memcpy copies 64 bytes or 8 longs in LP64 case, while sha_block
treats it as an 128 bytes long array... Indeed! SHA_CBLOCK is assumed to
be SHA_LBLOCK times sizeof(data[0]) which gives 4 for the latter which
is *not* case on LP64.
Solution. Force 32 bits even on LP64:
*** ./sha.h.orig Mon Dec 21 11:55:37 1998
--- ./sha.h Tue Apr 20 14:47:09 1999
***************
*** 70,80 ****
#define SHA_LENGTH_BLOCK 8
#define SHA_DIGEST_LENGTH 20
typedef struct SHAstate_st
{
! unsigned long h0,h1,h2,h3,h4;
! unsigned long Nl,Nh;
! unsigned long data[SHA_LBLOCK];
int num;
} SHA_CTX;
--- 70,82 ----
#define SHA_LENGTH_BLOCK 8
#define SHA_DIGEST_LENGTH 20
+ typedef unsigned int SHA_uint32;
+
typedef struct SHAstate_st
{
! SHA_uint32 h0,h1,h2,h3,h4;
! SHA_uint32 Nl,Nh;
! SHA_uint32 data[SHA_LBLOCK];
int num;
} SHA_CTX;
*** ./sha_dgst.c.orig Mon Mar 22 13:21:54 1999
--- ./sha_dgst.c Tue Apr 20 14:57:09 1999
***************
*** 69,87 ****
/* Implemented from SHA-0 document - The Secure Hash Algorithm
*/
! #define INIT_DATA_h0 (unsigned long)0x67452301L
! #define INIT_DATA_h1 (unsigned long)0xefcdab89L
! #define INIT_DATA_h2 (unsigned long)0x98badcfeL
! #define INIT_DATA_h3 (unsigned long)0x10325476L
! #define INIT_DATA_h4 (unsigned long)0xc3d2e1f0L
! #define K_00_19 0x5a827999L
! #define K_20_39 0x6ed9eba1L
! #define K_40_59 0x8f1bbcdcL
! #define K_60_79 0xca62c1d6L
#ifndef NOPROTO
! void sha_block(SHA_CTX *c, register unsigned long *p, int num);
#else
void sha_block();
#endif
--- 69,87 ----
/* Implemented from SHA-0 document - The Secure Hash Algorithm
*/
! #define INIT_DATA_h0 0x67452301UL
! #define INIT_DATA_h1 0xefcdab89UL
! #define INIT_DATA_h2 0x98badcfeUL
! #define INIT_DATA_h3 0x10325476UL
! #define INIT_DATA_h4 0xc3d2e1f0UL
! #define K_00_19 0x5a827999UL
! #define K_20_39 0x6ed9eba1UL
! #define K_40_59 0x8f1bbcdcUL
! #define K_60_79 0xca62c1d6UL
#ifndef NOPROTO
! void sha_block(SHA_CTX *c, register SHA_uint32 *p, int num);
#else
void sha_block();
#endif
***************
*** 110,116 ****
register unsigned char *data;
unsigned long len;
{
! register ULONG *p;
int ew,ec,sw,sc;
ULONG l;
--- 110,116 ----
register unsigned char *data;
unsigned long len;
{
! register SHA_uint32 *p;
int ew,ec,sw,sc;
ULONG l;
***************
*** 179,191 ****
*/
#if 1
#if defined(B_ENDIAN) || defined(SHA_ASM)
! if ((((unsigned long)data)%sizeof(ULONG)) == 0)
{
sw=len/SHA_CBLOCK;
if (sw)
{
sw*=SHA_CBLOCK;
! sha_block(c,(ULONG *)data,sw);
data+=sw;
len-=sw;
}
--- 179,191 ----
*/
#if 1
#if defined(B_ENDIAN) || defined(SHA_ASM)
! if ((((unsigned long)data)%sizeof(SHA_uint32)) == 0)
{
sw=len/SHA_CBLOCK;
if (sw)
{
sw*=SHA_CBLOCK;
! sha_block(c,(SHA_uint32 *)data,sw);
data+=sw;
len-=sw;
}
***************
*** 198,204 ****
while (len >= SHA_CBLOCK)
{
#if defined(B_ENDIAN) || defined(L_ENDIAN)
! if (p != (unsigned long *)data)
memcpy(p,data,SHA_CBLOCK);
data+=SHA_CBLOCK;
# ifdef L_ENDIAN
--- 198,204 ----
while (len >= SHA_CBLOCK)
{
#if defined(B_ENDIAN) || defined(L_ENDIAN)
! if (p != (SHA_uint32 *)data)
memcpy(p,data,SHA_CBLOCK);
data+=SHA_CBLOCK;
# ifdef L_ENDIAN
***************
*** 242,250 ****
SHA_CTX *c;
unsigned char *b;
{
! ULONG p[16];
#if !defined(B_ENDIAN)
! ULONG *q;
int i;
#endif
--- 242,250 ----
SHA_CTX *c;
unsigned char *b;
{
! SHA_uint32 p[16];
#if !defined(B_ENDIAN)
! SHA_uint32 *q;
int i;
#endif
***************
*** 265,271 ****
q=p;
for (i=(SHA_LBLOCK/4); i; i--)
{
! ULONG l;
c2nl(b,l); *(q++)=l;
c2nl(b,l); *(q++)=l;
c2nl(b,l); *(q++)=l;
--- 265,271 ----
q=p;
for (i=(SHA_LBLOCK/4); i; i--)
{
! SHA_uint32 l;
c2nl(b,l); *(q++)=l;
c2nl(b,l); *(q++)=l;
c2nl(b,l); *(q++)=l;
***************
*** 277,287 ****
void sha_block(c, W, num)
SHA_CTX *c;
! register unsigned long *W;
int num;
{
! register ULONG A,B,C,D,E,T;
! ULONG X[16];
A=c->h0;
B=c->h1;
--- 277,287 ----
void sha_block(c, W, num)
SHA_CTX *c;
! register SHA_uint32 *W;
int num;
{
! register SHA_uint32 A,B,C,D,E,T;
! SHA_uint32 X[16];
A=c->h0;
B=c->h1;
***************
*** 399,406 ****
SHA_CTX *c;
{
register int i,j;
! register ULONG l;
! register ULONG *p;
static unsigned char end[4]={0x80,0x00,0x00,0x00};
unsigned char *cp=end;
--- 399,406 ----
SHA_CTX *c;
{
register int i,j;
! register SHA_uint32 l;
! register SHA_uint32 *p;
static unsigned char end[4]={0x80,0x00,0x00,0x00};
unsigned char *cp=end;
*** ./sha1dgst.c.orig Mon Mar 22 13:21:54 1999
--- ./sha1dgst.c Tue Apr 20 14:58:05 1999
***************
*** 69,84 ****
/* Implemented from SHA-1 document - The Secure Hash Algorithm
*/
! #define INIT_DATA_h0 (unsigned long)0x67452301L
! #define INIT_DATA_h1 (unsigned long)0xefcdab89L
! #define INIT_DATA_h2 (unsigned long)0x98badcfeL
! #define INIT_DATA_h3 (unsigned long)0x10325476L
! #define INIT_DATA_h4 (unsigned long)0xc3d2e1f0L
! #define K_00_19 0x5a827999L
! #define K_20_39 0x6ed9eba1L
! #define K_40_59 0x8f1bbcdcL
! #define K_60_79 0xca62c1d6L
#ifndef NOPROTO
# ifdef SHA1_ASM
--- 69,84 ----
/* Implemented from SHA-1 document - The Secure Hash Algorithm
*/
! #define INIT_DATA_h0 0x67452301UL
! #define INIT_DATA_h1 0xefcdab89UL
! #define INIT_DATA_h2 0x98badcfeUL
! #define INIT_DATA_h3 0x10325476UL
! #define INIT_DATA_h4 0xc3d2e1f0UL
! #define K_00_19 0x5a827999UL
! #define K_20_39 0x6ed9eba1UL
! #define K_40_59 0x8f1bbcdcUL
! #define K_60_79 0xca62c1d6UL
#ifndef NOPROTO
# ifdef SHA1_ASM
***************
*** 85,91 ****
void sha1_block_x86(SHA_CTX *c, register unsigned long *p, int
num);
# define sha1_block sha1_block_x86
# else
! void sha1_block(SHA_CTX *c, register unsigned long *p, int num);
# endif
#else
# ifdef SHA1_ASM
--- 85,91 ----
void sha1_block_x86(SHA_CTX *c, register unsigned long *p, int
num);
# define sha1_block sha1_block_x86
# else
! void sha1_block(SHA_CTX *c, register SHA_uint32 *p, int num);
# endif
#else
# ifdef SHA1_ASM
***************
*** 129,135 ****
register unsigned char *data;
unsigned long len;
{
! register ULONG *p;
int ew,ec,sw,sc;
ULONG l;
--- 129,135 ----
register unsigned char *data;
unsigned long len;
{
! register SHA_uint32 *p;
int ew,ec,sw,sc;
ULONG l;
***************
*** 198,210 ****
*/
#if 1
#if defined(B_ENDIAN) || defined(SHA1_ASM)
! if ((((unsigned long)data)%sizeof(ULONG)) == 0)
{
sw=len/SHA_CBLOCK;
if (sw)
{
sw*=SHA_CBLOCK;
! sha1_block(c,(ULONG *)data,sw);
data+=sw;
len-=sw;
}
--- 198,210 ----
*/
#if 1
#if defined(B_ENDIAN) || defined(SHA1_ASM)
! if ((((unsigned long)data)%sizeof(SHA_uint32)) == 0)
{
sw=len/SHA_CBLOCK;
if (sw)
{
sw*=SHA_CBLOCK;
! sha1_block(c,(SHA_uint32 *)data,sw);
data+=sw;
len-=sw;
}
***************
*** 217,223 ****
while (len >= SHA_CBLOCK)
{
#if defined(B_ENDIAN) || defined(L_ENDIAN)
! if (p != (unsigned long *)data)
memcpy(p,data,SHA_CBLOCK);
data+=SHA_CBLOCK;
# ifdef L_ENDIAN
--- 217,223 ----
while (len >= SHA_CBLOCK)
{
#if defined(B_ENDIAN) || defined(L_ENDIAN)
! if (p != (SHA_uint32 *)data)
memcpy(p,data,SHA_CBLOCK);
data+=SHA_CBLOCK;
# ifdef L_ENDIAN
***************
*** 261,269 ****
SHA_CTX *c;
unsigned char *b;
{
! ULONG p[16];
#ifndef B_ENDIAN
! ULONG *q;
int i;
#endif
--- 261,269 ----
SHA_CTX *c;
unsigned char *b;
{
! SHA_uint32 p[16];
#ifndef B_ENDIAN
! SHA_uint32 *q;
int i;
#endif
***************
*** 284,290 ****
q=p;
for (i=(SHA_LBLOCK/4); i; i--)
{
! ULONG l;
c2nl(b,l); *(q++)=l;
c2nl(b,l); *(q++)=l;
c2nl(b,l); *(q++)=l;
--- 284,290 ----
q=p;
for (i=(SHA_LBLOCK/4); i; i--)
{
! SHA_uint32 l;
c2nl(b,l); *(q++)=l;
c2nl(b,l); *(q++)=l;
c2nl(b,l); *(q++)=l;
***************
*** 298,308 ****
void sha1_block(c, W, num)
SHA_CTX *c;
! register unsigned long *W;
int num;
{
! register ULONG A,B,C,D,E,T;
! ULONG X[16];
A=c->h0;
B=c->h1;
--- 298,308 ----
void sha1_block(c, W, num)
SHA_CTX *c;
! register SHA_uint32 *W;
int num;
{
! register SHA_uint32 A,B,C,D,E,T;
! SHA_uint32 X[16];
A=c->h0;
B=c->h1;
***************
*** 421,428 ****
SHA_CTX *c;
{
register int i,j;
! register ULONG l;
! register ULONG *p;
static unsigned char end[4]={0x80,0x00,0x00,0x00};
unsigned char *cp=end;
--- 421,428 ----
SHA_CTX *c;
{
register int i,j;
! register SHA_uint32 l;
! register SHA_uint32 *p;
static unsigned char end[4]={0x80,0x00,0x00,0x00};
unsigned char *cp=end;
Cheers (if you find anything cheerful). Andy.
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]