Moved UINT4 stuff in md4 & md5 to uint32_t, which is more portable.
authoraland <aland>
Wed, 20 Aug 2003 19:22:06 +0000 (19:22 +0000)
committeraland <aland>
Wed, 20 Aug 2003 19:22:06 +0000 (19:22 +0000)
src/include/md4.h
src/include/md5.h
src/lib/md4.c
src/lib/md5.c

index 787489a..aa523d6 100644 (file)
@@ -3,6 +3,20 @@
 
 #ifndef _LRAD_PROTO_H
 #define _LRAD_PROTO_H
+#include "autoconf.h"
+
+#if HAVE_INTTYPES_H
+#include <inttypes.h>
+#endif
+
+#if HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#if HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
 /* GLOBAL.H - RSAREF types and constants
  */
 
 typedef unsigned char *POINTER;
 #define _POINTER_T
 
-/* UINT2 defines a two byte word */
-typedef unsigned short int UINT2;
-#define _UINT2_T
-
-/* UINT4 defines a four byte word */
-#if defined(__alpha) && (defined(__osf__) || defined(__linux__))
-typedef unsigned int UINT4;
-#else
-typedef unsigned long int UINT4;
-#endif
-#define _UINT4_T
-
 /* PROTO_LIST is defined depending on how PROTOTYPES is defined above.
    If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it
   returns an empty list.
@@ -82,8 +84,8 @@ typedef unsigned long int UINT4;
 
 /* MD4 context. */
 typedef struct {
-  UINT4 state[4];                                   /* state (ABCD) */
-  UINT4 count[2];        /* number of bits, modulo 2^64 (lsb first) */
+  uint32_t state[4];                                   /* state (ABCD) */
+  uint32_t count[2];        /* number of bits, modulo 2^64 (lsb first) */
   unsigned char buffer[64];                         /* input buffer */
 } MD4_CTX;
 
index fe2e39a..40b90c1 100644 (file)
@@ -3,6 +3,20 @@
 
 #ifndef _LRAD_PROTO_H
 #define _LRAD_PROTO_H
+#include "autoconf.h"
+
+#if HAVE_INTTYPES_H
+#include <inttypes.h>
+#endif
+
+#if HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#if HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
 /* GLOBAL.H - RSAREF types and constants
  */
 
@@ -25,20 +39,6 @@ typedef unsigned char *POINTER;
 #endif
 typedef const unsigned char *CONSTPOINTER;
 
-/* UINT2 defines a two byte word */
-#ifndef _UINT2_T
-typedef unsigned short int UINT2;
-#endif
-
-/* UINT4 defines a four byte word */
-#ifndef _UINT4_T
-#if defined(__alpha) && (defined(__osf__) || defined(__linux__))
-typedef unsigned int UINT4;
-#else
-typedef unsigned long int UINT4;
-#endif
-#endif
-
 /* PROTO_LIST is defined depending on how PROTOTYPES is defined above.
    If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it
   returns an empty list.
@@ -86,8 +86,8 @@ documentation and/or software.
 
 /* MD5 context. */
 typedef struct {
-  UINT4 state[4];                                   /* state (ABCD) */
-  UINT4 count[2];        /* number of bits, modulo 2^64 (lsb first) */
+  uint32_t state[4];                                   /* state (ABCD) */
+  uint32_t count[2];        /* number of bits, modulo 2^64 (lsb first) */
   unsigned char buffer[64];                         /* input buffer */
 } MD5_CTX;
 
index 7fd17aa..f3cabaf 100644 (file)
 #define S33 11
 #define S34 15
 
-static void MD4Transform PROTO_LIST ((UINT4 [4], const unsigned char [64]));
+static void MD4Transform PROTO_LIST ((uint32_t [4], const unsigned char [64]));
 static void Encode PROTO_LIST
-  ((unsigned char *, const UINT4 *, unsigned int));
+  ((unsigned char *, const uint32_t *, unsigned int));
 static void Decode PROTO_LIST
-  ((UINT4 *, const unsigned char *, unsigned int));
+  ((uint32_t *, const unsigned char *, unsigned int));
 static void MD4_memcpy PROTO_LIST ((POINTER, const POINTER, unsigned int));
 static void MD4_memset PROTO_LIST ((POINTER, int, unsigned int));
 
@@ -75,11 +75,11 @@ static unsigned char PADDING[64] = {
     (a) = ROTATE_LEFT ((a), (s)); \
   }
 #define GG(a, b, c, d, x, s) { \
-    (a) += G ((b), (c), (d)) + (x) + (UINT4)0x5a827999; \
+    (a) += G ((b), (c), (d)) + (x) + (uint32_t)0x5a827999; \
     (a) = ROTATE_LEFT ((a), (s)); \
   }
 #define HH(a, b, c, d, x, s) { \
-    (a) += H ((b), (c), (d)) + (x) + (UINT4)0x6ed9eba1; \
+    (a) += H ((b), (c), (d)) + (x) + (uint32_t)0x6ed9eba1; \
     (a) = ROTATE_LEFT ((a), (s)); \
   }
 
@@ -124,10 +124,10 @@ unsigned int inputLen;                     /* length of input block */
   /* Compute number of bytes mod 64 */
   buffindex = (unsigned int)((context->count[0] >> 3) & 0x3F);
   /* Update number of bits */
-  if ((context->count[0] += ((UINT4)inputLen << 3))
-      < ((UINT4)inputLen << 3))
+  if ((context->count[0] += ((uint32_t)inputLen << 3))
+      < ((uint32_t)inputLen << 3))
     context->count[1]++;
-  context->count[1] += ((UINT4)inputLen >> 29);
+  context->count[1] += ((uint32_t)inputLen >> 29);
 
   partLen = 64 - buffindex;
 
@@ -184,10 +184,10 @@ MD4_CTX *context;                                        /* context */
 /* MD4 basic transformation. Transforms state based on block.
  */
 static void MD4Transform (state, block)
-UINT4 state[4];
+uint32_t state[4];
 const unsigned char block[64];
 {
-  UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
+  uint32_t a = state[0], b = state[1], c = state[2], d = state[3], x[16];
 
   Decode (x, block, 64);
 
@@ -255,12 +255,12 @@ const unsigned char block[64];
   MD4_memset ((POINTER)x, 0, sizeof (x));
 }
 
-/* Encodes input (UINT4) into output (unsigned char). Assumes len is
+/* Encodes input (uint32_t) into output (unsigned char). Assumes len is
      a multiple of 4.
  */
 static void Encode (output, input, len)
 unsigned char *output;
-const UINT4 *input;
+const uint32_t *input;
 unsigned int len;
 {
   unsigned int i, j;
@@ -273,20 +273,20 @@ unsigned int len;
   }
 }
 
-/* Decodes input (unsigned char) into output (UINT4). Assumes len is
+/* Decodes input (unsigned char) into output (uint32_t). Assumes len is
      a multiple of 4.
  */
 static void Decode (output, input, len)
 
-UINT4 *output;
+uint32_t *output;
 const unsigned char *input;
 unsigned int len;
 {
   unsigned int i, j;
 
   for (i = 0, j = 0; j < len; i++, j += 4)
-    output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
-      (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
+    output[i] = ((uint32_t)input[j]) | (((uint32_t)input[j+1]) << 8) |
+      (((uint32_t)input[j+2]) << 16) | (((uint32_t)input[j+3]) << 24);
 }
 
 /* Note: Replace "for loop" with standard memcpy if possible.
index a9af185..b479903 100644 (file)
@@ -52,11 +52,11 @@ documentation and/or software.
 
 void librad_md5_calc(unsigned char *output, unsigned char *input,
                     unsigned int inputlen);
-static void MD5Transform PROTO_LIST ((UINT4 [4], const unsigned char [64]));
+static void MD5Transform PROTO_LIST ((uint32_t [4], const unsigned char [64]));
 static void Encode PROTO_LIST
-  ((unsigned char *, const UINT4 *, unsigned int));
+  ((unsigned char *, const uint32_t *, unsigned int));
 static void Decode PROTO_LIST
-  ((UINT4 *, const unsigned char *, unsigned int));
+  ((uint32_t *, const unsigned char *, unsigned int));
 static void MD5_memcpy PROTO_LIST ((POINTER, CONSTPOINTER, unsigned int));
 static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
 
@@ -81,22 +81,22 @@ static const unsigned char PADDING[64] = {
 Rotation is separate from addition to prevent recomputation.
  */
 #define FF(a, b, c, d, x, s, ac) { \
- (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) += F ((b), (c), (d)) + (x) + (uint32_t)(ac); \
  (a) = ROTATE_LEFT ((a), (s)); \
  (a) += (b); \
   }
 #define GG(a, b, c, d, x, s, ac) { \
- (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) += G ((b), (c), (d)) + (x) + (uint32_t)(ac); \
  (a) = ROTATE_LEFT ((a), (s)); \
  (a) += (b); \
   }
 #define HH(a, b, c, d, x, s, ac) { \
- (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) += H ((b), (c), (d)) + (x) + (uint32_t)(ac); \
  (a) = ROTATE_LEFT ((a), (s)); \
  (a) += (b); \
   }
 #define II(a, b, c, d, x, s, ac) { \
- (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
+ (a) += I ((b), (c), (d)) + (x) + (uint32_t)(ac); \
  (a) = ROTATE_LEFT ((a), (s)); \
  (a) += (b); \
   }
@@ -140,10 +140,10 @@ unsigned int inputLen;                     /* length of input block */
   idx = (unsigned int)((context->count[0] >> 3) & 0x3F);
 
   /* Update number of bits */
-  if ((context->count[0] += ((UINT4)inputLen << 3))
-   < ((UINT4)inputLen << 3))
+  if ((context->count[0] += ((uint32_t)inputLen << 3))
+   < ((uint32_t)inputLen << 3))
  context->count[1]++;
-  context->count[1] += ((UINT4)inputLen >> 29);
+  context->count[1] += ((uint32_t)inputLen >> 29);
 
   partLen = 64 - idx;
 
@@ -201,10 +201,10 @@ MD5_CTX *context;                                       /* context */
 /* MD5 basic transformation. Transforms state based on block.
  */
 static void MD5Transform (state, block)
-UINT4 state[4];
+uint32_t state[4];
 const unsigned char block[64];
 {
-  UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
+  uint32_t a = state[0], b = state[1], c = state[2], d = state[3], x[16];
 
   Decode (x, block, 64);
 
@@ -290,12 +290,12 @@ const unsigned char block[64];
   MD5_memset ((POINTER)x, 0, sizeof (x));
 }
 
-/* Encodes input (UINT4) into output (unsigned char). Assumes len is
+/* Encodes input (uint32_t) into output (unsigned char). Assumes len is
   a multiple of 4.
  */
 static void Encode (output, input, len)
 unsigned char *output;
-const UINT4 *input;
+const uint32_t *input;
 unsigned int len;
 {
   unsigned int i, j;
@@ -308,19 +308,19 @@ unsigned int len;
   }
 }
 
-/* Decodes input (unsigned char) into output (UINT4). Assumes len is
+/* Decodes input (unsigned char) into output (uint32_t). Assumes len is
   a multiple of 4.
  */
 static void Decode (output, input, len)
-UINT4 *output;
+uint32_t *output;
 const unsigned char *input;
 unsigned int len;
 {
   unsigned int i, j;
 
   for (i = 0, j = 0; j < len; i++, j += 4)
- output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
-   (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
+ output[i] = ((uint32_t)input[j]) | (((uint32_t)input[j+1]) << 8) |
+   (((uint32_t)input[j+2]) << 16) | (((uint32_t)input[j+3]) << 24);
 }
 
 /* Note: Replace "for loop" with standard memcpy if possible.