ben 2003/11/05 05:34:53
Modified: . configure.in
include apr.h.in
random/unix sha2.c sha2.h
test Makefile.in testall.c
threadproc/unix proc.c
Log:
Endianness and APR types for random.
Revision Changes Path
1.549 +5 -1 apr/configure.in
Index: configure.in
===================================================================
RCS file: /home/cvs/apr/configure.in,v
retrieving revision 1.548
retrieving revision 1.549
diff -u -r1.548 -r1.549
--- configure.in 4 Nov 2003 10:02:01 -0000 1.548
+++ configure.in 5 Nov 2003 13:34:52 -0000 1.549
@@ -100,7 +100,7 @@
DEFAULT_OSDIR="unix"
echo "(Default will be ${DEFAULT_OSDIR})"
-apr_modules="file_io network_io threadproc misc locks time mmap shmem user
memory atomic poll support"
+apr_modules="file_io network_io threadproc misc locks time mmap shmem user
memory atomic poll support random"
dnl Checks for programs.
AC_PROG_MAKE_SET
@@ -1188,6 +1188,9 @@
pid_t_fmt='#error Can not determine the proper size for pid_t'
fi
+dnl Checks for endianness
+AC_C_BIGENDIAN([bigendian=1],[bigendian=0])
+
# Basically, we have tried to figure out the correct format strings
# for APR types which vary between platforms, but we don't always get
# it right. If you find that we don't get it right for your platform,
@@ -1242,6 +1245,7 @@
AC_SUBST(pid_t_fmt)
AC_SUBST(int64_literal)
AC_SUBST(stdint)
+AC_SUBST(bigendian)
dnl ----------------------------- Checking for string functions
AC_CHECK_FUNCS(strnicmp, have_strnicmp="1", have_strnicmp="0")
1.130 +3 -0 apr/include/apr.h.in
Index: apr.h.in
===================================================================
RCS file: /home/cvs/apr/include/apr.h.in,v
retrieving revision 1.129
retrieving revision 1.130
diff -u -r1.129 -r1.130
--- apr.h.in 15 Oct 2003 13:34:25 -0000 1.129
+++ apr.h.in 5 Nov 2003 13:34:52 -0000 1.130
@@ -305,6 +305,9 @@
#define APR_SIZEOF_VOIDP @voidp_size@
+/* Are we big endian? */
+#define APR_IS_BIGENDIAN @bigendian@
+
/* Mechanisms to properly type numeric literals */
@int64_literal@
1.3 +26 -83 apr/random/unix/sha2.c
Index: sha2.c
===================================================================
RCS file: /home/cvs/apr/random/unix/sha2.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- sha2.c 5 Nov 2003 12:05:28 -0000 1.2
+++ sha2.c 5 Nov 2003 13:34:53 -0000 1.3
@@ -82,67 +82,10 @@
*
*/
-
/*** SHA-256/384/512 Machine Architecture Definitions *****************/
-/*
- * BYTE_ORDER NOTE:
- *
- * Please make sure that your system defines BYTE_ORDER. If your
- * architecture is little-endian, make sure it also defines
- * LITTLE_ENDIAN and that the two (BYTE_ORDER and LITTLE_ENDIAN) are
- * equivilent.
- *
- * If your system does not define the above, then you can do so by
- * hand like this:
- *
- * #define LITTLE_ENDIAN 1234
- * #define BIG_ENDIAN 4321
- *
- * And for little-endian machines, add:
- *
- * #define BYTE_ORDER LITTLE_ENDIAN
- *
- * Or for big-endian machines:
- *
- * #define BYTE_ORDER BIG_ENDIAN
- *
- * The FreeBSD machine this was written on defines BYTE_ORDER
- * appropriately by including <sys/types.h> (which in turn includes
- * <machine/endian.h> where the appropriate definitions are actually
- * made).
- */
-#if !defined(BYTE_ORDER) || (BYTE_ORDER != LITTLE_ENDIAN && BYTE_ORDER !=
BIG_ENDIAN)
-#error Define BYTE_ORDER to be equal to either LITTLE_ENDIAN or BIG_ENDIAN
-#endif
-
-/*
- * Define the followingsha2_* types to types of the correct length on
- * the native archtecture. Most BSD systems and Linux define u_intXX_t
- * types. Machines with very recent ANSI C headers, can use the
- * uintXX_t definintions from inttypes.h by defining SHA2_USE_INTTYPES_H
- * during compile or in the sha.h header file.
- *
- * Machines that support neither u_intXX_t nor inttypes.h's uintXX_t
- * will need to define these three typedefs below (and the appropriate
- * ones in sha.h too) by hand according to their system architecture.
- *
- * Thank you, Jun-ichiro itojun Hagino, for suggesting using u_intXX_t
- * types and pointing out recent ANSI C support for uintXX_t in inttypes.h.
- */
-#ifdef SHA2_USE_INTTYPES_H
-
-typedef uint8_t sha2_byte; /* Exactly 1 byte */
-typedef uint32_t sha2_word32; /* Exactly 4 bytes */
-typedef uint64_t sha2_word64; /* Exactly 8 bytes */
-
-#else /* SHA2_USE_INTTYPES_H */
-
-typedef u_int8_t sha2_byte; /* Exactly 1 byte */
-typedef u_int32_t sha2_word32; /* Exactly 4 bytes */
-typedef u_int64_t sha2_word64; /* Exactly 8 bytes */
-
-#endif /* SHA2_USE_INTTYPES_H */
-
+typedef apr_byte_t sha2_byte; /* Exactly 1 byte */
+typedef apr_uint32_t sha2_word32; /* Exactly 4 bytes */
+typedef apr_uint64_t sha2_word64; /* Exactly 8 bytes */
/*** SHA-256/384/512 Various Length Definitions ***********************/
/* NOTE: Most of these are in sha2.h */
@@ -152,7 +95,7 @@
/*** ENDIAN REVERSAL MACROS *******************************************/
-#if BYTE_ORDER == LITTLE_ENDIAN
+#if !APR_IS_BIGENDIAN
#define REVERSE32(w,x) { \
sha2_word32 tmp = (w); \
tmp = (tmp >> 16) | (tmp << 16); \
@@ -166,7 +109,7 @@
(x) = ((tmp & 0xffff0000ffff0000ULL) >> 16) | \
((tmp & 0x0000ffff0000ffffULL) << 16); \
}
-#endif /* BYTE_ORDER == LITTLE_ENDIAN */
+#endif /* !APR_IS_BIGENDIAN */
/*
* Macro for incrementally adding the unsigned 64-bit integer n to the
@@ -372,7 +315,7 @@
/* Unrolled SHA-256 round macros: */
-#if BYTE_ORDER == LITTLE_ENDIAN
+#if !APR_IS_BIGENDIAN
#define ROUND256_0_TO_15(a,b,c,d,e,f,g,h) \
REVERSE32(*data++, W256[j]); \
@@ -383,7 +326,7 @@
j++
-#else /* BYTE_ORDER == LITTLE_ENDIAN */
+#else /* APR_IS_BIGENDIAN */
#define ROUND256_0_TO_15(a,b,c,d,e,f,g,h) \
T1 = (h) + Sigma1_256(e) + Ch((e), (f), (g)) + \
@@ -392,7 +335,7 @@
(h) = T1 + Sigma0_256(a) + Maj((a), (b), (c)); \
j++
-#endif /* BYTE_ORDER == LITTLE_ENDIAN */
+#endif /* APR_IS_BIGENDIAN */
#define ROUND256(a,b,c,d,e,f,g,h) \
s0 = W256[(j+1)&0x0f]; \
@@ -482,15 +425,15 @@
j = 0;
do {
-#if BYTE_ORDER == LITTLE_ENDIAN
+#if !APR_IS_BIGENDIAN
/* Copy data while converting to host byte order */
REVERSE32(*data++,W256[j]);
/* Apply the SHA-256 compression function to update a..h */
T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] + W256[j];
-#else /* BYTE_ORDER == LITTLE_ENDIAN */
+#else /* APR_IS_BIGENDIAN */
/* Apply the SHA-256 compression function to update a..h with
copy */
T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] + (W256[j] =
*data++);
-#endif /* BYTE_ORDER == LITTLE_ENDIAN */
+#endif /* APR_IS_BIGENDIAN */
T2 = Sigma0_256(a) + Maj(a, b, c);
h = g;
g = f;
@@ -601,7 +544,7 @@
/* If no digest buffer is passed, we don't bother doing this: */
if (digest != (sha2_byte*)0) {
usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH;
-#if BYTE_ORDER == LITTLE_ENDIAN
+#if !APR_IS_BIGENDIAN
/* Convert FROM host byte order */
REVERSE64(context->bitcount,context->bitcount);
#endif
@@ -635,7 +578,7 @@
/* Final transform: */
SHA256_Transform(context, (sha2_word32*)context->buffer);
-#if BYTE_ORDER == LITTLE_ENDIAN
+#if !APR_IS_BIGENDIAN
{
/* Convert TO host byte order */
int j;
@@ -699,7 +642,7 @@
#ifdef SHA2_UNROLL_TRANSFORM
/* Unrolled SHA-512 round macros: */
-#if BYTE_ORDER == LITTLE_ENDIAN
+#if !APR_IS_BIGENDIAN
#define ROUND512_0_TO_15(a,b,c,d,e,f,g,h) \
REVERSE64(*data++, W512[j]); \
@@ -710,7 +653,7 @@
j++
-#else /* BYTE_ORDER == LITTLE_ENDIAN */
+#else /* APR_IS_BIGENDIAN */
#define ROUND512_0_TO_15(a,b,c,d,e,f,g,h) \
T1 = (h) + Sigma1_512(e) + Ch((e), (f), (g)) + \
@@ -719,7 +662,7 @@
(h) = T1 + Sigma0_512(a) + Maj((a), (b), (c)); \
j++
-#endif /* BYTE_ORDER == LITTLE_ENDIAN */
+#endif /* APR_IS_BIGENDIAN */
#define ROUND512(a,b,c,d,e,f,g,h) \
s0 = W512[(j+1)&0x0f]; \
@@ -804,15 +747,15 @@
j = 0;
do {
-#if BYTE_ORDER == LITTLE_ENDIAN
+#if !APR_IS_BIGENDIAN
/* Convert TO host byte order */
REVERSE64(*data++, W512[j]);
/* Apply the SHA-512 compression function to update a..h */
T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] + W512[j];
-#else /* BYTE_ORDER == LITTLE_ENDIAN */
+#else /* APR_IS_BIGENDIAN */
/* Apply the SHA-512 compression function to update a..h with
copy */
T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] + (W512[j] =
*data++);
-#endif /* BYTE_ORDER == LITTLE_ENDIAN */
+#endif /* APR_IS_BIGENDIAN */
T2 = Sigma0_512(a) + Maj(a, b, c);
h = g;
g = f;
@@ -917,7 +860,7 @@
unsigned int usedspace;
usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH;
-#if BYTE_ORDER == LITTLE_ENDIAN
+#if !APR_IS_BIGENDIAN
/* Convert FROM host byte order */
REVERSE64(context->bitcount[0],context->bitcount[0]);
REVERSE64(context->bitcount[1],context->bitcount[1]);
@@ -965,7 +908,7 @@
SHA512_Last(context);
/* Save the hash data for output: */
-#if BYTE_ORDER == LITTLE_ENDIAN
+#if !APR_IS_BIGENDIAN
{
/* Convert TO host byte order */
int j;
@@ -974,9 +917,9 @@
*d++ = context->state[j];
}
}
-#else
+#else /* APR_IS_BIGENDIAN */
MEMCPY_BCOPY(d, context->state, SHA512_DIGEST_LENGTH);
-#endif
+#endif /* APR_IS_BIGENDIAN */
}
/* Zero out state data */
@@ -1040,7 +983,7 @@
SHA512_Last((SHA512_CTX*)context);
/* Save the hash data for output: */
-#if BYTE_ORDER == LITTLE_ENDIAN
+#if !APR_IS_BIGENDIAN
{
/* Convert TO host byte order */
int j;
@@ -1049,9 +992,9 @@
*d++ = context->state[j];
}
}
-#else
+#else /* APR_IS_BIGENDIAN */
MEMCPY_BCOPY(d, context->state, SHA384_DIGEST_LENGTH);
-#endif
+#endif /* APR_IS_BIGENDIAN */
}
/* Zero out state data */
1.3 +26 -125 apr/random/unix/sha2.h
Index: sha2.h
===================================================================
RCS file: /home/cvs/apr/random/unix/sha2.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- sha2.h 5 Nov 2003 12:05:28 -0000 1.2
+++ sha2.h 5 Nov 2003 13:34:53 -0000 1.3
@@ -65,20 +65,7 @@
extern "C" {
#endif
-
-/*
- * Import u_intXX_t size_t type definitions from system headers. You
- * may need to change this, or define these things yourself in this
- * file.
- */
-#include <sys/types.h>
-
-#ifdef SHA2_USE_INTTYPES_H
-
-#include <inttypes.h>
-
-#endif /* SHA2_USE_INTTYPES_H */
-
+#include "apr.h"
/*** SHA-256/384/512 Various Length Definitions ***********************/
#define SHA256_BLOCK_LENGTH 64
@@ -93,127 +80,41 @@
/*** SHA-256/384/512 Context Structures *******************************/
-/* NOTE: If your architecture does not define either u_intXX_t types or
- * uintXX_t (from inttypes.h), you may need to define things by hand
- * for your system:
- */
-#if 0
-typedef unsigned char u_int8_t; /* 1-byte (8-bits) */
-typedef unsigned int u_int32_t; /* 4-bytes (32-bits) */
-typedef unsigned long long u_int64_t; /* 8-bytes (64-bits) */
-#endif
-/*
- * Most BSD systems already define u_intXX_t types, as does Linux.
- * Some systems, however, like Compaq's Tru64 Unix instead can use
- * uintXX_t types defined by very recent ANSI C standards and included
- * in the file:
- *
- * #include <inttypes.h>
- *
- * If you choose to use <inttypes.h> then please define:
- *
- * #define SHA2_USE_INTTYPES_H
- *
- * Or on the command line during compile:
- *
- * cc -DSHA2_USE_INTTYPES_H ...
- */
-#ifdef SHA2_USE_INTTYPES_H
-
-typedef struct _SHA256_CTX {
- uint32_t state[8];
- uint64_t bitcount;
- uint8_t buffer[SHA256_BLOCK_LENGTH];
-} SHA256_CTX;
-typedef struct _SHA512_CTX {
- uint64_t state[8];
- uint64_t bitcount[2];
- uint8_t buffer[SHA512_BLOCK_LENGTH];
-} SHA512_CTX;
-
-#else /* SHA2_USE_INTTYPES_H */
-
typedef struct _SHA256_CTX {
- u_int32_t state[8];
- u_int64_t bitcount;
- u_int8_t buffer[SHA256_BLOCK_LENGTH];
+ apr_uint32_t state[8];
+ apr_uint64_t bitcount;
+ apr_byte_t buffer[SHA256_BLOCK_LENGTH];
} SHA256_CTX;
typedef struct _SHA512_CTX {
- u_int64_t state[8];
- u_int64_t bitcount[2];
- u_int8_t buffer[SHA512_BLOCK_LENGTH];
+ apr_uint64_t state[8];
+ apr_uint64_t bitcount[2];
+ apr_byte_t buffer[SHA512_BLOCK_LENGTH];
} SHA512_CTX;
-#endif /* SHA2_USE_INTTYPES_H */
-
typedef SHA512_CTX SHA384_CTX;
/*** SHA-256/384/512 Function Prototypes ******************************/
-#ifndef NOPROTO
-#ifdef SHA2_USE_INTTYPES_H
-
void SHA256_Init(SHA256_CTX *);
-void SHA256_Update(SHA256_CTX*, const uint8_t*, size_t);
-void SHA256_Final(uint8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*);
-char* SHA256_End(SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]);
-char* SHA256_Data(const uint8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]);
-
-void SHA384_Init(SHA384_CTX*);
-void SHA384_Update(SHA384_CTX*, const uint8_t*, size_t);
-void SHA384_Final(uint8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*);
-char* SHA384_End(SHA384_CTX*, char[SHA384_DIGEST_STRING_LENGTH]);
-char* SHA384_Data(const uint8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH]);
-
-void SHA512_Init(SHA512_CTX*);
-void SHA512_Update(SHA512_CTX*, const uint8_t*, size_t);
-void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*);
-char* SHA512_End(SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]);
-char* SHA512_Data(const uint8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]);
-
-#else /* SHA2_USE_INTTYPES_H */
-
-void SHA256_Init(SHA256_CTX *);
-void SHA256_Update(SHA256_CTX*, const u_int8_t*, size_t);
-void SHA256_Final(u_int8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*);
-char* SHA256_End(SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]);
-char* SHA256_Data(const u_int8_t*, size_t,
char[SHA256_DIGEST_STRING_LENGTH]);
-
-void SHA384_Init(SHA384_CTX*);
-void SHA384_Update(SHA384_CTX*, const u_int8_t*, size_t);
-void SHA384_Final(u_int8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*);
-char* SHA384_End(SHA384_CTX*, char[SHA384_DIGEST_STRING_LENGTH]);
-char* SHA384_Data(const u_int8_t*, size_t,
char[SHA384_DIGEST_STRING_LENGTH]);
-
-void SHA512_Init(SHA512_CTX*);
-void SHA512_Update(SHA512_CTX*, const u_int8_t*, size_t);
-void SHA512_Final(u_int8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*);
-char* SHA512_End(SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]);
-char* SHA512_Data(const u_int8_t*, size_t,
char[SHA512_DIGEST_STRING_LENGTH]);
-
-#endif /* SHA2_USE_INTTYPES_H */
-
-#else /* NOPROTO */
-
-void SHA256_Init();
-void SHA256_Update();
-void SHA256_Final();
-char* SHA256_End();
-char* SHA256_Data();
-
-void SHA384_Init();
-void SHA384_Update();
-void SHA384_Final();
-char* SHA384_End();
-char* SHA384_Data();
-
-void SHA512_Init();
-void SHA512_Update();
-void SHA512_Final();
-char* SHA512_End();
-char* SHA512_Data();
-
-#endif /* NOPROTO */
+void SHA256_Update(SHA256_CTX *, const apr_byte_t *, size_t);
+void SHA256_Final(apr_byte_t [SHA256_DIGEST_LENGTH], SHA256_CTX *);
+char* SHA256_End(SHA256_CTX *, char [SHA256_DIGEST_STRING_LENGTH]);
+char* SHA256_Data(const apr_byte_t *, size_t,
+ char [SHA256_DIGEST_STRING_LENGTH]);
+
+void SHA384_Init(SHA384_CTX *);
+void SHA384_Update(SHA384_CTX *, const apr_byte_t *, size_t);
+void SHA384_Final(apr_byte_t [SHA384_DIGEST_LENGTH], SHA384_CTX *);
+char* SHA384_End(SHA384_CTX *, char [SHA384_DIGEST_STRING_LENGTH]);
+char* SHA384_Data(const apr_byte_t *, size_t,
+ char [SHA384_DIGEST_STRING_LENGTH]);
+
+void SHA512_Init(SHA512_CTX *);
+void SHA512_Update(SHA512_CTX *, const apr_byte_t *, size_t);
+void SHA512_Final(apr_byte_t [SHA512_DIGEST_LENGTH], SHA512_CTX *);
+char* SHA512_End(SHA512_CTX *, char [SHA512_DIGEST_STRING_LENGTH]);
+char* SHA512_Data(const apr_byte_t *, size_t,
+ char [SHA512_DIGEST_STRING_LENGTH]);
#ifdef __cplusplus
}
1.144 +1 -1 apr/test/Makefile.in
Index: Makefile.in
===================================================================
RCS file: /home/cvs/apr/test/Makefile.in,v
retrieving revision 1.143
retrieving revision 1.144
diff -u -r1.143 -r1.144
--- Makefile.in 5 Nov 2003 09:16:44 -0000 1.143
+++ Makefile.in 5 Nov 2003 13:34:53 -0000 1.144
@@ -115,7 +115,7 @@
testdso.lo testoc.lo testdup.lo testsockets.lo testproc.lo \
testpoll.lo testlock.lo testsockopt.lo testpipe.lo testthread.lo \
testhash.lo testargs.lo testnames.lo testuser.lo testpath.lo \
- testenv.lo testprocmutex.lo
+ testenv.lo testprocmutex.lo testrand2.lo
testall: $(TESTS) mod_test.la libmod_test.la [EMAIL PROTECTED]@ \
[EMAIL PROTECTED]@ CuTest.lo [EMAIL PROTECTED]@ $(LOCAL_LIBS)
1.47 +1 -0 apr/test/testall.c
Index: testall.c
===================================================================
RCS file: /home/cvs/apr/test/testall.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- testall.c 5 Nov 2003 09:16:44 -0000 1.46
+++ testall.c 5 Nov 2003 13:34:53 -0000 1.47
@@ -95,6 +95,7 @@
{"testdup", testdup},
{"testdir", testdir},
{"testrand", testrand},
+ {"testrand2", testrand2},
{"testdso", testdso},
{"testoc", testoc},
{"testsockets", testsockets},
1.70 +2 -0 apr/threadproc/unix/proc.c
Index: proc.c
===================================================================
RCS file: /home/cvs/apr/threadproc/unix/proc.c,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -r1.69 -r1.70
--- proc.c 5 Nov 2003 09:16:44 -0000 1.69
+++ proc.c 5 Nov 2003 13:34:53 -0000 1.70
@@ -233,6 +233,8 @@
proc->out = NULL;
proc->err = NULL;
+ apr_random_after_fork(proc);
+
return APR_INCHILD;
}