crypto.m4 revision 103423
1dnl $Id: crypto.m4,v 1.13 2002/09/10 19:55:48 joda Exp $
2dnl
3dnl test for crypto libraries:
4dnl - libcrypto (from openssl)
5dnl - libdes (from krb4)
6dnl - own-built libdes
7
8m4_define([test_headers], [
9		#undef KRB5 /* makes md4.h et al unhappy */
10		#ifdef HAVE_OPENSSL
11		#include <openssl/md4.h>
12		#include <openssl/md5.h>
13		#include <openssl/sha.h>
14		#include <openssl/des.h>
15		#include <openssl/rc4.h>
16		#else
17		#include <md4.h>
18		#include <md5.h>
19		#include <sha.h>
20		#include <des.h>
21		#include <rc4.h>
22		#endif
23		#ifdef OLD_HASH_NAMES
24		typedef struct md4 MD4_CTX;
25		#define MD4_Init(C) md4_init((C))
26		#define MD4_Update(C, D, L) md4_update((C), (D), (L))
27		#define MD4_Final(D, C) md4_finito((C), (D))
28		typedef struct md5 MD5_CTX;
29		#define MD5_Init(C) md5_init((C))
30		#define MD5_Update(C, D, L) md5_update((C), (D), (L))
31		#define MD5_Final(D, C) md5_finito((C), (D))
32		typedef struct sha SHA_CTX;
33		#define SHA1_Init(C) sha_init((C))
34		#define SHA1_Update(C, D, L) sha_update((C), (D), (L))
35		#define SHA1_Final(D, C) sha_finito((C), (D))
36		#endif
37		])
38m4_define([test_body], [
39		void *schedule = 0;
40		MD4_CTX md4;
41		MD5_CTX md5;
42		SHA_CTX sha1;
43
44		MD4_Init(&md4);
45		MD5_Init(&md5);
46		SHA1_Init(&sha1);
47
48		des_cbc_encrypt(0, 0, 0, schedule, 0, 0);
49		RC4(0, 0, 0, 0);])
50
51
52AC_DEFUN([KRB_CRYPTO],[
53crypto_lib=unknown
54AC_WITH_ALL([openssl])
55
56DIR_des=
57
58AC_MSG_CHECKING([for crypto library])
59
60openssl=no
61old_hash=no
62
63if test "$crypto_lib" = "unknown" -a "$with_krb4" != "no"; then
64	save_CPPFLAGS="$CPPFLAGS"
65	save_LIBS="$LIBS"
66
67	cdirs= clibs=
68	for i in $LIB_krb4; do
69		case "$i" in
70		-L*) cdirs="$cdirs $i";;
71		-l*) clibs="$clibs $i";;
72		esac
73	done
74
75	ires=
76	for i in $INCLUDE_krb4; do
77		CFLAGS="-DHAVE_OPENSSL $i $save_CFLAGS"
78		AC_TRY_COMPILE(test_headers, test_body,
79			openssl=yes ires="$i"; break)
80		CFLAGS="$i $save_CFLAGS"
81		AC_TRY_COMPILE(test_headers, test_body,
82			openssl=no ires="$i"; break)
83		CFLAGS="-DOLD_HASH_NAMES $i $save_CFLAGS"
84		AC_TRY_COMPILE(test_headers, test_body,
85			openssl=no ires="$i" old_hash=yes; break)
86	done
87	lres=
88	for i in $cdirs; do
89		for j in $clibs; do
90			LIBS="$i $j $save_LIBS"
91			AC_TRY_LINK(test_headers, test_body,
92				lres="$i $j"; break 2)
93		done
94	done
95	CFLAGS="$save_CFLAGS"
96	LIBS="$save_LIBS"
97	if test "$ires" -a "$lres"; then
98		INCLUDE_des="$ires"
99		LIB_des="$lres"
100		crypto_lib=krb4
101		AC_MSG_RESULT([same as krb4])
102		LIB_des_a='$(LIB_des)'
103		LIB_des_so='$(LIB_des)'
104		LIB_des_appl='$(LIB_des)'
105	fi
106fi
107
108if test "$crypto_lib" = "unknown" -a "$with_openssl" != "no"; then
109	save_CFLAGS="$CFLAGS"
110	save_LIBS="$LIBS"
111	INCLUDE_des=
112	LIB_des=
113	if test "$with_openssl_include" != ""; then
114		INCLUDE_des="-I${with_openssl}/include"
115	fi
116	if test "$with_openssl_lib" != ""; then
117		LIB_des="-L${with_openssl}/lib"
118	fi
119	CFLAGS="-DHAVE_OPENSSL ${INCLUDE_des} ${CFLAGS}"
120	LIB_des="${LIB_des} -lcrypto"
121	LIB_des_a="$LIB_des"
122	LIB_des_so="$LIB_des"
123	LIB_des_appl="$LIB_des"
124	LIBS="${LIBS} ${LIB_des}"
125	AC_TRY_LINK(test_headers, test_body, [
126		crypto_lib=libcrypto openssl=yes
127		AC_MSG_RESULT([libcrypto])
128	])
129	CFLAGS="$save_CFLAGS"
130	LIBS="$save_LIBS"
131fi
132
133if test "$crypto_lib" = "unknown"; then
134
135  DIR_des='des'
136  LIB_des='$(top_builddir)/lib/des/libdes.la'
137  LIB_des_a='$(top_builddir)/lib/des/.libs/libdes.a'
138  LIB_des_so='$(top_builddir)/lib/des/.libs/libdes.so'
139  LIB_des_appl="-ldes"
140
141  AC_MSG_RESULT([included libdes])
142
143fi
144
145if test "$with_krb4" != no -a "$crypto_lib" != krb4; then
146	AC_MSG_ERROR([the crypto library used by krb4 lacks features
147required by Kerberos 5; to continue, you need to install a newer 
148Kerberos 4 or configure --without-krb4])
149fi
150
151if test "$openssl" = "yes"; then
152  AC_DEFINE([HAVE_OPENSSL], 1, [define to use openssl's libcrypto])
153fi
154if test "$old_hash" = yes; then
155  AC_DEFINE([HAVE_OLD_HASH_NAMES], 1,
156		[define if you have hash functions like md4_finito()])
157fi
158AM_CONDITIONAL(HAVE_OPENSSL, test "$openssl" = yes)dnl
159
160AC_SUBST(DIR_des)
161AC_SUBST(INCLUDE_des)
162AC_SUBST(LIB_des)
163AC_SUBST(LIB_des_a)
164AC_SUBST(LIB_des_so)
165AC_SUBST(LIB_des_appl)
166])
167