Reformat RSA
This commit is contained in:
parent
8233825353
commit
29e5593308
@ -60,8 +60,8 @@ namespace Aurora::Crypto::RSA
|
|||||||
|
|
||||||
unsigned long hashSize = hashVec.size();
|
unsigned long hashSize = hashVec.size();
|
||||||
auto ret = hash_memory(hash,
|
auto ret = hash_memory(hash,
|
||||||
reinterpret_cast<const unsigned char *>(buffer), length,
|
reinterpret_cast<const unsigned char *>(buffer), length,
|
||||||
reinterpret_cast<unsigned char *>(hashVec.data()), &hashSize);
|
reinterpret_cast<unsigned char *>(hashVec.data()), &hashSize);
|
||||||
if (ret != CRYPT_OK)
|
if (ret != CRYPT_OK)
|
||||||
{
|
{
|
||||||
SysPushErrorCrypt("{}", ret);
|
SysPushErrorCrypt("{}", ret);
|
||||||
@ -70,13 +70,13 @@ namespace Aurora::Crypto::RSA
|
|||||||
|
|
||||||
unsigned long len = out.size();
|
unsigned long len = out.size();
|
||||||
ret = rsa_sign_hash_ex(reinterpret_cast<const unsigned char *>(hashVec.data()), hashSize,
|
ret = rsa_sign_hash_ex(reinterpret_cast<const unsigned char *>(hashVec.data()), hashSize,
|
||||||
out.data(), &len,
|
out.data(), &len,
|
||||||
padding,
|
padding,
|
||||||
&yarrow_prng,
|
&yarrow_prng,
|
||||||
::Crypto::gPrngYarrow,
|
::Crypto::gPrngYarrow,
|
||||||
hash,
|
hash,
|
||||||
salt,
|
salt,
|
||||||
&key_);
|
&key_);
|
||||||
if (ret != CRYPT_OK)
|
if (ret != CRYPT_OK)
|
||||||
{
|
{
|
||||||
SysPushErrorCrypt("{}", ret);
|
SysPushErrorCrypt("{}", ret);
|
||||||
@ -86,10 +86,10 @@ namespace Aurora::Crypto::RSA
|
|||||||
out.resize(len);
|
out.resize(len);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PrivateRSA::Sign(const AuList<AuUInt8> &in,
|
bool PrivateRSA::Sign(const AuList<AuUInt8> &in,
|
||||||
EHashType method, EPaddingType type,
|
EHashType method, EPaddingType type,
|
||||||
AuList<AuUInt8> &out)
|
AuList<AuUInt8> &out)
|
||||||
{
|
{
|
||||||
return Sign(in.data(), in.size(), method, type, out);
|
return Sign(in.data(), in.size(), method, type, out);
|
||||||
}
|
}
|
||||||
@ -140,7 +140,7 @@ namespace Aurora::Crypto::RSA
|
|||||||
{
|
{
|
||||||
return Decrypt(in.data(), in.size(), type, out);
|
return Decrypt(in.data(), in.size(), type, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
AuSPtr<IRSAPublic> PrivateRSA::ToPublic()
|
AuSPtr<IRSAPublic> PrivateRSA::ToPublic()
|
||||||
{
|
{
|
||||||
return std::make_shared<PublicRSA>(key_);
|
return std::make_shared<PublicRSA>(key_);
|
||||||
|
@ -50,8 +50,8 @@ namespace Aurora::Crypto::RSA
|
|||||||
|
|
||||||
unsigned long hashSize = hashVec.size();
|
unsigned long hashSize = hashVec.size();
|
||||||
auto ret = hash_memory(hash,
|
auto ret = hash_memory(hash,
|
||||||
reinterpret_cast<const unsigned char *>(buffer), length,
|
reinterpret_cast<const unsigned char *>(buffer), length,
|
||||||
reinterpret_cast<unsigned char *>(hashVec.data()), &hashSize);
|
reinterpret_cast<unsigned char *>(hashVec.data()), &hashSize);
|
||||||
if (ret != CRYPT_OK)
|
if (ret != CRYPT_OK)
|
||||||
{
|
{
|
||||||
SysPushErrorCrypt("{}", ret);
|
SysPushErrorCrypt("{}", ret);
|
||||||
@ -61,8 +61,8 @@ namespace Aurora::Crypto::RSA
|
|||||||
|
|
||||||
int ok = 0;
|
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 *>(sigBuffer), sigLength,
|
||||||
reinterpret_cast<const unsigned char *>(hashVec.data()), hashSize,
|
reinterpret_cast<const unsigned char *>(hashVec.data()), hashSize,
|
||||||
padding, hash, 0, &ok, &key_);
|
padding, hash, 0, &ok, &key_);
|
||||||
if (ret != CRYPT_OK)
|
if (ret != CRYPT_OK)
|
||||||
{
|
{
|
||||||
SysPushErrorCrypt("{}", ret);
|
SysPushErrorCrypt("{}", ret);
|
||||||
@ -105,12 +105,12 @@ namespace Aurora::Crypto::RSA
|
|||||||
unsigned long len = out.size();
|
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 *>(buffer), length,
|
||||||
out.data(), &len,
|
out.data(), &len,
|
||||||
NULL, 0,
|
NULL, 0,
|
||||||
&yarrow_prng, prng_idx,
|
&yarrow_prng, prng_idx,
|
||||||
0,
|
0,
|
||||||
padding,
|
padding,
|
||||||
&key_);
|
&key_);
|
||||||
if (ret != CRYPT_OK)
|
if (ret != CRYPT_OK)
|
||||||
{
|
{
|
||||||
SysPushErrorCrypt("{}", ret);
|
SysPushErrorCrypt("{}", ret);
|
||||||
|
@ -18,8 +18,7 @@ namespace Aurora::Memory
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InternalHeap() : base_(nullptr), mutex_(nullptr), heap_(nullptr), _count(0)
|
InternalHeap() : base_(nullptr), mutex_(nullptr), heap_(nullptr), _count(0)
|
||||||
{
|
{ }
|
||||||
}
|
|
||||||
|
|
||||||
~InternalHeap();
|
~InternalHeap();
|
||||||
|
|
||||||
@ -49,24 +48,22 @@ namespace Aurora::Memory
|
|||||||
void *_FRealloc(void *buffer, Types::size_t length) override;
|
void *_FRealloc(void *buffer, Types::size_t length) override;
|
||||||
void *_FRealloc(void *buffer, Types::size_t length, Types::size_t align) override;
|
void *_FRealloc(void *buffer, Types::size_t length, Types::size_t align) override;
|
||||||
void _Free(void *buffer) override;
|
void _Free(void *buffer) override;
|
||||||
|
|
||||||
void TryRelease();
|
void TryRelease();
|
||||||
void RequestTermination();
|
void RequestTermination();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Threading::Primitives::MutexUnique_t mutex_;
|
Threading::Primitives::MutexUnique_t mutex_;
|
||||||
void *base_{};
|
void *base_ {};
|
||||||
O1HeapInstance *heap_{};
|
O1HeapInstance *heap_ {};
|
||||||
int _count{};
|
int _count {};
|
||||||
bool _isDangling{};
|
bool _isDangling {};
|
||||||
};
|
};
|
||||||
|
|
||||||
InternalHeap::~InternalHeap()
|
InternalHeap::~InternalHeap()
|
||||||
{
|
{
|
||||||
SysAssertDbgExp(_count == 0);
|
SysAssertDbgExp(_count == 0);
|
||||||
|
|
||||||
mutex_.reset();
|
|
||||||
|
|
||||||
if (base_)
|
if (base_)
|
||||||
{
|
{
|
||||||
o1HeapReleaseCpp(heap_);// ->~O1HeapInstance(); // TODO: make free func
|
o1HeapReleaseCpp(heap_);// ->~O1HeapInstance(); // TODO: make free func
|
||||||
@ -75,6 +72,8 @@ namespace Aurora::Memory
|
|||||||
base_ = nullptr;
|
base_ = nullptr;
|
||||||
mi_collect(false);
|
mi_collect(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mutex_.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InternalHeap::Init(AuUInt length)
|
bool InternalHeap::Init(AuUInt length)
|
||||||
@ -222,7 +221,7 @@ namespace Aurora::Memory
|
|||||||
return heap;
|
return heap;
|
||||||
}
|
}
|
||||||
|
|
||||||
AUKN_SYM void AllocHeapRelease(Heap *heap)
|
AUKN_SYM void AllocHeapRelease(Heap *heap)
|
||||||
{
|
{
|
||||||
dynamic_cast<InternalHeap *>(heap)->RequestTermination();
|
dynamic_cast<InternalHeap *>(heap)->RequestTermination();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user