Differences From Artifact [54579841e3]:
- File
src/OFObject.m
— part of check-in
[c1fe4b2b77]
at
2020-07-12 09:49:35
on branch trunk
— Make of_random() a function
When arc4random() is unavailable, either random() or rand() is used and
both need to be seeded. If of_random() is a macro, it needs to be
(re)seeded every time, as it's unknown whether it has already been
seeded. As it is seeded with gettimeofday() due to the lack of a better
initial seed, this means every call returns the first state for the
current time, which is very predictable. random() and rand() are both
not cryptographic, but this should at least make it a little bit better
now. (user: js, size: 30665) [annotate] [blame] [check-ins using]
To Artifact [d3c7a17532]:
- File src/OFObject.m — part of check-in [ba1135b0b2] at 2020-07-12 10:00:16 on branch trunk — Add support for getrandom() (user: js, size: 30806) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
119 120 121 122 123 124 125 | # endif } #endif uint32_t of_random(void) { | | > > > > > > | 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | # endif } #endif uint32_t of_random(void) { #if defined(HAVE_ARC4RANDOM) return arc4random(); #elif defined(HAVE_GETRANDOM) uint32_t buffer; OF_ENSURE(getrandom(&buffer, sizeof(buffer), 0) == sizeof(buffer)); return buffer; #else static of_once_t onceControl; of_once(&onceControl, initRandom); # ifdef HAVE_RANDOM return (((uint32_t)(random()) << 16) | ((uint32_t)(random()) & 0xFFFF)); # else |
︙ | ︙ |