[*] Improve time based RNG failover implementation
This commit is contained in:
parent
29226b8134
commit
115ee1a9ec
@ -170,47 +170,49 @@ namespace Aurora::RNG
|
||||
static AuUInt32 RngTimeBased(AuUInt8 *pBuf, AuUInt32 uLen)
|
||||
{
|
||||
AuUInt64 t1;
|
||||
int l, acc, bits, a, b, c;
|
||||
int acc, bits, a, b, c;
|
||||
|
||||
l = uLen;
|
||||
acc = a = b = c = 0;
|
||||
bits = 8;
|
||||
|
||||
void *pASLRSeed = &RngTimeBased;
|
||||
|
||||
while (uLen--)
|
||||
for (AU_ITERATE_N(uOffsetInByteStream, uLen))
|
||||
{
|
||||
while (bits--) // for each bit in byte
|
||||
for (AU_ITERATE_N(uMultiplePassesForTheFunOfIt, 3))
|
||||
{
|
||||
do
|
||||
while (bits--) // for each bit in byte
|
||||
{
|
||||
t1 = RngTimeClock();
|
||||
while (t1 == RngTimeClock()) // spin within 1 microseconds
|
||||
do
|
||||
{
|
||||
a ^= 1; // flip
|
||||
}
|
||||
t1 = RngTimeClock();
|
||||
while (t1 == RngTimeClock()) // spin within 1 microseconds
|
||||
{
|
||||
a ^= 1; // flip
|
||||
}
|
||||
|
||||
t1 = RngTimeClock();
|
||||
while (t1 == RngTimeClock()) // spin within 1 microseconds
|
||||
{
|
||||
b ^= 1; // flip
|
||||
t1 = RngTimeClock();
|
||||
while (t1 == RngTimeClock()) // spin within 1 microseconds
|
||||
{
|
||||
b ^= 1; // flip
|
||||
}
|
||||
}
|
||||
while (a == b); // ensure theres enough entropy for a deviation to occur
|
||||
acc = (acc << 1) | a; // push the first bit state
|
||||
}
|
||||
while (a == b); // ensure theres enough entropy for a deviation to occur
|
||||
acc = (acc << 1) | a; // push the first bit state
|
||||
|
||||
acc = 0;
|
||||
bits = 8;
|
||||
|
||||
c = AuFnv1a32Runtime(&acc, sizeof(acc)) ^
|
||||
(AuFnv1a32Runtime(&c, sizeof(c)) * kFnv1MagicPrime32) ^
|
||||
(a ? AuFnv1a32Runtime(&pASLRSeed, sizeof(pASLRSeed)) : 0);
|
||||
}
|
||||
|
||||
*pBuf = AuFnv1a32Runtime(&acc, sizeof(acc)) ^
|
||||
AuFnv1a32Runtime(&c, sizeof(c)) ^
|
||||
AuFnv1a32Runtime(&pASLRSeed, sizeof(pASLRSeed));
|
||||
|
||||
c = *pBuf++;
|
||||
|
||||
acc = 0;
|
||||
bits = 8;
|
||||
*pBuf++ = AuUInt8(c);
|
||||
}
|
||||
|
||||
return l;
|
||||
return uLen;
|
||||
}
|
||||
|
||||
AuUInt32 RngGetBytes(AuUInt8 *pBuffer, AuUInt32 uBytes)
|
||||
|
Loading…
Reference in New Issue
Block a user