[*] i was taking a shit when i remembered our hashcash algorithm is fundamentally borked
This commit is contained in:
parent
b7de15d78e
commit
824602b1fa
@ -12,50 +12,87 @@ namespace Aurora::Crypto::HashCash
|
||||
{
|
||||
AUKN_SYM bool CheckSalt(AuUInt64 token, AuUInt8 power, const HashCashAnswer &answer)
|
||||
{
|
||||
AuUInt8 count {};
|
||||
AuArray<AuUInt8, 16> hashBuffer;
|
||||
|
||||
struct Hash
|
||||
for (AU_ITERATE_N(i, 2))
|
||||
{
|
||||
AuUInt64 token;
|
||||
AuUInt64 y;
|
||||
} hash;
|
||||
static_assert(sizeof(Hash) == 16);
|
||||
AuUInt64 uCoefficient {};
|
||||
|
||||
hash.token = token;
|
||||
hash.y = answer.y;
|
||||
AuArray<AuUInt8, 16> hashBuffer;
|
||||
if (i == 0)
|
||||
{
|
||||
AuHashing::RMD128(AuMemoryViewRead(&token, sizeof(token)), hashBuffer);
|
||||
uCoefficient = answer.y & 0xFFFFFFFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
AuHashing::RMD128(AuMemoryViewRead(&token, sizeof(token)), hashBuffer);
|
||||
AuHashing::RMD128(AuMemoryViewRead(hashBuffer.data(), hashBuffer.size()), hashBuffer);
|
||||
uCoefficient = (answer.y >> 32) & 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
AuHashing::RMD128(AuMemoryViewRead(&hash, 16), hashBuffer);
|
||||
AuWriteU64LE(hashBuffer.data(),
|
||||
hashBuffer.size() - 8,
|
||||
AuReadU64LE(hashBuffer.data(), hashBuffer.size() - 8) + uCoefficient);
|
||||
AuHashing::RMD128(AuMemoryViewRead(hashBuffer.data(), hashBuffer.size()), hashBuffer);
|
||||
|
||||
AuUInt8 count {};
|
||||
AuBitScanForward(count, AuReadU64LE(hashBuffer.data(), 0));
|
||||
|
||||
return count == power;
|
||||
if (count != power)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
AUKN_SYM HashCashAnswer FindAnswer(AuUInt64 token, AuUInt8 power)
|
||||
{
|
||||
HashCashAnswer answer;
|
||||
HashCashAnswer answer {};
|
||||
AuArray<AuUInt8, 16> refBuffer;
|
||||
AuArray<AuUInt8, 16> rollingBuffer;
|
||||
AuArray<AuUInt8, 16> hashBuffer;
|
||||
|
||||
struct Hash
|
||||
for (AU_ITERATE_N(i, 2))
|
||||
{
|
||||
AuUInt64 token;
|
||||
AuUInt64 y;
|
||||
} hash;
|
||||
static_assert(sizeof(Hash) == 16);
|
||||
|
||||
hash.token = token;
|
||||
hash.y = AuRng::RngU64();
|
||||
if (i == 0)
|
||||
{
|
||||
AuHashing::RMD128(AuMemoryViewRead(&token, sizeof(token)), refBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
AuHashing::RMD128(AuMemoryViewRead(&token, sizeof(token)), refBuffer);
|
||||
AuHashing::RMD128(AuMemoryViewRead(refBuffer.data(), refBuffer.size()), refBuffer);
|
||||
}
|
||||
|
||||
AuUInt64 uTicks {};
|
||||
AuUInt8 count {};
|
||||
do
|
||||
{
|
||||
hash.y++;
|
||||
AuHashing::RMD128(AuMemoryViewRead(&hash, 16), hashBuffer);
|
||||
rollingBuffer = refBuffer;
|
||||
|
||||
AuWriteU64LE(rollingBuffer.data(),
|
||||
rollingBuffer.size() - 8,
|
||||
AuReadU64LE(rollingBuffer.data(), rollingBuffer.size() - 8) + (uTicks++));
|
||||
|
||||
AuHashing::RMD128(AuMemoryViewRead(rollingBuffer.data(), rollingBuffer.size()),
|
||||
hashBuffer);
|
||||
}
|
||||
while (AuBitScanForward(count, AuReadU64LE(hashBuffer.data(), 0)), count != power);
|
||||
|
||||
answer.y = hash.y;
|
||||
uTicks--;
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
answer.y = uTicks;
|
||||
}
|
||||
else
|
||||
{
|
||||
answer.y |= uTicks << 32;
|
||||
}
|
||||
}
|
||||
|
||||
return answer;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user