Improved bignum detection/use

This commit is contained in:
Kurt Zeilenga 2006-02-10 08:21:02 +00:00
parent da5c17aa1e
commit d2d1eb786b
5 changed files with 1126 additions and 798 deletions

1662
configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -248,12 +248,12 @@ OL_ARG_WITH(threads,[ --with-threads with threads],
auto, [auto nt posix mach pth lwp yes no manual] )
OL_ARG_WITH(tls,[ --with-tls with TLS/SSL support],
auto, [auto openssl yes no] )
OL_ARG_WITH(yielding_select,[ --with-yielding-select with implicitly yielding select],
OL_ARG_WITH(yielding_select,
[ --with-yielding-select with implicitly yielding select],
auto, [auto yes no manual] )
OL_ARG_WITH(multiple_precision,[ --with-multiple-precision
multiple precision support for statistics
auto|bignum|gmp],
auto, [auto bignum gmp yes no] )
OL_ARG_WITH(mp,
[ --with-mp with multiple precision statistics auto|longlong|long|bignum|gmp],
auto, [auto longlong long bignum gmp yes no])
dnl ----------------------------------------------------------------
dnl Server options
@ -2337,7 +2337,6 @@ if test $ol_enable_proctitle != no ; then
fi
dnl ----------------------------------------------------------------
dnl Check for SLPv2 Compliant API Library
if test $ol_enable_slp != no ; then
AC_CHECK_HEADERS( slp.h )
@ -2353,99 +2352,6 @@ if test $ol_enable_slp != no ; then
fi
fi
dnl ----------------------------------------------------------------
dnl Check for multiple precision support
if test "$ol_with_multiple_precision" != "no" ; then
ol_have_bignum=no
ol_have_gmp=no
AC_CHECK_HEADERS(openssl/bn.h bn.h)
AC_CHECK_HEADERS(openssl/crypto.h crypto.h)
AC_CHECK_HEADERS( gmp.h )
if test "$ol_with_tls" = "found" ; then
ol_have_bn_h=no
ol_have_crypto_h=no
if test "$ac_cv_header_openssl_bn_h" = "yes" ||
test "$ac_cv_header_bn_h" = "yes" ; then
ol_have_bn_h=yes
fi
if test "$ac_cv_header_openssl_crypto_h" = "yes" ||
test "$ac_cv_header_crypto_h" = "yes" ; then
ol_have_crypto_h=yes
fi
if test "$ol_have_bn_h" = "yes" &&
test "$ol_have_crypto_h" = "yes" ; then
ol_have_bignum=yes
fi
fi
if test $ac_cv_header_gmp_h = yes ; then
AC_CHECK_LIB(gmp, __gmpz_add_ui, [have_gmp=yes], [have_gmp=no])
if test $have_gmp = yes ; then
ol_have_gmp=yes
fi
fi
AC_MSG_CHECKING([for multiple precision support])
ol_mp_support="none"
case "$ol_with_multiple_precision" in
auto)
dnl preferred sequence:
dnl - OpenSSL's BIGNUM (if libssl is already linked)
dnl - GNU's MP
dnl - unsigned long
if test "$ol_have_bignum" = "yes" ; then
ol_mp_support="bignum"
else
if test "$ol_have_gmp" = "yes" ; then
ol_mp_support="gmp"
fi
fi
;;
bignum)
if test "$ol_have_bignum" != "yes" ; then
AC_MSG_ERROR([OpenSSL's BIGNUM not available])
fi
ol_mp_support="bignum"
;;
gmp)
if test "$ol_have_gmp" != "yes" ; then
AC_MSG_ERROR([GMP not available])
fi
ol_mp_support="gmp"
;;
yes)
if test "$ol_have_bignum" = "yes" ; then
ol_mp_support="bignum"
elif test "$ol_have_gmp" = "yes" ; then
ol_mp_support="gmp"
else
AC_MSG_ERROR([not available])
fi
;;
esac
case "$ol_mp_support" in
bignum)
AC_DEFINE(HAVE_BIGNUM, 1,
[define if you have OpenSSL's BIGNUM])
;;
gmp)
AC_DEFINE(HAVE_GMP, 1, [define if you have -lgmp])
SLAPD_GMP_LIBS=-lgmp
;;
none)
;;
esac
AC_MSG_RESULT($ol_mp_support)
fi
dnl ----------------------------------------------------------------
dnl Checks for typedefs, structures, and compiler characteristics.
@ -2501,6 +2407,7 @@ fi
AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(long long)
AC_CHECK_SIZEOF(wchar_t)
if test "$ac_cv_sizeof_int" -lt 4 ; then
@ -2515,6 +2422,50 @@ AC_DEFINE(LBER_LEN_T,long,[define to large integer type])
AC_DEFINE(LBER_SOCKET_T,int,[define to socket descriptor type])
AC_DEFINE(LBER_TAG_T,long,[define to large integer type])
dnl ----------------------------------------------------------------
dnl Check for multiple precision support
if test $ol_with_mp = longlong || test $ol_with_mp = auto ; then
if test $ac_cv_sizeof_long_long > 4 ; then
ol_with_mp=longlong
AC_DEFINE(USE_MP_LONG_LONG,1,[define to use 'long long' for MP])
elif test $ol_with_mp = longlong ; then
AC_MSG_ERROR([long long unusable for multiple precision])
fi
fi
if test $ol_with_mp = long || test $ol_with_mp = auto ; then
if test $ac_cv_sizeof_long > 4 ; then
ol_with_mp=long
AC_DEFINE(USE_MP_LONG,1,[define to use 'long' for MP])
elif test $ol_with_mp = long ; then
AC_MSG_ERROR([long unusable for multiple precision])
fi
fi
if test $ol_with_mp = bignum || test $ol_with_mp = auto ; then
AC_CHECK_HEADERS(openssl/bn.h)
AC_CHECK_HEADERS(openssl/crypto.h)
if test "$ac_cv_header_openssl_bn_h" = "yes" &&
test "$ac_cv_header_openssl_crypto_h" = "yes" &&
test "$ol_with_tls" = "found" ; then
ol_with_mp=bignum
AC_DEFINE(USE_MP_BIGNUM,1,[define to use OpenSSL BIGNUM for MP])
elif test $ol_with_mp = bignum ; then
AC_MSG_ERROR([bignum not available])
fi
fi
if test $ol_with_mp = gmp || test $ol_with_mp = auto ; then
AC_CHECK_HEADERS(gmp.h)
AC_CHECK_LIB(gmp, __gmpz_add_ui)
if test $ac_cv_header_gmp_h = yes && test $ac_cv_lib_gmp = yes ; then
AC_DEFINE(USE_MP_LONG_LONG,1,[define to use GMP for MP])
ol_with_mp=gmp
elif test $ol_with_mp = gmp ; then
AC_MSG_ERROR([gmp not available])
fi
fi
if test $ol_with_mp = auto ; then
ol_with_mp=no
fi
dnl ----------------------------------------------------------------
dnl Checks for library functions.
AC_FUNC_MEMCMP

View File

@ -272,34 +272,19 @@ LDAP_END_DECL
*
* If none is available, unsigned long data is used.
*/
#if !defined(HAVE_LONG_LONG)
#if defined(HAVE_BIGNUM)
#define USE_BIGNUM
#elif defined(HAVE_GMP)
#define USE_GMP
#endif
#endif
#ifdef USE_BIGNUM
#if USE_MP_BIGNUM
/*
* Use OpenSSL's BIGNUM
*/
#if defined(HAVE_OPENSSL_CRYPTO_H)
#include <openssl/crypto.h>
#elif HAVE_CRYPTO_H
#include <crypto.h>
#endif /* HAVE_OPENSSL_CRYPTO_H || HAVE_CRYPTO_H */
#ifdef HAVE_OPENSSL_BN_H
#include <openssl/bn.h>
#elif HAVE_BN_H
#include <bn.h>
#endif /* HAVE_OPENSSL_BN_H || HAVE_BN_H */
typedef BIGNUM* ldap_pvt_mp_t;
typedef BIGNUM* ldap_pvt_mp_t;
#define LDAP_PVT_MP_INIT (NULL)
#define ldap_pvt_mp_init(mp) \
(mp) = BN_new()
do { (mp) = BN_new(); } while (0)
/* FIXME: we rely on mpr being initialized */
#define ldap_pvt_mp_init_set(mpr,mpv) \
@ -314,13 +299,11 @@ typedef BIGNUM* ldap_pvt_mp_t;
#define ldap_pvt_mp_clear(mp) \
do { BN_free((mp)); (mp) = 0; } while (0)
#elif defined(USE_GMP)
#elif USE_MP_GMP
/*
* Use GNU's multiple precision library
*/
#ifdef HAVE_GMP_H
#include <gmp.h>
#endif
typedef mpz_t ldap_pvt_mp_t;
#define LDAP_PVT_MP_INIT { 0 }
@ -340,36 +323,42 @@ typedef mpz_t ldap_pvt_mp_t;
#define ldap_pvt_mp_clear(mp) \
mpz_clear((mp))
#else /* ! USE_BIGNUM && ! USE_GMP */
#else
/*
* Use unsigned long
* Use unsigned long long
*/
#ifdef HAVE_LONG_LONG
#if USE_MP_LONG_LONG
typedef unsigned long long ldap_pvt_mp_t;
#define LDAP_PVT_MP_INIT (0LL)
#else /* !HAVE_LONG_LONG */
#elif USE_MP_LONG
typedef unsigned long ldap_pvt_mp_t;
#define LDAP_PVT_MP_INIT (0L)
#endif /* !HAVE_LONG_LONG */
#elif HAVE_LONG_LONG
typedef unsigned long long ldap_pvt_mp_t;
#define LDAP_PVT_MP_INIT (0LL)
#else
typedef unsigned long ldap_pvt_mp_t;
#define LDAP_PVT_MP_INIT (0L)
#endif
#define ldap_pvt_mp_init(mp) \
(mp) = 0
do { (mp) = 0; } while (0)
#define ldap_pvt_mp_init_set(mpr,mpv) \
(mpr) = (mpv)
do { (mpr) = (mpv); } while (0)
#define ldap_pvt_mp_add(mpr,mpv) \
(mpr) += (mpv)
do { (mpr) += (mpv); } while (0)
#define ldap_pvt_mp_add_ulong(mp,v) \
(mp) += (v)
do { (mp) += (v); } while (0)
#define ldap_pvt_mp_clear(mp) \
(mp) = 0
do { (mp) = 0; } while (0)
#endif /* ! USE_BIGNUM && ! USE_GMP */
#endif /* MP */
#include "ldap_pvt_uc.h"
#endif
#endif /* _LDAP_PVT_H */

View File

@ -102,15 +102,9 @@
/* define if Berkeley DB has DB_THREAD support */
#undef HAVE_BERKELEY_DB_THREAD
/* define if you have OpenSSL's BIGNUM */
#undef HAVE_BIGNUM
/* Define to 1 if you have the <bits/types.h> header file. */
#undef HAVE_BITS_TYPES_H
/* Define to 1 if you have the <bn.h> header file. */
#undef HAVE_BN_H
/* Define to 1 if you have the `chroot' function. */
#undef HAVE_CHROOT
@ -123,9 +117,6 @@
/* define if crypt(3) is available */
#undef HAVE_CRYPT
/* Define to 1 if you have the <crypto.h> header file. */
#undef HAVE_CRYPTO_H
/* Define to 1 if you have the <crypt.h> header file. */
#undef HAVE_CRYPT_H
@ -256,9 +247,6 @@
/* Define to 1 if you have the `gettimeofday' function. */
#undef HAVE_GETTIMEOFDAY
/* define if you have -lgmp */
#undef HAVE_GMP
/* Define to 1 if you have the <gmp.h> header file. */
#undef HAVE_GMP_H
@ -331,6 +319,9 @@
/* Define to 1 if you have the `gen' library (-lgen). */
#undef HAVE_LIBGEN
/* Define to 1 if you have the `gmp' library (-lgmp). */
#undef HAVE_LIBGMP
/* Define to 1 if you have the `inet' library (-linet). */
#undef HAVE_LIBINET
@ -933,6 +924,9 @@
/* The size of a `long', as computed by sizeof. */
#undef SIZEOF_LONG
/* The size of a `long long', as computed by sizeof. */
#undef SIZEOF_LONG_LONG
/* The size of a `short', as computed by sizeof. */
#undef SIZEOF_SHORT
@ -1065,6 +1059,15 @@
/* set to urandom device */
#undef URANDOM_DEVICE
/* define to use OpenSSL BIGNUM for MP */
#undef USE_MP_BIGNUM
/* define to use 'long' for MP */
#undef USE_MP_LONG
/* define to use GMP for MP */
#undef USE_MP_LONG_LONG
/* Define to 1 if your processor stores words with the most significant byte
first (like Motorola and SPARC, unlike Intel and VAX). */
#undef WORDS_BIGENDIAN

View File

@ -1821,8 +1821,8 @@ LDAP_SLAPD_F (int) fe_access_allowed LDAP_P((
/* NOTE: this macro assumes that bv has been allocated
* by ber_* malloc functions or is { 0L, NULL } */
#if defined(USE_BIGNUM)
#define UI2BVX(bv,ui,ctx) \
#ifdef USE_MP_BIGNUM
# define UI2BVX(bv,ui,ctx) \
do { \
char *val; \
ber_len_t len; \
@ -1840,12 +1840,13 @@ LDAP_SLAPD_F (int) fe_access_allowed LDAP_P((
BER_BVZERO( (bv) ); \
} \
} while ( 0 )
#elif defined(USE_GMP)
#elif defined( USE_MP_GMP )
/* NOTE: according to the documentation, the result
* of mpz_sizeinbase() can exceed the length of the
* string representation of the number by 1
*/
#define UI2BVX(bv,ui,ctx) \
# define UI2BVX(bv,ui,ctx) \
do { \
ber_len_t len = mpz_sizeinbase( (ui), 10 ); \
if ( len > (bv)->bv_len ) { \
@ -1857,13 +1858,19 @@ LDAP_SLAPD_F (int) fe_access_allowed LDAP_P((
} \
(bv)->bv_len = len; \
} while ( 0 )
#else /* ! HAVE_BIGNUM && ! HAVE_GMP */
#ifdef HAVE_LONG_LONG
#define UI2BV_FORMAT "%llu"
#else /* ! HAVE_LONG_LONG */
#define UI2BV_FORMAT "%lu"
#endif /* ! HAVE_LONG_LONG */
#define UI2BVX(bv,ui,ctx) \
#else
# if USE_MP_LONG_LONG
# define UI2BV_FORMAT "%llu"
# elif USE_MP_LONG_LONG
# define UI2BV_FORMAT "%lu"
# elif HAVE_LONG_LONG
# define UI2BV_FORMAT "%llu"
# else
# define UI2BV_FORMAT "%lu"
# endif
# define UI2BVX(bv,ui,ctx) \
do { \
char buf[] = "+9223372036854775807L"; \
ber_len_t len; \
@ -1874,7 +1881,7 @@ LDAP_SLAPD_F (int) fe_access_allowed LDAP_P((
(bv)->bv_len = len; \
AC_MEMCPY( (bv)->bv_val, buf, len + 1 ); \
} while ( 0 )
#endif /* ! HAVE_GMP */
#endif
#define UI2BV(bv,ui) UI2BVX(bv,ui,NULL)