chiark / gitweb /
Use /dev/urandom (or corresponding file) by default in --both mode
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 21 Feb 2013 16:24:10 +0000 (16:24 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 21 Feb 2013 17:57:53 +0000 (17:57 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
configure.ac
m4/ax_random_device.m4 [new file with mode: 0644]
vbig.1
vbig.cc

index 01285c3996fcfd659110bda61a135569af32fb95..02ecfb6664a84509782d3624d1b8f9176c4bf3d8 100644 (file)
@@ -1,5 +1,6 @@
 AC_PREREQ([2.61])
 AC_INIT([vbig], [0.0.DEV], [rjk@greenend.org.uk])
+m4_include([m4/ax_random_device.m4])
 AC_CONFIG_AUX_DIR([config.aux])
 AM_INIT_AUTOMAKE([1.10])
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES])
@@ -23,5 +24,6 @@ AC_DEFINE([_GNU_SOURCE], [1], [use GNU extensions])
 if test "x$GXX" = xyes; then
   CXX="$CXX -Wall -W -Werror -Wpointer-arith -Wwrite-strings"
 fi
+AX_RANDOM_DEVICE
 AC_CONFIG_FILES([Makefile])
 AC_OUTPUT
diff --git a/m4/ax_random_device.m4 b/m4/ax_random_device.m4
new file mode 100644 (file)
index 0000000..ab9b56f
--- /dev/null
@@ -0,0 +1,31 @@
+dnl @synopsis AX_RANDOM_DEVICE
+dnl
+dnl This macro will check for a random device, allowing the user to explicitly
+dnl set the path. The user uses '--with-random=FILE' as an argument to
+dnl configure.
+dnl
+dnl If A random device is found then HAVE_RANDOM_DEVICE is set to 1 and
+dnl RANDOM_DEVICE contains the path.
+dnl
+dnl @category Miscellaneous
+dnl @author Martin Ebourne
+dnl @version 2005/07/01
+dnl @license AllPermissive
+
+AC_DEFUN([AX_RANDOM_DEVICE], [
+  AC_ARG_WITH([random],
+    [AC_HELP_STRING([--with-random=FILE], [Use FILE as random number seed [auto-detected]])],
+    [RANDOM_DEVICE="$withval"],
+    [AC_CHECK_FILE("/dev/urandom", [RANDOM_DEVICE="/dev/urandom";],
+       [AC_CHECK_FILE("/dev/arandom", [RANDOM_DEVICE="/dev/arandom";],
+         [AC_CHECK_FILE("/dev/random", [RANDOM_DEVICE="/dev/random";])]
+       )])
+    ])
+  if test "x$RANDOM_DEVICE" != "x" ; then
+    AC_DEFINE([HAVE_RANDOM_DEVICE], 1,
+              [Define to 1 (and set RANDOM_DEVICE) if a random device is available])
+    AC_SUBST([RANDOM_DEVICE])
+    AC_DEFINE_UNQUOTED([RANDOM_DEVICE], ["$RANDOM_DEVICE"],
+                       [Define to the filename of the random device (and set HAVE_RANDOM_DEVICE)])
+  fi
+  ])dnl
diff --git a/vbig.1 b/vbig.1
index 9076d0f8cb0c5507059b94e7e9cf03b2dbffaf4b..43052d62680f9f0e6c601927afd11425743a8c1e 100644 (file)
--- a/vbig.1
+++ b/vbig.1
@@ -36,7 +36,9 @@ The size is mandatory when creating a file but optional when verifying
 it, unless \-\-entire is specified.  If \fBSIZE\fR not specified when
 writing-then-verifying, it is as if \fB\-\-entire\fR was specified.
 .PP
-A fixed default seed is used if no seed or seed file is specified.
+If no seed or seed file is specified:
+in \fB--both\fR mode a fresh random seed is read from the system's
+random number generator; in other modes a fixed default seed is used.
 .SH OPTIONS
 .TP
 .B --seed\fR, \fB-s \fISEED
diff --git a/vbig.cc b/vbig.cc
index f1a6d44c0bfe99cb40c95b888b028008a43c3bd1..d2cc1a2c8ce4b8b28ade90a2fb98321a8a0403e7 100644 (file)
--- a/vbig.cc
+++ b/vbig.cc
@@ -163,6 +163,14 @@ int main(int argc, char **argv) {
   }
   if(seed && seedpath)
     fatal(0, "both --seed and --seed-file specified");
+  if(mode == BOTH && !seed && !seedpath) {
+#ifdef HAVE_RANDOM_DEVICE
+    seedpath = RANDOM_DEVICE;
+#else
+    fatal(0, "no --seed or --seed-file specified in --both mode"
+         " and random device not supported on this system");
+#endif
+  }
   if(seedpath) {
     if(!seedlen)
       seedlen = DEFAULT_SEED_LENGTH;