aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ares/ares_init.c16
-rw-r--r--ares/configure.ac16
2 files changed, 30 insertions, 2 deletions
diff --git a/ares/ares_init.c b/ares/ares_init.c
index e86d80ca4..efde96772 100644
--- a/ares/ares_init.c
+++ b/ares/ares_init.c
@@ -1276,6 +1276,7 @@ static void natural_mask(struct apattern *pat)
static void randomize_key(unsigned char* key,int key_data_len)
{
int randomized = 0;
+ int counter=0;
#ifdef WIN32
HMODULE lib=LoadLibrary("ADVAPI32.DLL");
if (lib) {
@@ -1286,11 +1287,22 @@ static void randomize_key(unsigned char* key,int key_data_len)
FreeLibrary(lib);
}
+#else /* !WIN32 */
+#ifdef RANDOM_FILE
+ char buffer[256];
+ FILE *f = fopen(RANDOM_FILE, "rb");
+ if(f) {
+ size_t i;
+ size_t rc = fread(buffer, key_data_len, 1, f);
+ for(i=0; i<rc && counter < key_data_len; i++)
+ key[counter++]=buffer[i];
+ fclose(f);
+ }
#endif
+#endif /* WIN32 */
if ( !randomized ) {
- int counter;
- for (counter=0;counter<key_data_len;counter++)
+ for (;counter<key_data_len;counter++)
key[counter]=rand() % 256;
}
}
diff --git a/ares/configure.ac b/ares/configure.ac
index 4eb62d1ee..574944233 100644
--- a/ares/configure.ac
+++ b/ares/configure.ac
@@ -785,4 +785,20 @@ AC_C_BIGENDIAN(
[AC_MSG_WARN([couldn't figure out endianess, assuming little endian!])]
)
+dnl Check for user-specified random device
+AC_ARG_WITH(random,
+AC_HELP_STRING([--with-random=FILE],
+ [read randomness from FILE (default=/dev/urandom)]),
+ [ RANDOM_FILE="$withval" ],
+ [
+ dnl Check for random device
+ AC_CHECK_FILE("/dev/urandom", [ RANDOM_FILE="/dev/urandom"] )
+ ]
+)
+if test -n "$RANDOM_FILE" && test X"$RANDOM_FILE" != Xno ; then
+ AC_SUBST(RANDOM_FILE)
+ AC_DEFINE_UNQUOTED(RANDOM_FILE, "$RANDOM_FILE",
+ [a suitable file/device to read random data from])
+fi
+
AC_OUTPUT(Makefile)