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