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