Commit f0211d954c055f21733bad7c0c5357b99f6c7b80
1 parent
34097d6c
use a simpler seed for the random number generator
git-svn-id: svn+q:///qpdf/trunk@821 71b93d88-0707-0410-a8cf-f5a4172ac649
Showing
1 changed file
with
4 additions
and
12 deletions
libqpdf/Pl_AES_PDF.cc
| 1 | #include <qpdf/Pl_AES_PDF.hh> | 1 | #include <qpdf/Pl_AES_PDF.hh> |
| 2 | #include <qpdf/QUtil.hh> | 2 | #include <qpdf/QUtil.hh> |
| 3 | -#include <qpdf/MD5.hh> | ||
| 4 | #include <cstring> | 3 | #include <cstring> |
| 5 | #include <assert.h> | 4 | #include <assert.h> |
| 6 | #include <stdexcept> | 5 | #include <stdexcept> |
| @@ -111,17 +110,10 @@ Pl_AES_PDF::initializeVector() | @@ -111,17 +110,10 @@ Pl_AES_PDF::initializeVector() | ||
| 111 | static bool seeded_random = false; | 110 | static bool seeded_random = false; |
| 112 | if (! seeded_random) | 111 | if (! seeded_random) |
| 113 | { | 112 | { |
| 114 | - std::string seed_str; | ||
| 115 | - seed_str += QUtil::int_to_string((int)QUtil::get_current_time()); | ||
| 116 | - seed_str += " QPDF aes random"; | ||
| 117 | - MD5 m; | ||
| 118 | - m.encodeString(seed_str.c_str()); | ||
| 119 | - MD5::Digest digest; | ||
| 120 | - m.digest(digest); | ||
| 121 | - assert(sizeof(digest) >= sizeof(unsigned int)); | ||
| 122 | - unsigned int seed; | ||
| 123 | - memcpy((void*)(&seed), digest, sizeof(unsigned int)); | ||
| 124 | - srandom(seed); | 113 | + // Seed the random number generator with something simple, but |
| 114 | + // just to be interesting, don't use the unmodified current | ||
| 115 | + // time.... | ||
| 116 | + srandom((int)QUtil::get_current_time() ^ 0xcccc); | ||
| 125 | seeded_random = true; | 117 | seeded_random = true; |
| 126 | } | 118 | } |
| 127 | for (unsigned int i = 0; i < this->buf_size; ++i) | 119 | for (unsigned int i = 0; i < this->buf_size; ++i) |