mirror of
https://github.com/qpdf/qpdf.git
synced 2025-02-08 22:58:25 +00:00
use a simpler seed for the random number generator
git-svn-id: svn+q:///qpdf/trunk@821 71b93d88-0707-0410-a8cf-f5a4172ac649
This commit is contained in:
parent
34097d6c64
commit
f0211d954c
@ -1,6 +1,5 @@
|
|||||||
#include <qpdf/Pl_AES_PDF.hh>
|
#include <qpdf/Pl_AES_PDF.hh>
|
||||||
#include <qpdf/QUtil.hh>
|
#include <qpdf/QUtil.hh>
|
||||||
#include <qpdf/MD5.hh>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
@ -111,17 +110,10 @@ Pl_AES_PDF::initializeVector()
|
|||||||
static bool seeded_random = false;
|
static bool seeded_random = false;
|
||||||
if (! seeded_random)
|
if (! seeded_random)
|
||||||
{
|
{
|
||||||
std::string seed_str;
|
// Seed the random number generator with something simple, but
|
||||||
seed_str += QUtil::int_to_string((int)QUtil::get_current_time());
|
// just to be interesting, don't use the unmodified current
|
||||||
seed_str += " QPDF aes random";
|
// time....
|
||||||
MD5 m;
|
srandom((int)QUtil::get_current_time() ^ 0xcccc);
|
||||||
m.encodeString(seed_str.c_str());
|
|
||||||
MD5::Digest digest;
|
|
||||||
m.digest(digest);
|
|
||||||
assert(sizeof(digest) >= sizeof(unsigned int));
|
|
||||||
unsigned int seed;
|
|
||||||
memcpy((void*)(&seed), digest, sizeof(unsigned int));
|
|
||||||
srandom(seed);
|
|
||||||
seeded_random = true;
|
seeded_random = true;
|
||||||
}
|
}
|
||||||
for (unsigned int i = 0; i < this->buf_size; ++i)
|
for (unsigned int i = 0; i < this->buf_size; ++i)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user