From 357101793b8722e2e59994189520f823601d5afd Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Wed, 17 Nov 1999 02:04:06 +0000 Subject: [PATCH] Use lber types instead of uint32 for md5. sha1 still requires an integer type of exactly 32 bits. --- configure | 106 ++++++++++++++++++--------------------- configure.in | 6 +-- include/ac/bytes.h | 17 ++++--- include/lber.h | 21 -------- include/lber_types.h.in | 27 ++++++++++ include/lutil_md5.h | 18 +++---- include/lutil_sha1.h | 4 -- libraries/liblutil/md5.c | 18 +++---- 8 files changed, 104 insertions(+), 113 deletions(-) diff --git a/configure b/configure index 64efd14439..3a30f69598 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # $OpenLDAP$ -# from OpenLDAP: pkg/ldap/configure.in,v 1.275 1999/11/02 01:10:37 kdz Exp +# from OpenLDAP: pkg/ldap/configure.in,v 1.276 1999/11/02 01:32:56 kdz Exp # Copyright 1998,1999 The OpenLDAP Foundation. All Rights Reserved. # @@ -14104,14 +14104,6 @@ if test "$ac_cv_sizeof_int" -lt 4 ; then cat >> confdefs.h <<\EOF #define LBER_INT_T long -EOF - - cat >> confdefs.h <<\EOF -#define LBER_TAG_T long -EOF - - cat >> confdefs.h <<\EOF -#define LBER_SOCKET_T int EOF else @@ -14119,23 +14111,23 @@ else #define LBER_INT_T int EOF - cat >> confdefs.h <<\EOF -#define LBER_TAG_T long +fi + +cat >> confdefs.h <<\EOF +#define LBER_LEN_T long EOF - cat >> confdefs.h <<\EOF +cat >> confdefs.h <<\EOF #define LBER_SOCKET_T int EOF -fi - cat >> confdefs.h <<\EOF -#define LBER_LEN_T long +#define LBER_TAG_T long EOF echo $ac_n "checking for 8-bit clean memcmp""... $ac_c" 1>&6 -echo "configure:14139: checking for 8-bit clean memcmp" >&5 +echo "configure:14131: checking for 8-bit clean memcmp" >&5 if eval "test \"\${ac_cv_func_memcmp_clean+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -14143,7 +14135,7 @@ else ac_cv_func_memcmp_clean=no else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:14149: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then ac_cv_func_memcmp_clean=yes else @@ -14171,12 +14163,12 @@ echo "$ac_t""$ac_cv_func_memcmp_clean" 1>&6 test $ac_cv_func_memcmp_clean = no && LIBOBJS="$LIBOBJS memcmp.${ac_objext}" echo $ac_n "checking for strftime""... $ac_c" 1>&6 -echo "configure:14175: checking for strftime" >&5 +echo "configure:14167: checking for strftime" >&5 if eval "test \"\${ac_cv_func_strftime+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:14196: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_strftime=yes" else @@ -14222,7 +14214,7 @@ else echo "$ac_t""no" 1>&6 # strftime is in -lintl on SCO UNIX. echo $ac_n "checking for strftime in -lintl""... $ac_c" 1>&6 -echo "configure:14226: checking for strftime in -lintl" >&5 +echo "configure:14218: checking for strftime in -lintl" >&5 ac_lib_var=`echo intl'_'strftime | sed 'y%./+-:%__p__%'` if eval "test \"\${ac_cv_lib_$ac_lib_var+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -14230,7 +14222,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lintl $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:14237: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -14269,12 +14261,12 @@ fi echo $ac_n "checking for inet_aton()""... $ac_c" 1>&6 -echo "configure:14273: checking for inet_aton()" >&5 +echo "configure:14265: checking for inet_aton()" >&5 if eval "test \"\${ol_cv_func_inet_aton+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:14292: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* ol_cv_func_inet_aton=yes else @@ -14318,12 +14310,12 @@ EOF echo $ac_n "checking for _spawnlp""... $ac_c" 1>&6 -echo "configure:14322: checking for _spawnlp" >&5 +echo "configure:14314: checking for _spawnlp" >&5 if eval "test \"\${ac_cv_func__spawnlp+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:14343: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func__spawnlp=yes" else @@ -14371,12 +14363,12 @@ fi echo $ac_n "checking for _snprintf""... $ac_c" 1>&6 -echo "configure:14375: checking for _snprintf" >&5 +echo "configure:14367: checking for _snprintf" >&5 if eval "test \"\${ac_cv_func__snprintf+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:14396: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func__snprintf=yes" else @@ -14426,12 +14418,12 @@ fi echo $ac_n "checking for _vsnprintf""... $ac_c" 1>&6 -echo "configure:14430: checking for _vsnprintf" >&5 +echo "configure:14422: checking for _vsnprintf" >&5 if eval "test \"\${ac_cv_func__vsnprintf+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:14451: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func__vsnprintf=yes" else @@ -14481,12 +14473,12 @@ fi echo $ac_n "checking for vprintf""... $ac_c" 1>&6 -echo "configure:14485: checking for vprintf" >&5 +echo "configure:14477: checking for vprintf" >&5 if eval "test \"\${ac_cv_func_vprintf+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:14506: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_vprintf=yes" else @@ -14534,12 +14526,12 @@ fi if test "$ac_cv_func_vprintf" != yes; then echo $ac_n "checking for _doprnt""... $ac_c" 1>&6 -echo "configure:14538: checking for _doprnt" >&5 +echo "configure:14530: checking for _doprnt" >&5 if eval "test \"\${ac_cv_func__doprnt+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:14559: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func__doprnt=yes" else @@ -14592,12 +14584,12 @@ if test $ac_cv_func_vprintf = yes ; then for ac_func in vsnprintf vsprintf do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:14596: checking for $ac_func" >&5 +echo "configure:14588: checking for $ac_func" >&5 if eval "test \"\${ac_cv_func_$ac_func+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:14617: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -14698,12 +14690,12 @@ for ac_func in \ do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:14702: checking for $ac_func" >&5 +echo "configure:14694: checking for $ac_func" >&5 if eval "test \"\${ac_cv_func_$ac_func+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:14723: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -14755,12 +14747,12 @@ done for ac_func in getopt tempnam do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:14759: checking for $ac_func" >&5 +echo "configure:14751: checking for $ac_func" >&5 if eval "test \"\${ac_cv_func_$ac_func+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:14780: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -14821,13 +14813,13 @@ fi # Check Configuration echo $ac_n "checking declaration of sys_errlist""... $ac_c" 1>&6 -echo "configure:14825: checking declaration of sys_errlist" >&5 +echo "configure:14817: checking declaration of sys_errlist" >&5 if eval "test \"\${ol_cv_dcl_sys_errlist+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < @@ -14840,7 +14832,7 @@ int main() { char *c = (char *) *sys_errlist ; return 0; } EOF -if { (eval echo configure:14844: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:14836: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ol_cv_dcl_sys_errlist=yes ol_cv_have_sys_errlist=yes @@ -14863,20 +14855,20 @@ EOF echo $ac_n "checking existence of sys_errlist""... $ac_c" 1>&6 -echo "configure:14867: checking existence of sys_errlist" >&5 +echo "configure:14859: checking existence of sys_errlist" >&5 if eval "test \"\${ol_cv_have_sys_errlist+set}\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < int main() { char *c = (char *) *sys_errlist ; return 0; } EOF -if { (eval echo configure:14880: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:14872: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* ol_cv_have_sys_errlist=yes else diff --git a/configure.in b/configure.in index 0d6d7f70df..08759eb747 100644 --- a/configure.in +++ b/configure.in @@ -1949,15 +1949,13 @@ if test "$ac_cv_sizeof_int" -lt 4 ; then AC_MSG_WARN([OpenLDAP requires 'int' to be 32 bits or greater.]) AC_DEFINE(LBER_INT_T,long) - AC_DEFINE(LBER_TAG_T,long) - AC_DEFINE(LBER_SOCKET_T,int) else AC_DEFINE(LBER_INT_T,int) - AC_DEFINE(LBER_TAG_T,long) - AC_DEFINE(LBER_SOCKET_T,int) fi AC_DEFINE(LBER_LEN_T,long) +AC_DEFINE(LBER_SOCKET_T,int) +AC_DEFINE(LBER_TAG_T,long) dnl ---------------------------------------------------------------- dnl Checks for library functions. diff --git a/include/ac/bytes.h b/include/ac/bytes.h index 27dab6b7b2..10398c38be 100644 --- a/include/ac/bytes.h +++ b/include/ac/bytes.h @@ -15,7 +15,7 @@ /* cross compilers should define both AC_INT{2,4}_TYPE in CPPFLAGS */ -#if !defined( AC_INT4_TYPE ) || !defined( AC_INT2_TYPE ) +#if !defined( AC_INT4_TYPE ) /* use autoconf defines to provide sized typedefs */ # if SIZEOF_LONG == 4 # define AC_INT4_TYPE long @@ -26,7 +26,13 @@ # else # error "AC_INT4_TYPE?" # endif +#endif + +typedef AC_INT4_TYPE ac_int4; +typedef signed AC_INT4_TYPE ac_sint4; +typedef unsigned AC_INT4_TYPE ac_uint4; +#if !defined( AC_INT4_TYPE ) # if SIZEOF_SHORT == 2 # define AC_INT2_TYPE short # elif SIZEOF_INT == 2 @@ -34,17 +40,16 @@ # elif SIZEOF_LONG == 2 # define AC_INT2_TYPE long # else -# error "AC_INT2_TYPE?" +/* not used, no error */ +/* # error "AC_INT2_TYPE?" */ # endif #endif -typedef AC_INT4_TYPE ac_int4; -typedef signed AC_INT4_TYPE ac_sint4; -typedef unsigned AC_INT4_TYPE ac_uint4; - +#if defined( AC_INT2_TYPE ) typedef AC_INT2_TYPE ac_int2; typedef signed AC_INT2_TYPE ac_sint2; typedef unsigned AC_INT2_TYPE ac_uint2; +#endif #ifndef BYTE_ORDER /* cross compilers should define BYTE_ORDER in CPPFLAGS */ diff --git a/include/lber.h b/include/lber.h index 02a93cf5aa..d960f2c2fe 100644 --- a/include/lber.h +++ b/include/lber.h @@ -23,31 +23,10 @@ #ifndef _LBER_H #define _LBER_H -#include #include LDAP_BEGIN_DECL -/* booleans, enumerations, and integers */ -typedef LBER_INT_T ber_int_t; - -/* signed and unsigned versions */ -typedef signed LBER_INT_T ber_sint_t; -typedef unsigned LBER_INT_T ber_uint_t; - -/* tags */ -typedef unsigned LBER_TAG_T ber_tag_t; - -/* "socket" descriptors */ -typedef LBER_SOCKET_T ber_socket_t; - -/* lengths */ -typedef unsigned LBER_LEN_T ber_len_t; - -/* signed lengths */ -typedef signed LBER_LEN_T ber_slen_t; - - /* Overview of LBER tag construction * * Bits diff --git a/include/lber_types.h.in b/include/lber_types.h.in index 64adffbda5..218202e685 100644 --- a/include/lber_types.h.in +++ b/include/lber_types.h.in @@ -9,6 +9,8 @@ * in file LICENSE in the top-level directory of the distribution. */ +#include + /* * LBER types */ @@ -16,6 +18,8 @@ #ifndef _LBER_TYPES_H #define _LBER_TYPES_H +LDAP_BEGIN_DECL + /* LBER boolean, enum, integers (32 bits or larger) */ #undef LBER_INT_T @@ -28,4 +32,27 @@ /* LBER lengths (32 bits or larger) */ #undef LBER_LEN_T +/* ------------------------------------------------------------ */ + +/* booleans, enumerations, and integers */ +typedef LBER_INT_T ber_int_t; + +/* signed and unsigned versions */ +typedef signed LBER_INT_T ber_sint_t; +typedef unsigned LBER_INT_T ber_uint_t; + +/* tags */ +typedef unsigned LBER_TAG_T ber_tag_t; + +/* "socket" descriptors */ +typedef LBER_SOCKET_T ber_socket_t; + +/* lengths */ +typedef unsigned LBER_LEN_T ber_len_t; + +/* signed lengths */ +typedef signed LBER_LEN_T ber_slen_t; + +LDAP_END_DECL + #endif /* _LBER_TYPES_H */ diff --git a/include/lutil_md5.h b/include/lutil_md5.h index 1d06b74c82..4c6a37beee 100644 --- a/include/lutil_md5.h +++ b/include/lutil_md5.h @@ -14,25 +14,19 @@ #ifndef _LUTIL_MD5_H_ #define _LUTIL_MD5_H_ -#include -#include +#include LDAP_BEGIN_DECL -/* Unlike previous versions of this code, uint32 need not be exactly +/* Unlike previous versions of this code, ber_int_t need not be exactly 32 bits, merely 32 bits or more. Choosing a data type which is 32 bits instead of 64 is not important; speed is considerably more important. ANSI guarantees that "unsigned long" will be big enough, and always using it seems to have few disadvantages. */ -#ifndef LDAP_UINT32 -#define LDAP_UINT32 1 -typedef ac_uint4 uint32; -#endif - struct lutil_MD5Context { - uint32 buf[4]; - uint32 bits[2]; + ber_uint_t buf[4]; + ber_uint_t bits[2]; unsigned char in[64]; }; @@ -53,7 +47,7 @@ LDAP_F( void ) lutil_MD5Update LDAP_P(( struct lutil_MD5Context *context, unsigned char const *buf, - unsigned len)); + ber_len_t len)); LDAP_F( void ) lutil_MD5Final LDAP_P(( @@ -62,7 +56,7 @@ lutil_MD5Final LDAP_P(( LDAP_F( void ) lutil_MD5Transform LDAP_P(( - uint32 buf[4], + ber_uint_t buf[4], const unsigned char in[64])); /* diff --git a/include/lutil_sha1.h b/include/lutil_sha1.h index cd2430c8d8..631f7c07b8 100644 --- a/include/lutil_sha1.h +++ b/include/lutil_sha1.h @@ -26,11 +26,7 @@ LDAP_BEGIN_DECL */ /* This code assumes char are 8-bits and uint32 are 32-bits */ - -#ifndef LDAP_UINT32 -#define LDAP_UINT32 1 typedef ac_uint4 uint32; -#endif typedef struct { uint32 state[5]; diff --git a/libraries/liblutil/md5.c b/libraries/liblutil/md5.c index 6758de0240..e1d316a459 100644 --- a/libraries/liblutil/md5.c +++ b/libraries/liblutil/md5.c @@ -44,12 +44,12 @@ #include /* Little-endian byte-swapping routines. Note that these do not - depend on the size of datatypes such as uint32, nor do they require + depend on the size of datatypes such as ber_uint_t, nor do they require us to detect the endianness of the machine we are running on. It is possible they should be macros for speed, but I would be surprised if they were a performance bottleneck for MD5. */ -static uint32 +static ber_uint_t getu32( const unsigned char *addr ) { return (((((unsigned long)addr[3] << 8) | addr[2]) << 8) @@ -57,7 +57,7 @@ getu32( const unsigned char *addr ) } static void -putu32( uint32 data, unsigned char *addr ) +putu32( ber_uint_t data, unsigned char *addr ) { addr[0] = (unsigned char)data; addr[1] = (unsigned char)(data >> 8); @@ -89,15 +89,15 @@ void lutil_MD5Update( struct lutil_MD5Context *ctx, const unsigned char *buf, - unsigned int len + ber_len_t len ) { - uint32 t; + ber_uint_t t; /* Update bitcount */ t = ctx->bits[0]; - if ((ctx->bits[0] = (t + ((uint32)len << 3)) & 0xffffffff) < t) + if ((ctx->bits[0] = (t + ((ber_uint_t)len << 3)) & 0xffffffff) < t) ctx->bits[1]++; /* Carry from low to high */ ctx->bits[1] += len >> 29; @@ -199,10 +199,10 @@ lutil_MD5Final( unsigned char *digest, struct lutil_MD5Context *ctx ) * the data and converts bytes into longwords for this routine. */ void -lutil_MD5Transform( uint32 *buf, const unsigned char *inraw ) +lutil_MD5Transform( ber_uint_t *buf, const unsigned char *inraw ) { - register uint32 a, b, c, d; - uint32 in[16]; + register ber_uint_t a, b, c, d; + ber_uint_t in[16]; int i; for (i = 0; i < 16; ++i) -- 2.39.5