DOVECOT_LIBCAP
DOVECOT_LIBWRAP
+DOVECOT_ARC4RANDOM
+
AC_DEFINE(PACKAGE_WEBPAGE, "http://www.dovecot.org/", [Support URL])
dnl * after -lsocket and -lnsl tests, inet_aton() may be in them
--- /dev/null
+AC_DEFUN([DOVECOT_ARC4RANDOM], [
+ AC_CHECK_FUNC([arc4random], [
+ AC_DEFINE([HAVE_ARC4RANDOM], [1], [Define this if you arc4random()])
+ ], [
+ AC_CHECK_LIB([bsd], [arc4random], [
+ LIBS="$LIBS -lbsd"
+ AC_DEFINE([HAVE_ARC4RANDOM], [1], [Define this if you arc4random()])
+ AC_DEFINE([HAVE_LIBBSD], [1], [Define this if you have libbsd])
+ ])
+ ])
+])
srand(seed);
}
+
+#ifdef HAVE_ARC4RANDOM
+#ifdef HAVE_LIBBSD
+#include <bsd/stdlib.h>
+#endif
+
+/* this returns [0,RAND_MAX), to keep it compatible with rand() */
+int arc4random_rand(void) {
+ return (int)(arc4random() % ((unsigned)RAND_MAX + 1));
+}
+#endif
/* Actually seed the prng (could add char* for name of function?) */
void rand_set_seed(unsigned int s);
+#ifdef HAVE_ARC4RANDOM
+
+int arc4random_rand(void);
+#define rand arc4random_rand
+
+#endif
+
#endif
i_close_fd(&urandom_fd);
}
+#ifdef HAVE_ARC4RANDOM
+#ifdef HAVE_LIBBSD
+#include <bsd/stdlib.h>
+#endif
+
+void random_fill_weak(void *buf, size_t size)
+{
+ arc4random_buf(buf, size);
+}
+
+#else
+
void random_fill_weak(void *buf, size_t size)
{
unsigned char *cbuf = buf;
for (; size > 0; size--)
*cbuf++ = (unsigned char)rand();
}
+
+#endif