Reece Wilson
8a2947ffc5
[*] Refactor bcrypt api: HashPW[Ex] -> HashPassword[Ex] [+] ByteBuffer::GetOrAllocateLinearWriteable [+] ByteBuffer::Can[Read/Write](n) [+] ByteBuffer::GetLinear[Read/Writable]able(n) [*] Split RNG.cpp into two files [+] EHashType::eSHA2_48 (_32, _64 was already in place. missed 48/384 bit) [+] AuCrypto::HMAC and IHMACContext (AuHashing) [+] EHashType::eSHA3_28 [+] EHashType::eSHA3_32 [+] EHashType::eSHA3_48 [+] EHashType::eSHA3_64 (AuCrypto) [+] EHashType::eSHA2_48_384 [+] EHashType::eSHA2_64_512 [+] EHashType::eSHA3_28_224 [+] EHashType::eSHA3_32_256 [+] EHashType::eSHA3_48_384 [+] EHashType::eSHA3_64_512 [*] (IRandomDevice) class -> struct [*] Bugfix: cast in Promise<SuccessValue_t, ErrorValue_t>::WriteIntoError [+] Missing AuHashing namespace alias [*] Time util: pad ms when fraction of a second to 3 digits
61 lines
1.4 KiB
C++
61 lines
1.4 KiB
C++
/***
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: HashCash.cpp
|
|
Date: 2022-9-18
|
|
Author: Reece
|
|
***/
|
|
#include <Source/RuntimeInternal.hpp>
|
|
#include "HashCash.hpp"
|
|
|
|
namespace Aurora::Crypto::HashCash
|
|
{
|
|
AUKN_SYM bool CheckSalt(AuUInt64 token, AuUInt8 power, const HashCashAnswer &answer)
|
|
{
|
|
AuUInt8 count {};
|
|
AuArray<AuUInt8, 16> hashBuffer;
|
|
|
|
struct Hash
|
|
{
|
|
AuUInt64 token;
|
|
AuUInt64 y;
|
|
} hash;
|
|
static_assert(sizeof(Hash) == 16);
|
|
|
|
hash.token = token;
|
|
hash.y = answer.y;
|
|
|
|
AuHashing::RMD128(AuMemoryViewRead(&hash, 16), hashBuffer);
|
|
|
|
AuBitScanForward(count, AuReadU64LE(hashBuffer.data(), 0));
|
|
|
|
return count == power;
|
|
}
|
|
|
|
AUKN_SYM HashCashAnswer FindAnswer(AuUInt64 token, AuUInt8 power)
|
|
{
|
|
HashCashAnswer answer;
|
|
AuArray<AuUInt8, 16> hashBuffer;
|
|
|
|
struct Hash
|
|
{
|
|
AuUInt64 token;
|
|
AuUInt64 y;
|
|
} hash;
|
|
static_assert(sizeof(Hash) == 16);
|
|
|
|
hash.token = token;
|
|
hash.y = AuRng::RngU64();
|
|
|
|
AuUInt8 count {};
|
|
do
|
|
{
|
|
hash.y++;
|
|
AuHashing::RMD128(AuMemoryViewRead(&hash, 16), hashBuffer);
|
|
}
|
|
while (AuBitScanForward(count, AuReadU64LE(hashBuffer.data(), 0)), count != power);
|
|
|
|
answer.y = hash.y;
|
|
return answer;
|
|
}
|
|
} |