1dnl $Id: crypto.m4 22080 2007-11-16 11:10:54Z lha $ 2dnl 3dnl test for crypto libraries: 4dnl - libcrypto (from openssl) 5dnl - own-built libhcrypto 6 7m4_define([test_headers], [ 8 #undef KRB5 /* makes md4.h et al unhappy */ 9 #ifdef HAVE_OPENSSL 10 #ifdef HAVE_SYS_TYPES_H 11 #include <sys/types.h> 12 #endif 13 #include <openssl/evp.h> 14 #include <openssl/md4.h> 15 #include <openssl/md5.h> 16 #include <openssl/sha.h> 17 #include <openssl/des.h> 18 #include <openssl/rc4.h> 19 #include <openssl/aes.h> 20 #include <openssl/engine.h> 21 #include <openssl/ui.h> 22 #include <openssl/rand.h> 23 #include <openssl/hmac.h> 24 #include <openssl/pkcs12.h> 25 #else 26 #include <hcrypto/evp.h> 27 #include <hcrypto/md4.h> 28 #include <hcrypto/md5.h> 29 #include <hcrypto/sha.h> 30 #include <hcrypto/des.h> 31 #include <hcrypto/rc4.h> 32 #include <hcrypto/aes.h> 33 #include <hcrypto/engine.h> 34 #include <hcrypto/hmac.h> 35 #include <hcrypto/pkcs12.h> 36 #endif 37 ]) 38m4_define([test_body], [ 39 void *schedule = 0; 40 MD4_CTX md4; 41 MD5_CTX md5; 42 SHA_CTX sha1; 43 SHA256_CTX sha256; 44 45 MD4_Init(&md4); 46 MD5_Init(&md5); 47 SHA1_Init(&sha1); 48 SHA256_Init(&sha256); 49 EVP_CIPHER_iv_length(((EVP_CIPHER*)0)); 50 #ifdef HAVE_OPENSSL 51 RAND_status(); 52 UI_UTIL_read_pw_string(0,0,0,0); 53 #endif 54 55 OpenSSL_add_all_algorithms(); 56 AES_encrypt(0,0,0); 57 DES_cbc_encrypt(0, 0, 0, schedule, 0, 0); 58 RC4(0, 0, 0, 0);]) 59 60 61AC_DEFUN([KRB_CRYPTO],[ 62crypto_lib=unknown 63AC_WITH_ALL([openssl]) 64 65DIR_hcrypto= 66 67AC_MSG_CHECKING([for crypto library]) 68 69openssl=no 70 71if test "$crypto_lib" = "unknown" -a "$with_krb4" != "no"; then 72 save_CPPFLAGS="$CPPFLAGS" 73 save_LIBS="$LIBS" 74 75 cdirs= clibs= 76 for i in $LIB_krb4; do 77 case "$i" in 78 -L*) cdirs="$cdirs $i";; 79 -l*) clibs="$clibs $i";; 80 esac 81 done 82 83 ires= 84 for i in $INCLUDE_krb4; do 85 CFLAGS="-DHAVE_OPENSSL $i $save_CFLAGS" 86 for j in $cdirs; do 87 for k in $clibs; do 88 LIBS="$j $k $save_LIBS" 89 AC_LINK_IFELSE([AC_LANG_PROGRAM([test_headers], 90 [test_body])], 91 [openssl=yes ires="$i" lres="$j $k"; break 3]) 92 done 93 done 94 CFLAGS="$i $save_CFLAGS" 95 for j in $cdirs; do 96 for k in $clibs; do 97 LIBS="$j $k $save_LIBS" 98 AC_LINK_IFELSE([AC_LANG_PROGRAM([test_headers],[test_body])], 99 [openssl=no ires="$i" lres="$j $k"; break 3]) 100 done 101 done 102 done 103 104 CFLAGS="$save_CFLAGS" 105 LIBS="$save_LIBS" 106 if test "$ires" -a "$lres"; then 107 INCLUDE_hcrypto="$ires" 108 LIB_hcrypto="$lres" 109 crypto_lib=krb4 110 AC_MSG_RESULT([same as krb4]) 111 LIB_hcrypto_a='$(LIB_hcrypto)' 112 LIB_hcrypto_so='$(LIB_hcrypto)' 113 LIB_hcrypto_appl='$(LIB_hcrypto)' 114 fi 115fi 116 117if test "$crypto_lib" = "unknown" -a "$with_openssl" != "no"; then 118 save_CFLAGS="$CFLAGS" 119 save_LIBS="$LIBS" 120 INCLUDE_hcrypto= 121 LIB_hcrypto= 122 if test "$with_openssl_include" != ""; then 123 INCLUDE_hcrypto="-I${with_openssl_include}" 124 fi 125 if test "$with_openssl_lib" != ""; then 126 LIB_hcrypto="-L${with_openssl_lib}" 127 fi 128 CFLAGS="-DHAVE_OPENSSL ${INCLUDE_hcrypto} ${CFLAGS}" 129 saved_LIB_hcrypto="$LIB_hcrypto" 130 for lres in "" "-ldl" "-lnsl -lsocket" "-lnsl -lsocket -ldl"; do 131 LIB_hcrypto="${saved_LIB_hcrypto} -lcrypto $lres" 132 LIB_hcrypto_a="$LIB_hcrypto" 133 LIB_hcrypto_so="$LIB_hcrypto" 134 LIB_hcrypto_appl="$LIB_hcrypto" 135 LIBS="${LIBS} ${LIB_hcrypto}" 136 AC_LINK_IFELSE([AC_LANG_PROGRAM([test_headers],[test_body])], [ 137 crypto_lib=libcrypto openssl=yes 138 AC_MSG_RESULT([libcrypto]) 139 ]) 140 if test "$crypto_lib" = libcrypto ; then 141 break; 142 fi 143 done 144 CFLAGS="$save_CFLAGS" 145 LIBS="$save_LIBS" 146fi 147 148if test "$crypto_lib" = "unknown"; then 149 150 DIR_hcrypto='hcrypto' 151 LIB_hcrypto='$(top_builddir)/lib/hcrypto/libhcrypto.la' 152 LIB_hcrypto_a='$(top_builddir)/lib/hcrypto/.libs/libhcrypto.a' 153 LIB_hcrypto_so='$(top_builddir)/lib/hcrypto/.libs/libhcrypto.so' 154 LIB_hcrypto_appl="-lhcrypto" 155 156 AC_MSG_RESULT([included libhcrypto]) 157 158fi 159 160if test "$with_krb4" != no -a "$crypto_lib" != krb4; then 161 AC_MSG_ERROR([the crypto library used by krb4 lacks features 162required by Kerberos 5; to continue, you need to install a newer 163Kerberos 4 or configure --without-krb4]) 164fi 165 166if test "$openssl" = "yes"; then 167 AC_DEFINE([HAVE_OPENSSL], 1, [define to use openssl's libcrypto]) 168fi 169AM_CONDITIONAL(HAVE_OPENSSL, test "$openssl" = yes)dnl 170 171AC_SUBST(DIR_hcrypto) 172AC_SUBST(INCLUDE_hcrypto) 173AC_SUBST(LIB_hcrypto) 174AC_SUBST(LIB_hcrypto_a) 175AC_SUBST(LIB_hcrypto_so) 176AC_SUBST(LIB_hcrypto_appl) 177]) 178