gc-random.m4 3.3 KB
Newer Older
1
# gc-random.m4 serial 6
2
dnl Copyright (C) 2005-2018 Free Software Foundation, Inc.
3 4 5 6 7 8 9 10 11
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

AC_DEFUN([gl_GC_RANDOM],
[
  # Devices with randomness.
  # FIXME: Are these the best defaults?

12 13 14
  AC_REQUIRE([AC_CANONICAL_HOST])dnl

  case "$host_os" in
15
    *openbsd* | *mirbsd*)
16 17 18 19 20
      NAME_OF_RANDOM_DEVICE="/dev/srandom"
      NAME_OF_PSEUDO_RANDOM_DEVICE="/dev/prandom"
      NAME_OF_NONCE_DEVICE="/dev/urandom"
      ;;

21
    *netbsd*)
22 23 24 25 26
      NAME_OF_RANDOM_DEVICE="/dev/srandom"
      NAME_OF_PSEUDO_RANDOM_DEVICE="/dev/urandom"
      NAME_OF_NONCE_DEVICE="/dev/urandom"
      ;;

27
    *solaris* | *irix* | *dec-osf* )
28 29 30 31 32 33 34 35 36 37 38 39 40
      NAME_OF_RANDOM_DEVICE="/dev/random"
      NAME_OF_PSEUDO_RANDOM_DEVICE="/dev/random"
      NAME_OF_NONCE_DEVICE="/dev/random"
      ;;

    *)
      NAME_OF_RANDOM_DEVICE="/dev/random"
      NAME_OF_PSEUDO_RANDOM_DEVICE="/dev/urandom"
      NAME_OF_NONCE_DEVICE="/dev/urandom"
      ;;
  esac

  AC_MSG_CHECKING([device with (strong) random data...])
41
  AC_ARG_ENABLE([random-device],
42 43 44
        AS_HELP_STRING([--enable-random-device],
                [device with (strong) randomness (for Nettle)]),
        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 50 51
        AS_HELP_STRING([--enable-pseudo-random-device],
                [device with pseudo randomness (for Nettle)]),
        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 57 58
        AS_HELP_STRING([--enable-nonce-device],
                [device with unpredictable nonces (for Nettle)]),
        NAME_OF_NONCE_DEVICE=$enableval)
59
  AC_MSG_RESULT([$NAME_OF_NONCE_DEVICE])
60 61

  if test "$cross_compiling" != yes; then
Simon Josefsson's avatar
Simon Josefsson committed
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]]))
Simon Josefsson's avatar
Simon Josefsson committed
65 66
    fi
    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]]))
Simon Josefsson's avatar
Simon Josefsson committed
69
    fi
Simon Josefsson's avatar
Simon Josefsson committed
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]]))
Simon Josefsson's avatar
Simon Josefsson committed
73
    fi
74
  else
75
    AC_MSG_NOTICE([[Cross compiling, assuming random devices exists on the target host...]])
76 77 78 79
  fi

  # FIXME?: Open+read 42 bytes+close twice and compare data.  Should differ.

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 87
                   [defined to the name of the unpredictable nonce device])
])