On x86, you can use the TimeStampCounter, with the RDTSC instruction.
That’s a 64-bit number that wraps every two seconds (@2GHz, obviously every
4 seconds at 1GHz, etc) on the lower 32-bits, so pretty much random from
start of the machine, unless your driver is the very first to start. And as
far as I can tell, it’s precise to within 2 bits of the whole range, so you
have 31 bits of relatively “random” data.
TSC is available on Pentium/AMD K5 and onwards. It’s also available on
AMD64. I’m unsure about the availability on Itanium, but I would certainly
assume that it’s there too.
Also, Windows NT+ has a “time of day” that is precise to 100ns (although
maybe only updated very x ms), which if you only take the lower part of it,
will be relatively random, but not half as good as TSC.
If you want less portable methods (I’m only mentioning this for
completeness), you can read the 8254 Timer/Counter chip, which has a set of
counters that will have some “random” count in them, located IO port
0x40-0x43. That’s not available on Itanium, I would expect, and also
possibly going away on modern PC’s, but it’s required for DOS-compatibility
(really well-behaved DOS apps will work without it, but anything like
Borland Pascal or Turbo C/C++ based apps would definitely have problems
with running on a machine that doesn’t have this hardware, same with many
other apps based on MS Compilers, I would suspect).
–
Mats
xxxxx@lists.osr.com wrote on 10/08/2004 03:55:39 PM:
> It’s also actually trivial to write your own robust
> pseudo-random number
> generator. Use Mitchell and Moore’s additive generator described by
> Knuth (in Seminumerical Algorithms). It’s insanely fast, has a huge
> period, and other desireable properties of a pseudo-random number
> generator. Note if you do write your own, and you care about the
> “randomness” of your numbers, use an established and preferrably
> well-studied algorithm (there’s lots of interesting ones in
> Knuth), and
> don’t mess with it, unless you’re really really really good at math.
> It’s quite hard to make a sequence more random, yet extremely easy to
> make one less random.
Not to thread hijack (sorry OP), but I’ve recently been curious about
good
seed sources for a PRNG in kernel-mode during various stages of boot. My
understanding is that the crypto API in user-mode (aside from allowing
the
caller to supply their own entropy) gathers entropy from various info
classes (SystemPerformanceInformation, SystemTimeOfDayInformation,
SystemProcessorStatistics, etc).
During various stages of boot this information is likely to not have a
wide
range of variance other than TimeOfDay which, for one who desires a
cryptographically secure PRNG, is not a positive thing. Am I correct in
thinking that this information will not vary much?
Aside from info classes, what are some other sources that are portable
and
good for gathering entropy (portable from W2K+) that don’t require
intrusive
means of obtaining them?
Questions? First check the Kernel Driver FAQ at http://www.
osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@3dlabs.com
To unsubscribe send a blank email to xxxxx@lists.osr.com
ForwardSourceID:NT00004FE6