summaryrefslogtreecommitdiff
path: root/lib/libc/md/md4c.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1996-10-02 03:50:27 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1996-10-02 03:50:27 +0000
commit2d0181727eae9dd33e29514e34e5985fd08af1e5 (patch)
treea294735438c85c2e19ba1d12b68e434120e82b13 /lib/libc/md/md4c.c
parent3b4a19fe2a7ba832839e12ae75de1c5281a8c079 (diff)
All the world is not a pc, BYTE_ORDER define.
Diffstat (limited to 'lib/libc/md/md4c.c')
-rw-r--r--lib/libc/md/md4c.c77
1 files changed, 42 insertions, 35 deletions
diff --git a/lib/libc/md/md4c.c b/lib/libc/md/md4c.c
index 35f3b1ae27e..a65c0e8f15f 100644
--- a/lib/libc/md/md4c.c
+++ b/lib/libc/md/md4c.c
@@ -22,7 +22,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: md4c.c,v 1.3 1996/09/29 14:55:25 millert Exp $";
+static char rcsid[] = "$OpenBSD: md4c.c,v 1.4 1996/10/02 03:50:25 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <string.h>
@@ -48,10 +48,16 @@ typedef unsigned char *POINTER;
#define S34 15
static void MD4Transform __P ((u_int32_t [4], const unsigned char [64]));
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define Encode memcpy
+#define Decode memcpy
+#else /* BIG_ENDIAN */
static void Encode __P
((unsigned char *, u_int32_t *, unsigned int));
static void Decode __P
((u_int32_t *, const unsigned char *, unsigned int));
+#endif /* LITTLE_ENDIAN */
static unsigned char PADDING[64] = {
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -84,6 +90,41 @@ static unsigned char PADDING[64] = {
(a) = ROTATE_LEFT ((a), (s)); \
}
+#if BYTE_ORDER != LITTLE_ENDIAN
+/* Encodes input (u_int32_t) into output (unsigned char). Assumes len is
+ a multiple of 4.
+ */
+static void Encode (output, input, len)
+unsigned char *output;
+u_int32_t *input;
+unsigned int len;
+{
+ unsigned int i, j;
+
+ for (i = 0, j = 0; j < len; i++, j += 4) {
+ output[j] = (unsigned char)(input[i] & 0xff);
+ output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
+ output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
+ output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
+ }
+}
+
+/* Decodes input (unsigned char) into output (u_int32_t). Assumes len is
+ a multiple of 4.
+ */
+static void Decode (output, input, len)
+u_int32_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] = ((u_int32_t)input[j]) | (((u_int32_t)input[j+1]) << 8) |
+ (((u_int32_t)input[j+2]) << 16) | (((u_int32_t)input[j+3]) << 24);
+}
+#endif /* !LITTLE_ENDIAN */
+
/* MD4 initialization. Begins an MD4 operation, writing a new context.
*/
void MD4Init (context)
@@ -242,37 +283,3 @@ const unsigned char block[64];
*/
memset ((POINTER)x, 0, sizeof (x));
}
-
-/* Encodes input (u_int32_t) into output (unsigned char). Assumes len is
- a multiple of 4.
- */
-static void Encode (output, input, len)
-unsigned char *output;
-u_int32_t *input;
-unsigned int len;
-{
- unsigned int i, j;
-
- for (i = 0, j = 0; j < len; i++, j += 4) {
- output[j] = (unsigned char)(input[i] & 0xff);
- output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
- output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
- output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
- }
-}
-
-/* Decodes input (unsigned char) into output (u_int32_t). Assumes len is
- a multiple of 4.
- */
-static void Decode (output, input, len)
-
-u_int32_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] = ((u_int32_t)input[j]) | (((u_int32_t)input[j+1]) << 8) |
- (((u_int32_t)input[j+2]) << 16) | (((u_int32_t)input[j+3]) << 24);
-}