[*] Hash WELL outputs (ABI break once again >:( )

[*] Rework/Fix WELL_NextBytes (large) improperly accounting for small buffers (this internal function is publicly visible. WELL_NextLong isn't going to save us)
This commit is contained in:
Reece Wilson 2024-04-18 05:06:40 +01:00
parent 62917318af
commit 616fc54531

View File

@ -89,7 +89,7 @@ auline AuUInt32 WELL_NextLong_Unlocked(WELLRand *rand)
a = rand->state[rand->index];
rand->state[rand->index] = a ^ b ^ d ^ (a << 2) ^ (b << 18) ^ (c << 28);
ret = rand->state[rand->index];
return ret;
return AuFnv1a32Runtime(&ret, sizeof(ret));
}
/**
@ -104,23 +104,25 @@ AuUInt32 WELL_NextLong(WELLRand *rand)
void WELL_NextBytes(WELLRand *rand, void *in, AuUInt32 length)
{
AuUInt i;
AuUInt i, b;
AuUInt8 *base;
i = 0;
b = length / 4;
base = reinterpret_cast<AuUInt8 *>(in);
AU_LOCK_GUARD(rand->lock);
for (; i < length; i += 4)
for (; i < b; i++)
{
AuUInt32 rng = WELL_NextLong_Unlocked(rand);
AuMemcpy(base + i, &rng, 4);
AuWriteU32(base, i * 4, rng);
}
if (i > length)
i *= 4;
if (i != length)
{
i -= 4;
AuUInt32 padRng = WELL_NextLong_Unlocked(rand);
AuMemcpy(base + i, &padRng, length - i);
}