Subject: Endian wierdness in libskey.
To: None <current-users@sun-lamp.cs.berkeley.edu>
From: Jan-Oliver Neumann <jan@encap.Hanse.DE>
List: current-users
Date: 05/25/1994 14:23:54
In file md4.c of libskey we have some of these homebrewed endian checks
that can blow up the md4 algorithm. As we have our <machine/endian.h> I
propose the following fix:

-------------------------------------------------------------------------------
*** md4.c~	Wed May 25 14:13:43 1994
--- md4.c	Wed May 25 14:19:20 1994
***************
*** 46,72 ****
  
  /* Implementation notes:
   * This implementation assumes that longs are 32-bit quantities.
!  * If the machine stores the least-significant byte of an long in the
!  * least-addressed byte (eg., VAX and 8086), then LOWBYTEFIRST should be
!  * set to TRUE.  Otherwise (eg., SUNS), LOWBYTEFIRST should be set to
!  * FALSE.  Note that on machines with LOWBYTEFIRST FALSE the routine
   * MDupdate modifies has a side-effect on its input array (the order of bytes
   * in each word are reversed).  If this is undesired a call to MDreverse(X) can
   * reverse the bytes of X back into order after each call to MDupdate.
   */
- #define TRUE  1
- #define FALSE 0
  
- #if (defined(__MSDOS__) || defined(MPU8086) || defined(MPU8080) \
-  || defined(vax) || defined (MIPSEL))
- #define LOWBYTEFIRST TRUE	/* Low order bytes are first in memory */
- #else			/* Almost all other machines are big-endian */
- #define	LOWBYTEFIRST FALSE
- #endif
- 
- 
  /* Compile-time includes */
  #include <stdio.h>
  #include "md4.h"
  
  /* Compile-time declarations of MD4 ``magic constants'' */
--- 46,60 ----
  
  /* Implementation notes:
   * This implementation assumes that longs are 32-bit quantities.
!  * Note that on big endian machines the routine
   * MDupdate modifies has a side-effect on its input array (the order of bytes
   * in each word are reversed).  If this is undesired a call to MDreverse(X) can
   * reverse the bytes of X back into order after each call to MDupdate.
   */
  
  /* Compile-time includes */
  #include <stdio.h>
+ #include <machine/endian.h>
  #include "md4.h"
  
  /* Compile-time declarations of MD4 ``magic constants'' */
***************
*** 189,195 ****
  { 
  	register unsigned long tmp, A, B, C, D;
  
! #if LOWBYTEFIRST == FALSE
  	MDreverse(X);
  #endif
  	A = MDp->buffer[0];
--- 177,183 ----
  { 
  	register unsigned long tmp, A, B, C, D;
  
! #if BYTE_ORDER == BIG_ENDIAN
  	MDreverse(X);
  #endif
  	A = MDp->buffer[0];
---------------------------------------------------------------------------
Happy hacking,
              Jan

------------------------------------------------------------------------------