heimdal: remove checking of KDC PAC signature, delegate to wdc plugin
[heimdal.git] / cf / crypto.m4
blobf42905d0df9b94bb71227c73bfc5b12b9b3fc84e
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/bn.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/rsa.h>
22                 #include <openssl/dsa.h>
23                 #include <openssl/dh.h>
24                 #include <openssl/ec.h>
25                 #include <openssl/engine.h>
26                 #include <openssl/ui.h>
27                 #include <openssl/rand.h>
28                 #include <openssl/hmac.h>
29                 #include <openssl/pkcs12.h>
30                 #else
31                 #include <hcrypto/evp.h>
32                 #include <hcrypto/md4.h>
33                 #include <hcrypto/md5.h>
34                 #include <hcrypto/sha.h>
35                 #include <hcrypto/des.h>
36                 #include <hcrypto/rc4.h>
37                 #include <hcrypto/aes.h>
38                 #include <hcrypto/engine.h>
39                 #include <hcrypto/hmac.h>
40                 #include <hcrypto/pkcs12.h>
41                 #endif
42                 ])
43 m4_define([test_body], [
44                 void *schedule = 0;
45                 EVP_MD_CTX mdctx;
47                 EVP_md4();
48                 EVP_md5();
49                 EVP_sha1();
50                 EVP_sha256();
52                 EVP_MD_CTX_init(&mdctx);
53                 EVP_DigestInit_ex(&mdctx, EVP_sha1(), (ENGINE *)0);
54                 EVP_CIPHER_iv_length(((EVP_CIPHER*)0));
55                 UI_UTIL_read_pw_string(0,0,0,0);
56                 RAND_status();
57                 #ifdef HAVE_OPENSSL
58                 EC_KEY_new();
59                 #endif
61                 OpenSSL_add_all_algorithms();
62                 AES_encrypt(0,0,0);
63                 DES_cbc_encrypt(0, 0, 0, schedule, 0, 0);
64                 RC4(0, 0, 0, 0);])
66 m4_define([bn_headers], [
67                 #include <stdlib.h>
68                 #include <openssl/bn.h>
69                 ])
70 m4_define([bn_body], [
71                 BIGNUM *bn = BN_new();
72                 BN_set_word(bn, 1);
73                 if (BN_is_negative(bn))
74                         exit(EXIT_FAILURE);
75                 BN_set_negative(bn, 1);
76                 if (!BN_is_negative(bn))
77                         exit(EXIT_FAILURE);
78                 exit(EXIT_SUCCESS);
79                 ])
81 AC_DEFUN([KRB_CRYPTO],[
82 crypto_lib=unknown
83 AC_WITH_ALL([openssl])
85 DIR_hcrypto=
87 AC_MSG_CHECKING([for crypto library])
89 openssl=no
91 if test "$crypto_lib" = "unknown" -a "$with_openssl" != "no"; then
92         save_CFLAGS="$CFLAGS"
93         save_LIBS="$LIBS"
94         INCLUDE_hcrypto=
95         LIB_hcrypto=
96         if test "$with_openssl_include" != ""; then
97                 INCLUDE_hcrypto="-I${with_openssl_include}"
98         fi
99         if test "$with_openssl_lib" != ""; then
100                 LIB_hcrypto="-L${with_openssl_lib}"
101         fi
102         CFLAGS="-DHAVE_OPENSSL ${INCLUDE_hcrypto} ${CFLAGS}"
103         saved_LIB_hcrypto="$LIB_hcrypto"
104         for lres in "" "-ldl" "-lnsl -lsocket" "-lnsl -lsocket -ldl"; do
105                 LIB_hcrypto="${saved_LIB_hcrypto} -lcrypto $lres"
106                 LIB_hcrypto_a="$LIB_hcrypto"
107                 LIB_hcrypto_so="$LIB_hcrypto"
108                 LIB_hcrypto_appl="$LIB_hcrypto"
109                 LIBS="${LIBS} ${LIB_hcrypto}"
110                 AC_LINK_IFELSE([AC_LANG_PROGRAM([test_headers],[test_body])], [
111                         crypto_lib=libcrypto openssl=yes
112                         AC_MSG_RESULT([libcrypto])
113                         AC_RUN_IFELSE([AC_LANG_PROGRAM([bn_headers],[bn_body])], [
114                           AC_DEFINE([HAVE_BN_IS_NEGATIVE], 1, [define if OpenSSL provides BN_is_negative])
115                         ])
116                 ])
117                 if test "$crypto_lib" = libcrypto ; then
118                         break;
119                 fi
120         done
121         AC_CHECK_LIB(crypto, RAND_egd, AC_DEFINE(HAVE_RAND_EGD, 1, [Define if the libcrypto has RAND_egd]))
122         CFLAGS="$save_CFLAGS"
123         LIBS="$save_LIBS"
126 if test "$crypto_lib" = "unknown"; then
128   DIR_hcrypto='hcrypto'
129   LIB_hcrypto='$(top_builddir)/lib/hcrypto/libhcrypto.la'
130   LIB_hcrypto_a='$(top_builddir)/lib/hcrypto/.libs/libhcrypto.a'
131   LIB_hcrypto_so='$(top_builddir)/lib/hcrypto/.libs/libhcrypto.so'
132   LIB_hcrypto_appl="-lhcrypto"
134   AC_MSG_RESULT([included libhcrypto])
138 if test "$openssl" = "yes"; then
139   AC_DEFINE([HAVE_OPENSSL], 1, [define to use openssl's libcrypto])
141 AM_CONDITIONAL(HAVE_OPENSSL, test "$openssl" = yes)dnl
143 AC_SUBST(DIR_hcrypto)
144 AC_SUBST(INCLUDE_hcrypto)
145 AC_SUBST(LIB_hcrypto)
146 AC_SUBST(LIB_hcrypto_a)
147 AC_SUBST(LIB_hcrypto_so)
148 AC_SUBST(LIB_hcrypto_appl)