Update gnulib files.
[gnutls:gnutls.git] / lgl / m4 / gc-random.m4
1 # gc-random.m4 serial 3
2 dnl Copyright (C) 2005-2008 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_GC_RANDOM],
8 [
9   # Devices with randomness.
10   # FIXME: Are these the best defaults?
11
12   AC_REQUIRE([AC_CANONICAL_HOST])dnl
13
14   case "$host_os" in
15     *openbsd*)
16       NAME_OF_RANDOM_DEVICE="/dev/srandom"
17       NAME_OF_PSEUDO_RANDOM_DEVICE="/dev/prandom"
18       NAME_OF_NONCE_DEVICE="/dev/urandom"
19       ;;
20
21     *netbsd*)
22       NAME_OF_RANDOM_DEVICE="/dev/srandom"
23       NAME_OF_PSEUDO_RANDOM_DEVICE="/dev/urandom"
24       NAME_OF_NONCE_DEVICE="/dev/urandom"
25       ;;
26
27     *solaris* | *irix* | *dec-osf* )
28       NAME_OF_RANDOM_DEVICE="/dev/random"
29       NAME_OF_PSEUDO_RANDOM_DEVICE="/dev/random"
30       NAME_OF_NONCE_DEVICE="/dev/random"
31       ;;
32
33     *)
34       NAME_OF_RANDOM_DEVICE="/dev/random"
35       NAME_OF_PSEUDO_RANDOM_DEVICE="/dev/urandom"
36       NAME_OF_NONCE_DEVICE="/dev/urandom"
37       ;;
38   esac
39
40   AC_MSG_CHECKING([device with (strong) random data...])
41   AC_ARG_ENABLE(random-device,
42         AS_HELP_STRING([--enable-random-device],
43                 [device with (strong) randomness (for Nettle)]),
44         NAME_OF_RANDOM_DEVICE=$enableval)
45   AC_MSG_RESULT($NAME_OF_RANDOM_DEVICE)
46
47   AC_MSG_CHECKING([device with pseudo random data...])
48   AC_ARG_ENABLE(pseudo-random-device,
49         AS_HELP_STRING([--enable-pseudo-random-device],
50                 [device with pseudo randomness (for Nettle)]),
51         NAME_OF_PSEUDO_RANDOM_DEVICE=$enableval)
52   AC_MSG_RESULT($NAME_OF_PSEUDO_RANDOM_DEVICE)
53
54   AC_MSG_CHECKING([device with unpredictable data for nonces...])
55   AC_ARG_ENABLE(nonce-device,
56         AS_HELP_STRING([--enable-nonce-device],
57                 [device with unpredictable nonces (for Nettle)]),
58         NAME_OF_NONCE_DEVICE=$enableval)
59   AC_MSG_RESULT($NAME_OF_NONCE_DEVICE)
60
61   if test "$cross_compiling" != yes; then
62     if test "$NAME_OF_RANDOM_DEVICE" != "no"; then
63       AC_CHECK_FILE($NAME_OF_RANDOM_DEVICE,,
64         AC_MSG_WARN([[Device `$NAME_OF_RANDOM_DEVICE' does not exist, consider to use --enable-random-device]]))
65     fi
66     if test "$NAME_OF_PSEUDO_RANDOM_DEVICE" != "no"; then
67       AC_CHECK_FILE($NAME_OF_PSEUDO_RANDOM_DEVICE,,
68         AC_MSG_WARN([[Device `$NAME_OF_PSEUDO_RANDOM_DEVICE' does not exist, consider to use --enable-pseudo-random-device]]))
69     fi
70     if test "$NAME_OF_NONCE_DEVICE" != "no"; then
71       AC_CHECK_FILE($NAME_OF_NONCE_DEVICE,,
72         AC_MSG_WARN([[Device `$NAME_OF_NONCE_DEVICE' does not exist, consider to use --enable-nonce-device]]))
73     fi
74   else
75     AC_MSG_NOTICE([[Cross compiling, assuming random devices exists on the target host...]])
76   fi
77
78   # FIXME?: Open+read 42 bytes+close twice and compare data.  Should differ.
79
80   AC_DEFINE_UNQUOTED(NAME_OF_RANDOM_DEVICE, "$NAME_OF_RANDOM_DEVICE",
81                    [defined to the name of the (strong) random device])
82   AC_DEFINE_UNQUOTED(NAME_OF_PSEUDO_RANDOM_DEVICE,
83                          "$NAME_OF_PSEUDO_RANDOM_DEVICE",
84                    [defined to the name of the pseudo random device])
85   AC_DEFINE_UNQUOTED(NAME_OF_NONCE_DEVICE, "$NAME_OF_NONCE_DEVICE",
86                    [defined to the name of the unpredictable nonce device])
87 ])