/* This file has our secure PRNG code. On platforms that have arc4random(), *wejustusethat.Otherwise,weincludearc4random.casabunchofstatic *functions,andwrapitlightly.Wedon'texposethearc4random*()APIs *becauseA)theyaren'tinournamespace,andB)it'snotnicetonameyour *APIsaftertheirimplementations.Wekeeptheminaseparatefile *sothatotherpeoplecanripitoutanduseitforwhatever.
*/
#ifdefined(EVENT__HAVE_ARC4RANDOM_BUF) /* OSX 10.7 introducd arc4random_buf, so if you build your program *there,you'llgetsurprisedwhenolderversionsofOSXfailtorun. *Tosolvethis,wecancheckwhetherthefunctionpointerisset, *andfallbackotherwise.(OSXdoesthisusingsomelinker *trickery.)
*/
{ void (*tptr)(void *,size_t) =
(void (*)(void*,size_t))arc4random_buf; if (tptr != NULL) {
arc4random_buf(buf, n); return;
}
} #endif /* Make sure that we start out with b at a 4-byte alignment; plenty
* of CPUs care about this for 32-bit access. */ if (n >= 4 && ((ev_uintptr_t)b) & 3) {
ev_uint32_t u = arc4random(); int n_bytes = 4 - (((ev_uintptr_t)b) & 3);
memcpy(b, &u, n_bytes);
b += n_bytes;
n -= n_bytes;
} while (n >= 4) {
*(ev_uint32_t*)b = arc4random();
b += 4;
n -= 4;
} if (n) {
ev_uint32_t u = arc4random();
memcpy(b, &u, n);
} #endif
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.