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