[*] Linux should not raise int3 unless the binary is a debug one
TODO: investigate registering an int3 signal handler to prevent crashing under internal builds [*] Amend MemoryViews [*] Begin shifting towards MemoryView based binary APIs [*] Fix public RSA key leak [+] Some clean up and possible bug fixes
This commit is contained in:
parent
e0ac8344d0
commit
510928e62e
@ -9,8 +9,7 @@
|
||||
|
||||
namespace Aurora::Crypto::AES
|
||||
{
|
||||
AUKN_SYM AuUInt GetSafeCipherPadding(const void* plainText,
|
||||
AuUInt plainTextLength);
|
||||
AUKN_SYM AuUInt GetSafeCipherPadding(Memory::MemoryViewRead plainText);
|
||||
|
||||
// Remember: AES works in chunks of 128 bits
|
||||
// IVS are 16 bytes long
|
||||
@ -21,15 +20,17 @@ namespace Aurora::Crypto::AES
|
||||
// It is not the end of the world if an IV is made public by design
|
||||
// Keys must be random
|
||||
// Initialization vectors could be derived from SHA1, Tiger, or SHA2 digests
|
||||
AUKN_SYM bool Encrypt(const void* plainText, AuUInt plainTextLength,
|
||||
const void* iv, void* outIv, AuUInt ivLength,
|
||||
const void* key, AuUInt keyLength,
|
||||
AuList<AuUInt8>& out,
|
||||
AUKN_SYM bool Encrypt(Memory::MemoryViewRead plainText,
|
||||
Memory::MemoryViewRead inIv,
|
||||
Memory::MemoryViewWrite outIv,
|
||||
Memory::MemoryViewRead inKey,
|
||||
AuList<AuUInt8> &out,
|
||||
bool auCoolCodePadding);
|
||||
|
||||
AUKN_SYM bool Decrypt(const void* cipherText, AuUInt cipherTextLength,
|
||||
const void* iv, void* outIv, AuUInt ivLength,
|
||||
const void* key, AuUInt keyLength,
|
||||
AUKN_SYM bool Decrypt(Memory::MemoryViewRead cipherText,
|
||||
Memory::MemoryViewRead inIv,
|
||||
Memory::MemoryViewWrite outIv,
|
||||
Memory::MemoryViewRead inKey,
|
||||
AuList<AuUInt8>& plainText,
|
||||
bool auCoolCodePadding);
|
||||
}
|
@ -17,8 +17,11 @@ namespace Aurora::Crypto::CA
|
||||
class ICertificateStore
|
||||
{
|
||||
public:
|
||||
virtual void AddSignature(const AuSPtr<RSA::IRSAPublic>& CA, const AuList<AuUInt8>& sig,
|
||||
EHashType method, EPaddingType type) = 0;
|
||||
virtual void AddSignature(const AuSPtr<RSA::IRSAPublic>& CA,
|
||||
const AuList<AuUInt8>& sig,
|
||||
EHashType method,
|
||||
EPaddingType type) = 0;
|
||||
|
||||
virtual void AddPublicCert(const X509::Certificate& cert) = 0;
|
||||
|
||||
/// For future support of http gets of the CA list
|
||||
|
@ -7,5 +7,49 @@
|
||||
***/
|
||||
#pragma once
|
||||
|
||||
namespace Aurora::Crypto::ECC
|
||||
{
|
||||
#if 0
|
||||
class IECCPublic
|
||||
{
|
||||
public:
|
||||
|
||||
virtual bool Verify(const void *hash, AuUInt hashLength,
|
||||
const void *sigBuffer, AuUInt sigLength) = 0;
|
||||
|
||||
virtual bool Verify(const void *buffer, AuUInt length,
|
||||
const void *sigBuffer, AuUInt sigLength,
|
||||
EHashType method) = 0;
|
||||
|
||||
virtual bool Verify(const AuList<AuUInt8> &buffer, const AuList<AuUInt8> &sig,
|
||||
EHashType method) = 0;
|
||||
|
||||
|
||||
virtual bool AsPublicECC(PublicECCKey &out) = 0;
|
||||
};
|
||||
|
||||
class IECCPrivate
|
||||
{
|
||||
public:
|
||||
virtual bool Sign(const void *buffer, AuUInt length,
|
||||
EHashType method,
|
||||
AuList<AuUInt8> &out) = 0;
|
||||
|
||||
virtual bool Sign(const AuList<AuUInt8> &in,
|
||||
EHashType method,
|
||||
AuList<AuUInt8> &out) = 0;
|
||||
|
||||
|
||||
virtual bool Sign(const void *hash, AuUInt hashLength, AuList<AuUInt8> &out) = 0;
|
||||
|
||||
virtual bool ECDH(IECCPublic *partnerPublic, AuList<AuUInt8> &sharedKey) = 0;
|
||||
|
||||
|
||||
virtual bool AsPublicECC(PublicECCKey &out) = 0;
|
||||
virtual bool AsPrivateECC(PrivateECCKey &out) = 0;
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
#include "25519/25519.hpp"
|
||||
#include "NIST/NIST.hpp"
|
@ -13,15 +13,14 @@ namespace Aurora::Crypto::RSA
|
||||
class IRSAPrivate
|
||||
{
|
||||
public:
|
||||
virtual bool Sign(const void *buffer, AuUInt length,
|
||||
EHashType method, EPaddingType type,
|
||||
AuList<AuUInt8> &out) = 0;
|
||||
virtual bool Sign(const AuList<AuUInt8> &in,
|
||||
EHashType method, EPaddingType type,
|
||||
virtual bool Sign(Memory::MemoryViewRead payload,
|
||||
EHashType method,
|
||||
EPaddingType type,
|
||||
AuList<AuUInt8> &out) = 0;
|
||||
|
||||
virtual bool Decrypt(const void *buffer, AuUInt length, EPaddingType type, AuList<AuUInt8> &out) = 0;
|
||||
virtual bool Decrypt(const AuList<AuUInt8> &in, EPaddingType type, AuList<AuUInt8> &out) = 0;
|
||||
virtual bool Decrypt(Memory::MemoryViewRead payload,
|
||||
EPaddingType type,
|
||||
AuList<AuUInt8> &out) = 0;
|
||||
|
||||
virtual AuSPtr<IRSAPublic> ToPublic() = 0;
|
||||
|
||||
|
@ -13,16 +13,14 @@ namespace Aurora::Crypto::RSA
|
||||
class IRSAPublic
|
||||
{
|
||||
public:
|
||||
virtual bool Verify(const void *buffer, AuUInt length,
|
||||
const void *sigBuffer, AuUInt sigLength,
|
||||
virtual bool Verify(Memory::MemoryViewRead payload,
|
||||
Memory::MemoryViewRead signature,
|
||||
EHashType method,
|
||||
EPaddingType type) = 0;
|
||||
|
||||
virtual bool Verify(const AuList<AuUInt8> &buffer, const AuList<AuUInt8> &sig,
|
||||
EHashType method, EPaddingType type) = 0;
|
||||
|
||||
virtual bool Encrypt(const void *buffer, AuUInt length, EPaddingType type, AuList<AuUInt8> &out) = 0;
|
||||
virtual bool Encrypt(const AuList<AuUInt8> &in, EPaddingType type, AuList<AuUInt8> &out) = 0;
|
||||
virtual bool Encrypt(Memory::MemoryViewRead plainText,
|
||||
EPaddingType type,
|
||||
AuList<AuUInt8> &out) = 0;
|
||||
|
||||
virtual bool ToKey(ERSAKeyType type, AuList<AuUInt8> &out) = 0;
|
||||
};
|
||||
|
@ -11,7 +11,7 @@ namespace Aurora::Data
|
||||
{
|
||||
enum class DataType
|
||||
{
|
||||
kTypeUInt, // Human friendly types
|
||||
kTypeUInt, // Human friendly types, used by parse, inherited by struct type members
|
||||
kTypeSInt,
|
||||
kTypeNumber,
|
||||
kTypeString,
|
||||
@ -20,7 +20,7 @@ namespace Aurora::Data
|
||||
kTypeVec3,
|
||||
kTypeVec4,
|
||||
|
||||
kTypeGenericMax, // Binary serialization
|
||||
kTypeGenericMax, // Binary serialization, inherit pare types
|
||||
|
||||
kTypeStructFloat,
|
||||
kTypeStructUInt8,
|
||||
@ -30,13 +30,13 @@ namespace Aurora::Data
|
||||
kTypeStructUInt32,
|
||||
kTypeStructInt32,
|
||||
|
||||
kTypeSpecialComponent, // Special QST
|
||||
kTypeSpecialComponent, // Special QST types
|
||||
kTypeSpecialArray, //
|
||||
kTypeSpecialObject, //
|
||||
kTypeSpecialReserved1, //
|
||||
kTypeSpecialReserved2, //
|
||||
kTypeSpecialReserved3, //
|
||||
kTypeSpecialReserved4, //
|
||||
kTypeSpecialReserved1, // User definable
|
||||
kTypeSpecialReserved2 = kTypeSpecialReserved1 + 20, //
|
||||
kTypeSpecialReserved3 = kTypeSpecialReserved2 + 20, //
|
||||
kTypeSpecialReserved4 = kTypeSpecialReserved3 + 20, //
|
||||
|
||||
kTypeEND,
|
||||
|
||||
|
@ -23,19 +23,18 @@ namespace Aurora::IO::Buffered
|
||||
return EStreamError::eErrorNone;
|
||||
}
|
||||
|
||||
virtual EStreamError ArbitraryRead(AuUInt32 offset, void *buffer, AuUInt32 &len) override
|
||||
virtual EStreamError ArbitraryRead(AuUInt32 offset, Memory::MemoryViewStreamWrite paramters) override
|
||||
{
|
||||
auto oldLen = std::exchange(len, 0);
|
||||
if (buffer_.empty()) return EStreamError::eErrorEndOfStream;
|
||||
|
||||
auto endOffset = offset + oldLen;
|
||||
auto realEndOffset = std::min(AuUInt32(buffer_.size()), endOffset);
|
||||
auto endOffset = offset + paramters.length;
|
||||
auto realEndOffset = std::min(buffer_.size(), endOffset);
|
||||
auto actualLength = realEndOffset - offset;
|
||||
|
||||
if (actualLength < 0) return EStreamError::eErrorEndOfStream;
|
||||
|
||||
len = actualLength;
|
||||
std::memcpy(buffer, buffer_.data() + offset, len);
|
||||
paramters.outVariable = actualLength;
|
||||
std::memcpy(paramters.ptr, buffer_.data() + offset, paramters.outVariable);
|
||||
|
||||
return EStreamError::eErrorNone;
|
||||
}
|
||||
|
@ -23,15 +23,13 @@ namespace Aurora::IO::Buffered
|
||||
return EStreamError::eErrorNone;
|
||||
}
|
||||
|
||||
virtual EStreamError Read(void *buffer, AuUInt32 &len) override
|
||||
virtual EStreamError Read(Memory::MemoryViewStreamWrite paramters) override
|
||||
{
|
||||
auto oldLen = std::exchange(len, 0);
|
||||
|
||||
auto realEndOffset = std::min(AuUInt32(buffer_.size()) - offset_, oldLen);
|
||||
auto realEndOffset = std::min(buffer_.size() - offset_, paramters.length);
|
||||
if (realEndOffset == 0) return EStreamError::eErrorEndOfStream;
|
||||
|
||||
len = realEndOffset;
|
||||
std::memcpy(buffer, buffer_.data() + offset_, len);
|
||||
paramters.outVariable = realEndOffset;
|
||||
std::memcpy(paramters.ptr, buffer_.data() + offset_, realEndOffset);
|
||||
offset_ += realEndOffset;
|
||||
|
||||
return EStreamError::eErrorNone;
|
||||
|
@ -22,11 +22,11 @@ namespace Aurora::IO::Buffered
|
||||
return EStreamError::eErrorNone;
|
||||
}
|
||||
|
||||
virtual EStreamError Write(const void *buffer, AuUInt32 len) override
|
||||
virtual EStreamError Write(Memory::MemoryViewStreamRead parameters) override
|
||||
{
|
||||
auto idx = buffer_.size();
|
||||
buffer_.resize(idx + len);
|
||||
std::memcpy(buffer_.data() + idx, buffer, len);
|
||||
buffer_.resize(idx + parameters.length);
|
||||
std::memcpy(buffer_.data() + idx, parameters.ptr, buffer_.size() - idx);
|
||||
return EStreamError::eErrorNone;
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@ namespace Aurora::IO::FS
|
||||
class IAsyncTransaction
|
||||
{
|
||||
public:
|
||||
// Do not switch to Aurora::Memory::MemoryView, you must use a raw pointer to the parent RAII object that effectively owns the IAsyncTransaction
|
||||
virtual bool StartRead(AuUInt64 offset, void *, AuUInt32 length) = 0;
|
||||
virtual bool StartWrite(AuUInt64 offset, const void *, AuUInt32 length) = 0;
|
||||
|
||||
|
@ -21,7 +21,7 @@ namespace Aurora::IO::FS
|
||||
*/
|
||||
AUKN_SYM bool DirsInDirectory(const AuString &string, AuList<AuString> &dirs);
|
||||
|
||||
AUKN_SYM bool WriteFile(const AuString &path, const void *data, size_t length);
|
||||
AUKN_SYM bool WriteFile(const AuString &path, const void *data, AuUInt length);
|
||||
AUKN_SYM bool WriteString(const AuString &path, const AuString &str);
|
||||
|
||||
AUKN_SYM bool ReadFile(const AuString &path, AuList<uint8_t> &buffer);
|
||||
|
@ -29,13 +29,12 @@ namespace Aurora::IO::FS
|
||||
return stream_ ? EStreamError::eErrorNone : EStreamError::eErrorStreamInterrupted;
|
||||
}
|
||||
|
||||
virtual EStreamError ArbitraryRead(AuUInt32 offset, void *buffer, AuUInt32 &len) override
|
||||
virtual EStreamError ArbitraryRead(AuUInt32 offset, Memory::MemoryViewStreamWrite paramters) override
|
||||
{
|
||||
auto oldLen = std::exchange(len, 0);
|
||||
if (!stream_) return EStreamError::eErrorStreamNotOpen;
|
||||
stream_->SetOffset(offset);
|
||||
len = stream_->Read(buffer, oldLen);
|
||||
if (len == 0) return EStreamError::eErrorEndOfStream;
|
||||
if (!stream_->SetOffset(offset)) return EStreamError::eErrorEndOfStream;
|
||||
if (!stream_->Read(paramters)) return EStreamError::eErrorStreamInterrupted;
|
||||
if (paramters.outVariable== 0) return EStreamError::eErrorEndOfStream;
|
||||
return EStreamError::eErrorNone;
|
||||
}
|
||||
|
||||
|
@ -29,12 +29,11 @@ namespace Aurora::IO::FS
|
||||
return stream_ ? EStreamError::eErrorNone : EStreamError::eErrorStreamInterrupted;
|
||||
}
|
||||
|
||||
virtual EStreamError Read(void *buffer, AuUInt32 &len) override
|
||||
virtual EStreamError Read(Memory::MemoryViewStreamWrite paramters) override
|
||||
{
|
||||
auto oldLen = std::exchange(len, 0);
|
||||
if (!stream_) return EStreamError::eErrorStreamNotOpen;
|
||||
len = stream_->Read(buffer, oldLen);
|
||||
if (len == 0) return EStreamError::eErrorEndOfStream;
|
||||
if (!stream_->Read(paramters)) return EStreamError::eErrorStreamInterrupted;
|
||||
if (paramters.outVariable == 0) return EStreamError::eErrorEndOfStream;
|
||||
return EStreamError::eErrorNone;
|
||||
}
|
||||
|
||||
|
@ -15,8 +15,8 @@ namespace Aurora::IO::FS
|
||||
virtual AuUInt64 GetOffset() = 0;
|
||||
virtual bool SetOffset(AuUInt64 offset) = 0;
|
||||
virtual AuUInt64 GetLength() = 0;
|
||||
virtual AuUInt64 Read(void *in, AuUInt64 length) = 0;
|
||||
virtual AuUInt64 Write(const void *out, AuUInt64 length) = 0;
|
||||
virtual bool Read(Memory::MemoryViewStreamWrite parameters) = 0;
|
||||
virtual bool Write(Memory::MemoryViewStreamRead parameters) = 0;
|
||||
virtual void Close() = 0;
|
||||
virtual void Flush() = 0;
|
||||
};
|
||||
|
@ -29,12 +29,12 @@ namespace Aurora::IO::FS
|
||||
return stream_ ? EStreamError::eErrorNone : EStreamError::eErrorStreamInterrupted;
|
||||
}
|
||||
|
||||
virtual EStreamError Write(const void *buffer, AuUInt32 len) override
|
||||
virtual EStreamError Write(Memory::MemoryViewStreamRead parameters) override
|
||||
{
|
||||
if (!stream_) return EStreamError::eErrorStreamNotOpen;
|
||||
len = stream_->Write(buffer, len);
|
||||
if (len == 0) return EStreamError::eErrorEndOfStream;
|
||||
if (len != len) return EStreamError::eErrorStreamInterrupted;
|
||||
if (!stream_->Write(parameters)) return EStreamError::eErrorStreamInterrupted;
|
||||
if (parameters.outVariable == 0) return EStreamError::eErrorEndOfStream;
|
||||
if (parameters.outVariable != parameters.length) return EStreamError::eErrorStreamInterrupted;
|
||||
return EStreamError::eErrorNone;
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ namespace Aurora::IO
|
||||
{
|
||||
public:
|
||||
virtual EStreamError Open() = 0;
|
||||
virtual EStreamError ArbitraryRead(AuUInt32 offset, void *buffer, AuUInt32 &len) = 0;
|
||||
virtual EStreamError ArbitraryRead(AuUInt32 offset, Memory::MemoryViewStreamWrite paramters) = 0;
|
||||
virtual void Close() = 0;
|
||||
};
|
||||
}
|
@ -13,7 +13,7 @@ namespace Aurora::IO
|
||||
{
|
||||
public:
|
||||
virtual EStreamError Open() = 0;
|
||||
virtual EStreamError Read(void *buffer, AuUInt32 &len) = 0;
|
||||
virtual EStreamError Read(Memory::MemoryViewStreamWrite paramters) = 0;
|
||||
virtual void Close() = 0;
|
||||
|
||||
EStreamError ReadAll(AuList<AuUInt8> &buffer)
|
||||
@ -21,10 +21,10 @@ namespace Aurora::IO
|
||||
static const int kBufferSize = 2048;
|
||||
AuUInt8 temp[kBufferSize];
|
||||
|
||||
AuUInt32 len = kBufferSize;
|
||||
AuUInt len = kBufferSize;
|
||||
EStreamError ret = EStreamError::eErrorEndOfStream;
|
||||
|
||||
while ((ret = Read(temp, len)) == EStreamError::eErrorNone)
|
||||
while ((ret = Read(Memory::MemoryViewStreamWrite(temp, len))) == EStreamError::eErrorNone)
|
||||
{
|
||||
if (len == 0)
|
||||
{
|
||||
|
@ -13,7 +13,7 @@ namespace Aurora::IO
|
||||
{
|
||||
public:
|
||||
virtual EStreamError Open() = 0;
|
||||
virtual EStreamError Write(const void *buffer, AuUInt32 len) = 0;
|
||||
virtual EStreamError Write(Memory::MemoryViewStreamRead parameters) = 0;
|
||||
virtual void Flush() = 0;
|
||||
virtual void Close() = 0;
|
||||
};
|
||||
|
69
Include/Aurora/Loop/nnnnn.txt
Normal file
69
Include/Aurora/Loop/nnnnn.txt
Normal file
@ -0,0 +1,69 @@
|
||||
WaitMultipleWayland
|
||||
WaitMultipleFd
|
||||
WaitMultipleGlib
|
||||
WaitMultipleFd
|
||||
+ other hacks
|
||||
WaitMultipleX11
|
||||
WaitMultipleFd
|
||||
WaitMultipleFd
|
||||
win: cast to handle, queue handle
|
||||
bsd: queue kqueue source
|
||||
linux: queue poll poll
|
||||
WaitMultipleAsync
|
||||
all: WaitMultipleSemaphore
|
||||
WaitMultipleWin32
|
||||
win: switch to MsgWait...
|
||||
others: n/a
|
||||
WaitMultipleApple
|
||||
mac: hijack mainloop, add kqueue sources
|
||||
others: n/a
|
||||
WaitMultipleTimer
|
||||
bsd: queue kqueue source
|
||||
linux: timerfd_create
|
||||
win32: CreateTimer
|
||||
WaitMultipleSemaphore
|
||||
win32: CreateSemaphore
|
||||
linux: eventfd semaphore
|
||||
bsd:
|
||||
mutex (as in, au primitive mutex) lock non-blocking reads
|
||||
pipe
|
||||
WaitMultipleMutex
|
||||
win32: CreateMutex
|
||||
linux + bsd: WaitMultipleSemaphore
|
||||
WaitMultipleAIO
|
||||
win32: waitmultiple
|
||||
bsd/posix: select
|
||||
linux: switch over to io_submit, IOCB_CMD_PREAD for fds
|
||||
|
||||
|
||||
IPCSemaphore:
|
||||
linux: eventfd semaphore
|
||||
win32: CreateSemaphore
|
||||
bsd:
|
||||
shm spinlock -> Does this require a security note?
|
||||
I guess we could trust people in our user session
|
||||
Having a page one could write 1 across seems more exploitable than
|
||||
named pipes, semaphores, and mutexes, but it doesn't seem to reduce
|
||||
the required scope of attack, so it doesnt really matter
|
||||
protected pipe
|
||||
IPCMutex
|
||||
win32: CreateMutex
|
||||
linux + bsd: IPCSemaphore
|
||||
|
||||
IPCCV:
|
||||
all: ipcsemaphore
|
||||
|
||||
IPCServer
|
||||
win32: CreatePipe
|
||||
posix: pipe
|
||||
|
||||
|
||||
|
||||
class ILoopSourceEx : public ILoopSource
|
||||
{
|
||||
public:
|
||||
virtual void OnPresleep() = 0;
|
||||
virtual bool OnTrigger(AuUInt handle, bool atomicSignal) = 0;
|
||||
virtual void OnFinishSleep() = 0;
|
||||
virtual AuList<AuUInt> GetHandle() = 0;
|
||||
};
|
@ -117,10 +117,22 @@ namespace Aurora::Memory
|
||||
this->writePtr = this->base;
|
||||
}
|
||||
|
||||
ByteBuffer() : flagCircular(0), flagExpandable(0), flagReadError(0), flagWriteError(0)
|
||||
{
|
||||
this->base = {};
|
||||
this->length = {};
|
||||
this->allocSize = {};
|
||||
this->readPtr = {};
|
||||
this->writePtr = {};
|
||||
}
|
||||
|
||||
~ByteBuffer()
|
||||
{
|
||||
if (this->base)
|
||||
{
|
||||
Free(this->base);
|
||||
}
|
||||
}
|
||||
|
||||
inline void ResetPositions()
|
||||
{
|
||||
|
@ -1,3 +1,10 @@
|
||||
/***
|
||||
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||
|
||||
File: MemoryView.hpp
|
||||
Date: 2021-9-14
|
||||
Author: Reece
|
||||
***/
|
||||
#pragma once
|
||||
|
||||
namespace Aurora::Memory
|
||||
@ -15,12 +22,12 @@ namespace Aurora::Memory
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr MemoryView(Void_t start, Void_t end)
|
||||
constexpr MemoryView(T *start, T *end)
|
||||
{
|
||||
this->ptr = start;
|
||||
if constexpr (std::is_same_v<T, Void_t>)
|
||||
{
|
||||
this->length = reinterpret_cast<const AuUInt8*>(end) - reinterpret_cast<const AuUInt8*>(start);
|
||||
this->length = reinterpret_cast<const AuUInt8 *>(end) - reinterpret_cast<const AuUInt8 *>(start);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -29,12 +36,18 @@ namespace Aurora::Memory
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr MemoryView(Void_t start, AuUInt length)
|
||||
constexpr MemoryView(T *start, AuUInt length)
|
||||
{
|
||||
this->ptr = start;
|
||||
this->length = length;
|
||||
}
|
||||
|
||||
MemoryView()
|
||||
{
|
||||
this->ptr = nullptr;
|
||||
this->length = 0;
|
||||
}
|
||||
|
||||
AuUInt ToPointer()
|
||||
{
|
||||
return reinterpret_cast<AuUInt>(ptr);
|
||||
@ -52,21 +65,48 @@ namespace Aurora::Memory
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* Begin()
|
||||
T *Begin()
|
||||
{
|
||||
return reinterpret_cast<T *>(ptr);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* End()
|
||||
T *End()
|
||||
{
|
||||
return Begin<T>() + ToCount<T>();
|
||||
}
|
||||
|
||||
Void_t const ptr;
|
||||
AuUInt const length;
|
||||
Void_t /*const*/ ptr;
|
||||
AuUInt /*const*/ length;
|
||||
};
|
||||
|
||||
using MemoryViewRead = MemoryView<true>;
|
||||
using MemoryViewWrite = MemoryView<false>;
|
||||
|
||||
template<bool Readonly_b>
|
||||
struct MemoryViewStream : MemoryView<Readonly_b>
|
||||
{
|
||||
template<typename T>
|
||||
constexpr MemoryViewStream(const AuList<T> &list, AuUInt &length) : MemoryView<Readonly_b>(list), outVariable(length)
|
||||
{
|
||||
outVariable = 0;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr MemoryViewStream(T *start, T *end, AuUInt &length) : MemoryView<Readonly_b>(start, end), outVariable(length)
|
||||
{
|
||||
outVariable = 0;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr MemoryViewStream(T *start, AuUInt &length) : MemoryView<Readonly_b>(start, length), outVariable(length)
|
||||
{
|
||||
outVariable = 0;
|
||||
}
|
||||
|
||||
AuUInt &outVariable;
|
||||
};
|
||||
|
||||
using MemoryViewStreamRead = MemoryViewStream<true>;
|
||||
using MemoryViewStreamWrite = MemoryViewStream<false>;
|
||||
}
|
@ -123,10 +123,8 @@ namespace Aurora::Telemetry
|
||||
Aurora::Build::EABI abi;
|
||||
|
||||
Aurora::HWInfo::CpuInfo cpuInfo;
|
||||
|
||||
AuUInt16 ramMb;
|
||||
AuUInt16 remainingMb;
|
||||
AuUInt16 pageSize;
|
||||
Aurora::HWInfo::RamStat sysMem;
|
||||
Aurora::HWInfo::RamStat procMem;
|
||||
};
|
||||
|
||||
struct NewBlackBoxEntryReportApplication
|
||||
|
@ -660,6 +660,16 @@ namespace Aurora::Compression
|
||||
|
||||
AUKN_SYM bool Compress(const CompressionPipe &stream, const CompressionInfo &info)
|
||||
{
|
||||
if (!stream.inPipe)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
if (!stream.writePipe)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
switch (info.type)
|
||||
{
|
||||
case ECompresionType::eZSTD:
|
||||
@ -677,13 +687,25 @@ namespace Aurora::Compression
|
||||
}
|
||||
}
|
||||
|
||||
AUKN_SYM bool Decompress( const CompressionPipe &pipe, const DecompressInfo &meta2)
|
||||
AUKN_SYM bool Decompress(const CompressionPipe &pipe, const DecompressInfo &meta2)
|
||||
{
|
||||
DecompressInfo meta = meta2;
|
||||
|
||||
if (!meta.internalStreamSize)
|
||||
{
|
||||
meta.internalStreamSize = 1024 * 64 * 2;
|
||||
}
|
||||
|
||||
if (!pipe.inPipe)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
if (!pipe.writePipe)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
switch (meta.alg)
|
||||
{
|
||||
case ECompresionType::eZSTD:
|
||||
|
@ -13,23 +13,23 @@
|
||||
|
||||
namespace Aurora::Crypto::AES
|
||||
{
|
||||
AUKN_SYM AuUInt GetSafeCipherPadding(const void *plainText, AuUInt plainTextLength)
|
||||
AUKN_SYM AuUInt GetSafeCipherPadding(Memory::MemoryViewRead parameters)
|
||||
{
|
||||
auto tptr = reinterpret_cast<const unsigned char *>(plainText);
|
||||
auto tptr = reinterpret_cast<const unsigned char *>(parameters.ptr);
|
||||
|
||||
auto overhang = plainTextLength & (128 - 1);
|
||||
auto primaryLength = plainTextLength - overhang;
|
||||
auto overhang = parameters.length & (128 - 1);
|
||||
auto primaryLength = parameters.length - overhang;
|
||||
|
||||
if (overhang == 0)
|
||||
{
|
||||
auto lastbyte = tptr[primaryLength - 1];
|
||||
if (lastbyte <= 128)
|
||||
{
|
||||
return plainTextLength + 128;
|
||||
return parameters.length + 128;
|
||||
}
|
||||
else
|
||||
{
|
||||
return plainTextLength;
|
||||
return parameters.length;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -139,33 +139,72 @@ namespace Aurora::Crypto::AES
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
AUKN_SYM bool Encrypt(const void *plainText, AuUInt plainTextLength,
|
||||
const void *iv, void *outIv, AuUInt ivLength,
|
||||
const void *key, AuUInt keyLength,
|
||||
AUKN_SYM bool Encrypt(Memory::MemoryViewRead plainText,
|
||||
Memory::MemoryViewRead inIv,
|
||||
Memory::MemoryViewWrite outIv,
|
||||
Memory::MemoryViewRead inKey,
|
||||
AuList<AuUInt8> &out,
|
||||
bool safe)
|
||||
bool auCoolCodePadding)
|
||||
{
|
||||
symmetric_CBC cbc;
|
||||
|
||||
if (ivLength != 16)
|
||||
if (!plainText.length)
|
||||
{
|
||||
SysPushErrorCrypt("{}", ivLength);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((keyLength != 16) &&
|
||||
(keyLength != 24) &&
|
||||
(keyLength != 32))
|
||||
if (!plainText.ptr)
|
||||
{
|
||||
SysPushErrorCrypt("{}", keyLength);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!inIv.length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!inIv.ptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!inKey.length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!inKey.ptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (inIv.length != 16)
|
||||
{
|
||||
SysPushErrorCrypt("{}", inIv.length);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (outIv.length)
|
||||
{
|
||||
if (inIv.length != outIv.length)
|
||||
{
|
||||
SysPushErrorCrypt("{}", outIv.length);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ((inKey.length != 16) &&
|
||||
(inKey.length != 24) &&
|
||||
(inKey.length != 32))
|
||||
{
|
||||
SysPushErrorCrypt("{}", inKey.length);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto ret = cbc_start(::Crypto::gAesCipher,
|
||||
reinterpret_cast<const unsigned char *>(iv),
|
||||
reinterpret_cast<const unsigned char *>(key),
|
||||
keyLength,
|
||||
reinterpret_cast<const unsigned char *>(inIv.ptr),
|
||||
reinterpret_cast<const unsigned char *>(inKey.ptr),
|
||||
inKey.length,
|
||||
0,
|
||||
&cbc);
|
||||
if (ret != CRYPT_OK)
|
||||
@ -174,24 +213,24 @@ namespace Aurora::Crypto::AES
|
||||
return false;
|
||||
}
|
||||
|
||||
auto tptr = reinterpret_cast<const unsigned char *>(plainText);
|
||||
auto tptr = reinterpret_cast<const unsigned char *>(plainText.ptr);
|
||||
|
||||
if (safe)
|
||||
if (auCoolCodePadding)
|
||||
{
|
||||
if (!EncryptCoolCodePadding(plainText, plainTextLength, iv, outIv, ivLength, key, keyLength, out, cbc))
|
||||
if (!EncryptCoolCodePadding(tptr, plainText.length, inIv.ptr, outIv.ptr, inIv.length, inKey.ptr, inKey.length, out, cbc))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((plainTextLength & (16 - 1)) != 0)
|
||||
if ((plainText.length & (16 - 1)) != 0)
|
||||
{
|
||||
SysPushErrorArg("{}", keyLength);
|
||||
SysPushErrorArg("{}", plainText.length);
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = cbc_encrypt(tptr, out.data(), plainTextLength, &cbc);
|
||||
ret = cbc_encrypt(tptr, out.data(), plainText.length, &cbc);
|
||||
if (ret != CRYPT_OK)
|
||||
{
|
||||
SysPushErrorCrypt("{}", ret);
|
||||
@ -199,10 +238,10 @@ namespace Aurora::Crypto::AES
|
||||
}
|
||||
}
|
||||
|
||||
if (outIv)
|
||||
if (outIv.ptr)
|
||||
{
|
||||
unsigned long ivLength = 16;
|
||||
ret = cbc_getiv(reinterpret_cast<unsigned char *>(outIv), &ivLength, &cbc);
|
||||
ret = cbc_getiv(reinterpret_cast<unsigned char *>(outIv.ptr), &ivLength, &cbc);
|
||||
|
||||
if (ret != CRYPT_OK)
|
||||
{
|
||||
@ -215,9 +254,10 @@ namespace Aurora::Crypto::AES
|
||||
}
|
||||
|
||||
|
||||
AUKN_SYM bool Decrypt(const void *cipherText, AuUInt cipherTextLength,
|
||||
const void *iv, void *outIv, AuUInt ivLength,
|
||||
const void *key, AuUInt keyLength,
|
||||
AUKN_SYM bool Decrypt(Memory::MemoryViewRead cipherText,
|
||||
Memory::MemoryViewRead inIv,
|
||||
Memory::MemoryViewWrite outIv,
|
||||
Memory::MemoryViewRead inKey,
|
||||
AuList<AuUInt8> &plainText,
|
||||
bool safe)
|
||||
{
|
||||
@ -225,24 +265,62 @@ namespace Aurora::Crypto::AES
|
||||
|
||||
symmetric_CBC cbc;
|
||||
|
||||
if (ivLength != 16)
|
||||
if (!cipherText.length)
|
||||
{
|
||||
SysPushErrorArg("{}", ivLength);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((keyLength != 16) &&
|
||||
(keyLength != 24) &&
|
||||
(keyLength != 32))
|
||||
if (!cipherText.ptr)
|
||||
{
|
||||
SysPushErrorArg("{}", keyLength);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!inIv.length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!inIv.ptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!inKey.length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!inKey.ptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (inIv.length != 16)
|
||||
{
|
||||
SysPushErrorCrypt("{}", inIv.length);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (outIv.length)
|
||||
{
|
||||
if (inIv.length != outIv.length)
|
||||
{
|
||||
SysPushErrorCrypt("{}", outIv.length);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ((inKey.length != 16) &&
|
||||
(inKey.length != 24) &&
|
||||
(inKey.length != 32))
|
||||
{
|
||||
SysPushErrorCrypt("{}", inKey.length);
|
||||
return false;
|
||||
}
|
||||
auto ret = cbc_start(::Crypto::gAesCipher,
|
||||
reinterpret_cast<const unsigned char *>(iv),
|
||||
reinterpret_cast<const unsigned char *>(key),
|
||||
keyLength,
|
||||
reinterpret_cast<const unsigned char *>(inIv.ptr),
|
||||
reinterpret_cast<const unsigned char *>(inKey.ptr),
|
||||
inKey.length,
|
||||
0,
|
||||
&cbc);
|
||||
if (ret != CRYPT_OK)
|
||||
@ -251,15 +329,15 @@ namespace Aurora::Crypto::AES
|
||||
return false;
|
||||
}
|
||||
|
||||
auto tptr = reinterpret_cast<const unsigned char *>(cipherText);
|
||||
auto tptr = reinterpret_cast<const unsigned char *>(cipherText.ptr);
|
||||
|
||||
if (!AuTryResize(plainText, cipherTextLength))
|
||||
if (!AuTryResize(plainText, cipherText.length))
|
||||
{
|
||||
SysPushErrorMem();
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = cbc_decrypt(tptr, plainText.data(), cipherTextLength, &cbc);
|
||||
ret = cbc_decrypt(tptr, plainText.data(), cipherText.length, &cbc);
|
||||
if (ret != CRYPT_OK)
|
||||
{
|
||||
SysPushErrorCrypt("{}", ret);
|
||||
@ -268,17 +346,17 @@ namespace Aurora::Crypto::AES
|
||||
|
||||
if (safe)
|
||||
{
|
||||
auto magic = plainText[cipherTextLength - 1];
|
||||
auto magic = plainText[cipherText.length - 1];
|
||||
if (magic <= 128)
|
||||
{
|
||||
plainText.resize(cipherTextLength - magic);
|
||||
plainText.resize(cipherText.length - magic);
|
||||
}
|
||||
}
|
||||
|
||||
if (outIv)
|
||||
if (outIv.ptr)
|
||||
{
|
||||
unsigned long ivLength = 16;
|
||||
ret = cbc_getiv(reinterpret_cast<unsigned char *>(outIv), &ivLength, &cbc);
|
||||
ret = cbc_getiv(reinterpret_cast<unsigned char *>(outIv.ptr), &ivLength, &cbc);
|
||||
if (ret != CRYPT_OK)
|
||||
{
|
||||
|
||||
|
@ -23,8 +23,9 @@ namespace Aurora::Crypto::RSA
|
||||
rsa_free(&key_);
|
||||
}
|
||||
|
||||
bool PrivateRSA::Sign(const void *buffer, AuUInt length,
|
||||
EHashType method, EPaddingType type,
|
||||
bool PrivateRSA::Sign(Memory::MemoryViewRead payload,
|
||||
EHashType method,
|
||||
EPaddingType type,
|
||||
AuList<AuUInt8> &out)
|
||||
{
|
||||
prng_state yarrow_prng;
|
||||
@ -60,7 +61,7 @@ namespace Aurora::Crypto::RSA
|
||||
|
||||
unsigned long hashSize = hashVec.size();
|
||||
auto ret = hash_memory(hash,
|
||||
reinterpret_cast<const unsigned char *>(buffer), length,
|
||||
reinterpret_cast<const unsigned char *>(payload.ptr), payload.length,
|
||||
reinterpret_cast<unsigned char *>(hashVec.data()), &hashSize);
|
||||
if (ret != CRYPT_OK)
|
||||
{
|
||||
@ -87,14 +88,9 @@ namespace Aurora::Crypto::RSA
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrivateRSA::Sign(const AuList<AuUInt8> &in,
|
||||
EHashType method, EPaddingType type,
|
||||
bool PrivateRSA::Decrypt(Memory::MemoryViewRead payload,
|
||||
EPaddingType type,
|
||||
AuList<AuUInt8> &out)
|
||||
{
|
||||
return Sign(in.data(), in.size(), method, type, out);
|
||||
}
|
||||
|
||||
bool PrivateRSA::Decrypt(const void *buffer, AuUInt length, EPaddingType type, AuList<AuUInt8> &out)
|
||||
{
|
||||
int padding = PaddingToType(type);
|
||||
if (padding == 0xFF)
|
||||
@ -110,7 +106,7 @@ namespace Aurora::Crypto::RSA
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!AuTryResize(out, length))
|
||||
if (!AuTryResize(out, payload.length))
|
||||
{
|
||||
SysPushErrorMem();
|
||||
return false;
|
||||
@ -119,7 +115,7 @@ namespace Aurora::Crypto::RSA
|
||||
unsigned long len = out.size();
|
||||
|
||||
int stat = 0;
|
||||
auto ret = rsa_decrypt_key_ex(reinterpret_cast<const unsigned char *>(buffer), length,
|
||||
auto ret = rsa_decrypt_key_ex(reinterpret_cast<const unsigned char *>(payload.ptr), payload.length,
|
||||
out.data(), &len,
|
||||
NULL, 0,
|
||||
0, // hash? excuse me?
|
||||
@ -136,14 +132,9 @@ namespace Aurora::Crypto::RSA
|
||||
return stat == 1;
|
||||
}
|
||||
|
||||
bool PrivateRSA::Decrypt(const AuList<AuUInt8> &in, EPaddingType type, AuList<AuUInt8> &out)
|
||||
{
|
||||
return Decrypt(in.data(), in.size(), type, out);
|
||||
}
|
||||
|
||||
AuSPtr<IRSAPublic> PrivateRSA::ToPublic()
|
||||
{
|
||||
return AuMakeShared<PublicRSA>(key_);
|
||||
return AuMakeShared<PublicRSA>(key_, false);
|
||||
}
|
||||
|
||||
bool PrivateRSA::ToKey(const RSAMeta &meta, AuList<AuUInt8> &out)
|
||||
|
@ -15,19 +15,15 @@ namespace Aurora::Crypto::RSA
|
||||
PrivateRSA(rsa_key &key);
|
||||
~PrivateRSA();
|
||||
|
||||
bool Sign(const void *buffer, AuUInt length,
|
||||
EHashType method, EPaddingType type,
|
||||
bool Sign(Memory::MemoryViewRead payload,
|
||||
EHashType method,
|
||||
EPaddingType type,
|
||||
AuList<AuUInt8> &out) override;
|
||||
|
||||
|
||||
bool Sign(const AuList<AuUInt8> &in,
|
||||
EHashType method, EPaddingType type,
|
||||
bool Decrypt(Memory::MemoryViewRead payload,
|
||||
EPaddingType type,
|
||||
AuList<AuUInt8> &out) override;
|
||||
|
||||
bool Decrypt(const void *buffer, AuUInt length, EPaddingType type, AuList<AuUInt8> &out) override;
|
||||
|
||||
bool Decrypt(const AuList<AuUInt8> &in, EPaddingType type, AuList<AuUInt8> &out) override;
|
||||
|
||||
AuSPtr<IRSAPublic> ToPublic() override;
|
||||
|
||||
bool ToKey(const RSAMeta &meta, AuList<AuUInt8> &out) override;
|
||||
|
@ -12,18 +12,21 @@
|
||||
|
||||
namespace Aurora::Crypto::RSA
|
||||
{
|
||||
PublicRSA::PublicRSA(rsa_key &key) : key_(key)
|
||||
PublicRSA::PublicRSA(rsa_key &key, bool owned) : key_(key), owned_(owned)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PublicRSA::~PublicRSA()
|
||||
{
|
||||
|
||||
if (owned_)
|
||||
{
|
||||
rsa_free(&key_);
|
||||
}
|
||||
}
|
||||
|
||||
bool PublicRSA::Verify(const void *buffer, AuUInt length,
|
||||
const void *sigBuffer, AuUInt sigLength,
|
||||
bool PublicRSA::Verify(Memory::MemoryViewRead payload,
|
||||
Memory::MemoryViewRead signature,
|
||||
EHashType method,
|
||||
EPaddingType type)
|
||||
{
|
||||
@ -50,7 +53,7 @@ namespace Aurora::Crypto::RSA
|
||||
|
||||
unsigned long hashSize = hashVec.size();
|
||||
auto ret = hash_memory(hash,
|
||||
reinterpret_cast<const unsigned char *>(buffer), length,
|
||||
reinterpret_cast<const unsigned char *>(payload.ptr), payload.length,
|
||||
reinterpret_cast<unsigned char *>(hashVec.data()), &hashSize);
|
||||
if (ret != CRYPT_OK)
|
||||
{
|
||||
@ -60,7 +63,7 @@ namespace Aurora::Crypto::RSA
|
||||
|
||||
|
||||
int ok = 0;
|
||||
ret = rsa_verify_hash_ex(reinterpret_cast<const unsigned char *>(sigBuffer), sigLength,
|
||||
ret = rsa_verify_hash_ex(reinterpret_cast<const unsigned char *>(signature.ptr), signature.length,
|
||||
reinterpret_cast<const unsigned char *>(hashVec.data()), hashSize,
|
||||
padding, hash, 0, &ok, &key_);
|
||||
if (ret != CRYPT_OK)
|
||||
@ -72,13 +75,9 @@ namespace Aurora::Crypto::RSA
|
||||
return ok == 1;
|
||||
}
|
||||
|
||||
bool PublicRSA::Verify(const AuList<AuUInt8> &buffer, const AuList<AuUInt8> &sig,
|
||||
EHashType method, EPaddingType type)
|
||||
{
|
||||
return Verify(buffer.data(), buffer.size(), sig.data(), sig.size(), method, type);
|
||||
}
|
||||
|
||||
bool PublicRSA::Encrypt(const void *buffer, AuUInt length, EPaddingType type, AuList<AuUInt8> &out)
|
||||
bool PublicRSA::Encrypt(Memory::MemoryViewRead plainText,
|
||||
EPaddingType type,
|
||||
AuList<AuUInt8> &out)
|
||||
{
|
||||
prng_state yarrow_prng;
|
||||
|
||||
@ -96,7 +95,7 @@ namespace Aurora::Crypto::RSA
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!AuTryResize(out, length + 1024))
|
||||
if (!AuTryResize(out, plainText.length + 1024))
|
||||
{
|
||||
SysPushErrorMem();
|
||||
return false;
|
||||
@ -104,7 +103,8 @@ namespace Aurora::Crypto::RSA
|
||||
|
||||
unsigned long len = out.size();
|
||||
|
||||
auto ret = rsa_encrypt_key_ex(reinterpret_cast<const unsigned char *>(buffer), length,
|
||||
auto ret = rsa_encrypt_key_ex(reinterpret_cast<const unsigned char *>(plainText.ptr),
|
||||
plainText.length,
|
||||
out.data(), &len,
|
||||
NULL, 0,
|
||||
&yarrow_prng, prng_idx,
|
||||
@ -121,11 +121,6 @@ namespace Aurora::Crypto::RSA
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PublicRSA::Encrypt(const AuList<AuUInt8> &in, EPaddingType type, AuList<AuUInt8> &out)
|
||||
{
|
||||
return Encrypt(in.data(), in.size(), type, out);
|
||||
}
|
||||
|
||||
bool PublicRSA::ToKey(ERSAKeyType type, AuList<AuUInt8> &out)
|
||||
{
|
||||
return ExportRSAKey(key_, EKeyType::eKeyPublic, type, out);
|
||||
@ -140,7 +135,7 @@ namespace Aurora::Crypto::RSA
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto ret = _new PublicRSA(in);
|
||||
auto ret = _new PublicRSA(in, true);
|
||||
if (!ret)
|
||||
{
|
||||
rsa_free(&in);
|
||||
|
@ -13,23 +13,22 @@ namespace Aurora::Crypto::RSA
|
||||
class PublicRSA : public IRSAPublic
|
||||
{
|
||||
public:
|
||||
PublicRSA(rsa_key &key);
|
||||
PublicRSA(rsa_key &key, bool owned = true);
|
||||
~PublicRSA();
|
||||
|
||||
bool Verify(const void *buffer, AuUInt length,
|
||||
const void *sigBuffer, AuUInt sigLength,
|
||||
bool Verify(Memory::MemoryViewRead payload,
|
||||
Memory::MemoryViewRead signature,
|
||||
EHashType method,
|
||||
EPaddingType type) override;
|
||||
|
||||
bool Verify(const AuList<AuUInt8> &buffer, const AuList<AuUInt8> &sig,
|
||||
EHashType method, EPaddingType type) override;
|
||||
|
||||
bool Encrypt(const void *buffer, AuUInt length, EPaddingType type, AuList<AuUInt8> &out) override;
|
||||
bool Encrypt(const AuList<AuUInt8> &in, EPaddingType type, AuList<AuUInt8> &out) override;
|
||||
bool Encrypt(Memory::MemoryViewRead plainText,
|
||||
EPaddingType type,
|
||||
AuList<AuUInt8> &out) override;
|
||||
|
||||
bool ToKey(ERSAKeyType type, AuList<AuUInt8> &out) override;
|
||||
|
||||
private:
|
||||
rsa_key key_;
|
||||
bool owned_;
|
||||
};
|
||||
}
|
@ -24,12 +24,10 @@ namespace Aurora::Debug
|
||||
AuUInt32 GetCErrorFence();
|
||||
AuOptional<int> TryGetOrFetchCError();
|
||||
|
||||
AuUInt32 GetStackTraceFence();
|
||||
AuOptional<int> TryGetOrFetchStackTrace();
|
||||
|
||||
void ReportStackTrace(const StackTrace &trace);
|
||||
|
||||
|
||||
|
||||
AuOptional<int> TryFetchStackTrace();
|
||||
AuOptional<OSError_t> TryFetchOSError();
|
||||
AuOptional<int> TryFetchCError();
|
||||
|
||||
|
@ -23,7 +23,8 @@ namespace Aurora::Debug
|
||||
{
|
||||
::DebugBreak();
|
||||
}
|
||||
#elif defined(AURORA_COMPILER_MSVC)
|
||||
#elif defined(DEBUG)
|
||||
#if defined(AURORA_COMPILER_MSVC)
|
||||
__debugbreak();
|
||||
#elif defined(__has_builtin) && __has_builtin(__builtin_debugtrap))
|
||||
__builtin_debugtrap();
|
||||
@ -32,6 +33,7 @@ namespace Aurora::Debug
|
||||
// I refuse to chuck inline assembly here, not here, not in this project, not for freetards.
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
AUKN_SYM void Panic()
|
||||
|
@ -195,7 +195,7 @@ namespace Aurora::HWInfo
|
||||
|
||||
bool CpuId::HLE()
|
||||
{
|
||||
return AuTestBit(isIntel && f_7_EBX, 4);
|
||||
return isIntel && AuTestBit(f_7_EBX, 4);
|
||||
}
|
||||
|
||||
bool CpuId::AVX2()
|
||||
@ -220,7 +220,7 @@ namespace Aurora::HWInfo
|
||||
|
||||
bool CpuId::RTM()
|
||||
{
|
||||
return AuTestBit(isIntel && f_7_EBX, 11);
|
||||
return isIntel && AuTestBit(f_7_EBX, 11);
|
||||
}
|
||||
|
||||
bool CpuId::AVX512F()
|
||||
@ -270,52 +270,52 @@ namespace Aurora::HWInfo
|
||||
|
||||
bool CpuId::LZCNT()
|
||||
{
|
||||
return AuTestBit(isIntel && f_81_ECX, 5);
|
||||
return isIntel && AuTestBit(f_81_ECX, 5);
|
||||
}
|
||||
|
||||
bool CpuId::ABM()
|
||||
{
|
||||
return AuTestBit(isAMD && f_81_ECX, 5);
|
||||
return isAMD && AuTestBit(f_81_ECX, 5);
|
||||
}
|
||||
|
||||
bool CpuId::SSE4a()
|
||||
{
|
||||
return AuTestBit(isAMD && f_81_ECX, 6);
|
||||
return isAMD && AuTestBit(f_81_ECX, 6);
|
||||
}
|
||||
|
||||
bool CpuId::XOP()
|
||||
{
|
||||
return AuTestBit(isAMD && f_81_ECX, 11);
|
||||
return isAMD && AuTestBit(f_81_ECX, 11);
|
||||
}
|
||||
|
||||
bool CpuId::TBM()
|
||||
{
|
||||
return AuTestBit(isAMD && f_81_ECX, 21);
|
||||
return isAMD && AuTestBit(f_81_ECX, 21);
|
||||
}
|
||||
|
||||
bool CpuId::SYSCALL()
|
||||
{
|
||||
return AuTestBit(isIntel && f_81_EDX, 11);
|
||||
return isIntel && AuTestBit(f_81_EDX, 11);
|
||||
}
|
||||
|
||||
bool CpuId::MMXEXT()
|
||||
{
|
||||
return AuTestBit(isAMD && f_81_EDX, 22);
|
||||
return isAMD && AuTestBit(f_81_EDX, 22);
|
||||
}
|
||||
|
||||
bool CpuId::RDTSCP()
|
||||
{
|
||||
return AuTestBit(isIntel && f_81_EDX, 27);
|
||||
return isIntel && AuTestBit(f_81_EDX, 27);
|
||||
}
|
||||
|
||||
bool CpuId::_3DNOWEXT()
|
||||
{
|
||||
return AuTestBit(isAMD && f_81_EDX, 30);
|
||||
return isAMD && AuTestBit(f_81_EDX, 30);
|
||||
}
|
||||
|
||||
bool CpuId::_3DNOW()
|
||||
{
|
||||
return AuTestBit(isAMD && f_81_EDX, 31);
|
||||
return isAMD && AuTestBit(f_81_EDX, 31);
|
||||
}
|
||||
|
||||
AUKN_SYM const CpuInfo &GetCPUInfo()
|
||||
|
@ -301,10 +301,12 @@ namespace Aurora::IO::FS
|
||||
|
||||
auto ret = WaitForMultipleObjects(handles.size(), handles.data(), false, timeout ? timeout : INFINITE);
|
||||
|
||||
#if 0
|
||||
for (const auto &file : files)
|
||||
{
|
||||
std::static_pointer_cast<NtAsyncFileTransaction>(file)->Complete();
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret != WAIT_TIMEOUT && ret != WAIT_FAILED;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ namespace Aurora::IO::FS
|
||||
return IterateDirEntriesSTL(string, false, dirs);
|
||||
}
|
||||
|
||||
AUKN_SYM bool WriteFile(const AuString &path, const void *data, size_t length)
|
||||
AUKN_SYM bool WriteFile(const AuString &path, const void *data, AuUInt length)
|
||||
{
|
||||
auto file = fopen(NormalizePathRet(path).c_str(), "wb");
|
||||
if (!file)
|
||||
|
@ -44,7 +44,7 @@ namespace Aurora::IO::FS
|
||||
return false;
|
||||
}
|
||||
|
||||
AUKN_SYM bool WriteFile(const AuString &path, const void *data, size_t length)
|
||||
AUKN_SYM bool WriteFile(const AuString &path, const void *data, AuUInt length)
|
||||
{
|
||||
bool status;
|
||||
size_t offset;
|
||||
|
@ -100,28 +100,28 @@ namespace Aurora::IO::FS
|
||||
return true;
|
||||
}
|
||||
|
||||
AuUInt64 Read(void *in, AuUInt64 length) override
|
||||
bool Read(Memory::MemoryViewStreamWrite parameters) override
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!stream_.is_open())
|
||||
{
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
stream_.read(reinterpret_cast<char *>(in), length);
|
||||
length = stream_.gcount();
|
||||
offset_ += length;
|
||||
return length;
|
||||
stream_.read(reinterpret_cast<char *>(parameters.ptr), parameters.length);
|
||||
parameters.outVariable = stream_.gcount();
|
||||
offset_ += parameters.outVariable;
|
||||
return true;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
AuUInt64 Write(const void *out, AuUInt64 length) override
|
||||
bool Write(Memory::MemoryViewStreamRead parameters) override
|
||||
{
|
||||
SysPanic("Invalid operation");
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
@ -134,29 +134,30 @@ namespace Aurora::IO::FS
|
||||
offset_ = stream_.tellp();
|
||||
}
|
||||
|
||||
AuUInt64 Read(void *in, AuUInt64 length) override
|
||||
bool Read(Memory::MemoryViewStreamWrite parameters) override
|
||||
{
|
||||
SysPanic("Invalid operation");
|
||||
return false;
|
||||
}
|
||||
|
||||
AuUInt64 Write(const void *out, AuUInt64 length) override
|
||||
bool Write(Memory::MemoryViewStreamRead parameters) override
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!stream_.is_open())
|
||||
{
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
auto start = stream_.tellp();
|
||||
stream_.write(reinterpret_cast<const char *>(out), length);
|
||||
length = stream_.tellp() - start;
|
||||
offset_ += length;
|
||||
stream_.write(reinterpret_cast<const char *>(parameters.ptr), parameters.length);
|
||||
parameters.outVariable = stream_.tellp() - start;
|
||||
offset_ += parameters.outVariable;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
return length;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetOffset(AuUInt64 offset) override
|
||||
|
@ -89,14 +89,15 @@ namespace Aurora::IO::FS
|
||||
return length.QuadPart;
|
||||
}
|
||||
|
||||
AuUInt64 WinFileStream::Read(void *in, AuUInt64 length)
|
||||
bool WinFileStream::Read(Memory::MemoryViewStreamWrite parameters)
|
||||
{
|
||||
if (handle_ == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
SysPushErrorUninitialized();
|
||||
return 0;
|
||||
return {};
|
||||
}
|
||||
|
||||
auto length = parameters.length;
|
||||
AuUInt64 offset {0};
|
||||
while (length)
|
||||
{
|
||||
@ -104,11 +105,11 @@ namespace Aurora::IO::FS
|
||||
|
||||
int blockSize = std::min(kFileCopyBlock, length);
|
||||
|
||||
if (!::ReadFile(handle_, &reinterpret_cast<char *>(in)[offset], blockSize, &read, NULL))
|
||||
if (!::ReadFile(handle_, &reinterpret_cast<char *>(parameters.ptr)[offset], blockSize, &read, NULL))
|
||||
{
|
||||
LogWarn("ReadFile IO Error: 0x%x, {}", GetLastError(), path_);
|
||||
SysPushErrorIO();
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (read == 0)
|
||||
@ -120,10 +121,16 @@ namespace Aurora::IO::FS
|
||||
length -= read;
|
||||
}
|
||||
|
||||
return offset;
|
||||
if (!offset)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
AuUInt64 WinFileStream::Write(const void *out, AuUInt64 length)
|
||||
parameters.outVariable = offset;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WinFileStream::Write(Memory::MemoryViewStreamRead parameters)
|
||||
{
|
||||
if (handle_ == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
@ -131,31 +138,39 @@ namespace Aurora::IO::FS
|
||||
return 0;
|
||||
}
|
||||
|
||||
AuUInt64 offset {0};
|
||||
auto length = parameters.length;
|
||||
AuUInt offset {0};
|
||||
while (length)
|
||||
{
|
||||
DWORD written;
|
||||
|
||||
int blockSize = std::min(kFileCopyBlock, length);
|
||||
|
||||
if (!::WriteFile(handle_, &reinterpret_cast<const char *>(out)[offset], blockSize, &written, NULL))
|
||||
if (!::WriteFile(handle_, &reinterpret_cast<const char *>(parameters.ptr)[offset], blockSize, &written, NULL))
|
||||
{
|
||||
LogWarn("WriteFileEx IO Error: 0x%x, {}", GetLastError(), path_);
|
||||
SysPushErrorIO();
|
||||
return offset;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (written != blockSize)
|
||||
{
|
||||
SysPushErrorIO();
|
||||
return offset;
|
||||
parameters.outVariable = offset;
|
||||
return true;
|
||||
}
|
||||
|
||||
offset += written;
|
||||
length -= written;
|
||||
}
|
||||
|
||||
return offset;
|
||||
if (!offset)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
parameters.outVariable = offset;
|
||||
return true;
|
||||
}
|
||||
|
||||
void WinFileStream::Close()
|
||||
|
@ -21,8 +21,8 @@ namespace Aurora::IO::FS
|
||||
AuUInt64 GetOffset() override;
|
||||
bool SetOffset(AuUInt64 offset) override;
|
||||
AuUInt64 GetLength() override;
|
||||
AuUInt64 Read(void *in, AuUInt64 length) override;
|
||||
AuUInt64 Write(const void *out, AuUInt64 length) override;
|
||||
bool Read(Memory::MemoryViewStreamWrite parameters) override;
|
||||
bool Write(Memory::MemoryViewStreamRead parameters) override;
|
||||
void Close() override;
|
||||
void Flush() override;
|
||||
|
||||
|
@ -161,7 +161,7 @@ namespace Aurora::IO::FS
|
||||
return PosixGetLength(handle_);
|
||||
}
|
||||
|
||||
AuUInt64 PosixFileStream::Read(void *in, AuUInt64 length)
|
||||
bool PosixFileStream::Read(Memory::MemoryViewStreamWrite parameters)
|
||||
{
|
||||
if (handle_ == -1)
|
||||
{
|
||||
@ -169,14 +169,15 @@ namespace Aurora::IO::FS
|
||||
return 0;
|
||||
}
|
||||
|
||||
AuUInt64 offset {0};
|
||||
auto length = parameters.length;
|
||||
AuUInt offset {0};
|
||||
while (length)
|
||||
{
|
||||
AuUInt32 read;
|
||||
|
||||
int blockSize = std::min(kFileCopyBlock, length);
|
||||
|
||||
if (!PosixRead(handle_, &reinterpret_cast<char *>(in)[offset], blockSize, &read))
|
||||
if (!PosixRead(handle_, &reinterpret_cast<char *>(parameters.ptr)[offset], blockSize, &read))
|
||||
{
|
||||
SysPushErrorNested("File Error: {}", path);
|
||||
break;
|
||||
@ -191,10 +192,16 @@ namespace Aurora::IO::FS
|
||||
length -= read;
|
||||
}
|
||||
|
||||
return offset;
|
||||
if (!offset)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
AuUInt64 PosixFileStream::Write(const void *out, AuUInt64 length)
|
||||
parameters.outVariable = offset;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PosixFileStream::Write(Memory::MemoryViewStreamRead parameters)
|
||||
{
|
||||
if (handle_ == -1)
|
||||
{
|
||||
@ -202,31 +209,38 @@ namespace Aurora::IO::FS
|
||||
return 0;
|
||||
}
|
||||
|
||||
AuUInt64 offset {0};
|
||||
auto length = parameters.length;
|
||||
AuUInt offset {0};
|
||||
while (length)
|
||||
{
|
||||
AuUInt32 written;
|
||||
|
||||
int blockSize = std::min(kFileCopyBlock, length);
|
||||
|
||||
if (!PosixWrite(handle_, &reinterpret_cast<const char *>(out)[offset], blockSize, &written))
|
||||
if (!PosixWrite(handle_, &reinterpret_cast<const char *>(parameters.ptr)[offset], blockSize, &written))
|
||||
{
|
||||
SysPushErrorNested("File Error: {}", path);
|
||||
return offset;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (written != blockSize)
|
||||
{
|
||||
SysPushErrorIO();
|
||||
SysPushErrorNested("File Error: {}", path);
|
||||
return offset;
|
||||
break;
|
||||
}
|
||||
|
||||
offset += written;
|
||||
length -= written;
|
||||
}
|
||||
|
||||
return offset;
|
||||
if (!offset)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
parameters.outVariable = offset;
|
||||
return true;
|
||||
}
|
||||
|
||||
void PosixFileStream::Close()
|
||||
|
@ -36,6 +36,16 @@ namespace Aurora::Telemetry
|
||||
|
||||
}
|
||||
|
||||
void ReportSysInfo()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Init()
|
||||
{
|
||||
ReportSysInfo();
|
||||
}
|
||||
|
||||
AUKN_SYM void Mayday()
|
||||
{
|
||||
|
||||
|
@ -13,5 +13,7 @@ namespace Aurora::Telemetry
|
||||
void InsertMsgError(const Debug::LastError &error);
|
||||
void InsertCError(AuSInt cError);
|
||||
void InsertManualFence(AuUInt32 fence);
|
||||
void ReportSysInfo();
|
||||
void Report(Telemetry::NewBlockboxEntry &entry);
|
||||
void Init();
|
||||
}
|
Loading…
Reference in New Issue
Block a user