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