I'm principally interested in the implementation of SecRandomCopyBytes
on iOS, if it differs from the OS X implementation. (I would presume that it does, since a mobile device has more and more readily available sources of entropy than a desktop computer.)
Does anyone have information on:
- Where SecRandomCopyBytes gets entropy from?
- What rate it can generate good random numbers?
- Will it block, or fail immediately if not enough entropy is available?
- Is it FIPS 140-2 compliant, or has it been included in any other official certification?
The documentation does not cover these points.
I've only been able to find hear-say comments that it uses information from radios, the compass, accelerometers and other sources, but no quotes from people actually representing Apple.
/dev/random is fed by entropy from the SecurityServer. SecurityServer collecting entropy from the kernel event tracking (kdebug). The method is described in the book "Mac OS X Internals. A Systems Approach". You can read about it online for example at http://flylib.com/books/en/3.126.1.73/1/
the source code for the entropy collecting is here: http://www.opensource.apple.com/source/securityd/securityd-40600/src/entropy.cpp
In xnu-1504.9.37 (latest version for OS X as of writing), the kernel entropy buffer is filled in kernel_debug_internal()
, using only timing information. This is the only place that the entropy buffer is written to.
if (entropy_flag && (kdebug_enable & KDEBUG_ENABLE_ENTROPY)) {
if (kd_entropy_indx < kd_entropy_count) {
kd_entropy_buffer [ kd_entropy_indx] = mach_absolute_time();
kd_entropy_indx++;
}
if (kd_entropy_indx == kd_entropy_count) {
/*
* Disable entropy collection
*/
kdebug_enable &= ~KDEBUG_ENABLE_ENTROPY;
kdebug_slowcheck &= ~SLOW_ENTROPY;
}
}
The iOS SDK clearly states that this function uses the output of /dev/random
for retrieving the secure random data. As iOS is a ported version of OSX which itself is in it's core a Free-BSD.
If you seach for /dev/random
and OSX you find several posts that there was (and my be is) a problem regarding the entropy collection in OSX:
http://www.mail-archive.com/cryptography@metzdowd.com/msg00620.html
Therefore I would expect that /dev/random
works not better than the one in OSX.