summaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/InsecureRandomDataProvider.cc9
-rw-r--r--libqpdf/QUtil.cc24
2 files changed, 14 insertions, 19 deletions
diff --git a/libqpdf/InsecureRandomDataProvider.cc b/libqpdf/InsecureRandomDataProvider.cc
index 18b21baa..e246ff97 100644
--- a/libqpdf/InsecureRandomDataProvider.cc
+++ b/libqpdf/InsecureRandomDataProvider.cc
@@ -30,8 +30,13 @@ InsecureRandomDataProvider::random()
// Seed the random number generator with something simple, but
// just to be interesting, don't use the unmodified current
// time. It would be better if this were a more secure seed.
- QUtil::srandom(static_cast<unsigned int>(
- QUtil::get_current_time() ^ 0xcccc));
+ unsigned int seed = static_cast<unsigned int>(
+ QUtil::get_current_time() ^ 0xcccc);
+#ifdef HAVE_RANDOM
+ ::srandom(seed);
+#else
+ srand(seed);
+#endif
this->seeded_random = true;
}
diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc
index 8717e148..177b49e1 100644
--- a/libqpdf/QUtil.cc
+++ b/libqpdf/QUtil.cc
@@ -878,16 +878,6 @@ QUtil::toUTF16(unsigned long uval)
// Random data support
-long
-QUtil::random()
-{
- long result = 0L;
- initializeWithRandomBytes(
- reinterpret_cast<unsigned char*>(&result),
- sizeof(result));
- return result;
-}
-
static RandomDataProvider* random_data_provider = 0;
#ifdef USE_INSECURE_RANDOM
@@ -941,14 +931,14 @@ QUtil::initializeWithRandomBytes(unsigned char* data, size_t len)
random_data_provider->provideRandomData(data, len);
}
-void
-QUtil::srandom(unsigned int seed)
+long
+QUtil::random()
{
-#ifdef HAVE_RANDOM
- ::srandom(seed);
-#else
- srand(seed);
-#endif
+ long result = 0L;
+ initializeWithRandomBytes(
+ reinterpret_cast<unsigned char*>(&result),
+ sizeof(result));
+ return result;
}
bool