AuroraRuntime/Source/RNG/RNG.cpp
Reece Wilson 8a2947ffc5 [+] RMD128+BScFwd based HashCash (bcrypt DoS mitigation, acc creation, antibot, etc)
[*] 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
2022-09-19 02:34:57 +01:00

60 lines
1.3 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: RNG.cpp
Date: 2021-6-11
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "RNG.hpp"
#include "RNGEntropy.hpp"
#include "WELL.hpp"
namespace Aurora::RNG
{
static WELLRand gWellRand;
RandomUnique_t gFastDevice;
AUKN_SYM void ReadSecureRNG(void *in, AuUInt32 length)
{
AuUInt32 offset;
AuUInt8 *headPtr;
headPtr = reinterpret_cast<AuUInt8 *>(in);
offset = 0;
while (offset != length)
{
auto req = length - offset;
auto bytes = RngGetBytes(headPtr + offset, req);
SysAssertExp(bytes, "Couldn't consume {} RNG bytes", req);
offset += bytes;
}
}
AUKN_SYM void ReadFastRNG(void *in, AuUInt32 length)
{
WELL_NextBytes(&gWellRand, in, length);
}
static void InitFastRng()
{
AuArray<AuUInt8, 64> maxEntropy;
RngFillArray<false, AuUInt8>(maxEntropy.data(), 64);
gWellRand = WELL_SeedRandBig64(maxEntropy);
RandomDef fast;
fast.secure = false;
gFastDevice = RandomUnique(fast);
}
void Init()
{
EntropyInit();
InitFastRng();
}
void Release()
{
EntropyDeinit();
}
}