516646e17c20e5ae72bb31ce69367fadfed14995
[gnulib.git] / m4 / gc-random.m4
1 # gc-random.m4 serial 1
2 dnl Copyright (C) 2005, 2006 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         AC_HELP_STRING([--enable-random-device],
43                 [device with (strong) randomness (for Nettle)]),
44         test "$enableval" != "no" && 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         AC_HELP_STRING([--enable-pseudo-random-device],
50                 [device with pseudo randomness (for Nettle)]),
51         test "$enableval" != "no" && 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         AC_HELP_STRING([--enable-nonce-device],
57                 [device with unpredictable nonces (for Nettle)]),
58         test "$enableval" != "no" && NAME_OF_NONCE_DEVICE=$enableval)
59   AC_MSG_RESULT($NAME_OF_NONCE_DEVICE)
60
61   if test "$cross_compiling" != yes; then
62     AC_CHECK_FILE($NAME_OF_RANDOM_DEVICE,,
63       AC_MSG_WARN([[device for (strong) random data `$NAME_OF_RANDOM_DEVICE' does not exist]]))
64     AC_CHECK_FILE($NAME_OF_PSEUDO_RANDOM_DEVICE,,
65       AC_MSG_WARN([[device for pseudo-random data `$NAME_OF_PSEUDO_RANDOM_DEVICE' does not exist]]))
66     AC_CHECK_FILE($NAME_OF_NONCE_DEVICE,,
67       AC_MSG_WARN([[device for unpredictable nonces `$NAME_OF_NONCE_DEVICE' does not exist]]))
68   else
69     AC_MSG_NOTICE([[Cross compiling, assuming random devices exists on the target host...]])  
70   fi
71
72   # FIXME?: Open+read 42 bytes+close twice and compare data.  Should differ.
73
74   AC_DEFINE_UNQUOTED(NAME_OF_RANDOM_DEVICE, "$NAME_OF_RANDOM_DEVICE",
75                    [defined to the name of the (strong) random device])
76   AC_DEFINE_UNQUOTED(NAME_OF_PSEUDO_RANDOM_DEVICE,
77                          "$NAME_OF_PSEUDO_RANDOM_DEVICE",
78                    [defined to the name of the pseudo random device])
79   AC_DEFINE_UNQUOTED(NAME_OF_NONCE_DEVICE, "$NAME_OF_NONCE_DEVICE",
80                    [defined to the name of the unpredictable nonce device])
81
82   AC_DEFINE(GC_USE_RANDOM, 1, [Define if you want to support RNG through GC.])
83 ])