|
Boost Users : |
Subject: Re: [Boost-users] Seeding boost::mt19937 with bytes from CryptoGenRandom
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-02-11 10:37:31
AMDG
Ovanes Markarian wrote:
> On Thu, Feb 11, 2010 at 5:58 AM, Steven Watanabe <watanabesj_at_[hidden]>wrote:
>
>> uint64_t seed;
>> memcpy(&seed, &randomBytes[0], sizeof(seed));
>>
> at first this solution seemed to me pretty cool. As far as I understand seed
> will contain some value from stack. The only question is how probable is it,
> that seed is always initialized with a different value?
>
I was assuming that the code I wrote was prefixed with
HCRYPTPROV hProvider = 0;
BYTE randomBytes[8];
CryptAcquireContext(&hProvider, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
CryptGenRandom(hProvider, sizeof(randomBytes), randomBytes);
CryptReleaseContext(hProvider, 0);
The memcpy should copy from randomBytes into seed. (Assuming I
haven't forgotten the signature of memcpy.)
In Christ,
Steven Watanabe
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net