[*] Went over baseN and RSA again

This commit is contained in:
Reece Wilson 2022-09-19 21:34:54 +01:00
parent c36f159f95
commit 6ac4fd61ab
3 changed files with 47 additions and 29 deletions

View File

@ -149,7 +149,7 @@ namespace Aurora::Crypto::RSA
AuSPtr<IRSAPublic> PrivateRSA::ToPublic() AuSPtr<IRSAPublic> PrivateRSA::ToPublic()
{ {
rsa_key key; rsa_key key {};
key.type = this->key_.type; key.type = this->key_.type;
#define COPY_KEY_PART(x) \ #define COPY_KEY_PART(x) \
@ -206,7 +206,6 @@ namespace Aurora::Crypto::RSA
AUKN_SYM IRSAPrivate *NewRSAKeyNew(AuUInt16 keySize) AUKN_SYM IRSAPrivate *NewRSAKeyNew(AuUInt16 keySize)
{ {
prng_state yarrow_prng {};
rsa_key key {}; rsa_key key {};
const int prng_idx = register_prng(&sprng_desc); const int prng_idx = register_prng(&sprng_desc);

View File

@ -13,21 +13,28 @@ namespace Aurora::Parse
{ {
AUKN_SYM bool Base32Decode(const AuString &in, AuByteBuffer &decoded) AUKN_SYM bool Base32Decode(const AuString &in, AuByteBuffer &decoded)
{ {
int iRet;
unsigned long length = in.size(); unsigned long length = in.size();
auto writeView = decoded.GetOrAllocateLinearWriteable(length); auto writeView = decoded.GetOrAllocateLinearWriteable(length);
if (!writeView) if (!writeView)
{ {
SysPushErrorMem(); SysPushErrorMem();
return {}; return false;
}
iRet = ::base32_decode(AuReinterpretCast<const char *>(decoded.writePtr),
(unsigned long)length,
AuReinterpretCast<unsigned char *>(&decoded[0]),
&length,
BASE32_RFC4648);
if (iRet != CRYPT_OK)
{
return false;
} }
auto status = ::base32_decode(AuReinterpretCast<const char *>(decoded.writePtr),
(unsigned long)length,
AuReinterpretCast<unsigned char *>(&decoded[0]),
&length, BASE32_RFC4648);
decoded.writePtr += length; decoded.writePtr += length;
return status == CRYPT_OK; return true;
} }
AUKN_SYM bool Base32Encode(const void *buffer, AuMach length, AuString &encoded) AUKN_SYM bool Base32Encode(const void *buffer, AuMach length, AuString &encoded)
@ -40,17 +47,18 @@ namespace Aurora::Parse
return false; return false;
} }
auto status = ::base32_encode(AuReinterpretCast<const unsigned char *>(buffer), auto iRet = ::base32_encode(AuReinterpretCast<const unsigned char *>(buffer),
(unsigned long)length, (unsigned long)length,
&encoded[0], &encoded[0],
&outLength, &outLength,
BASE32_RFC4648); BASE32_RFC4648);
if (!AuTryResize(encoded, length))
if (!AuTryResize(encoded, outLength))
{ {
SysPushErrorMem(); SysPushErrorMem();
return false; return false;
} }
return status == CRYPT_OK; return iRet == CRYPT_OK;
} }
} }

View File

@ -13,6 +13,7 @@ namespace Aurora::Parse
{ {
AUKN_SYM bool Base64Decode(const AuString &in, AuByteBuffer &decoded, bool url) AUKN_SYM bool Base64Decode(const AuString &in, AuByteBuffer &decoded, bool url)
{ {
int iRet;
unsigned long length = (unsigned long)in.size(); unsigned long length = (unsigned long)in.size();
auto writeView = decoded.GetOrAllocateLinearWriteable(length); auto writeView = decoded.GetOrAllocateLinearWriteable(length);
@ -22,28 +23,33 @@ namespace Aurora::Parse
return {}; return {};
} }
int status;
if (url) if (url)
{ {
status = ::base64url_decode(AuReinterpretCast<const char *>(decoded.writePtr), iRet = ::base64url_decode(AuReinterpretCast<const char *>(decoded.writePtr),
(unsigned long)length, (unsigned long)length,
AuReinterpretCast<unsigned char *>(&decoded[0]), AuReinterpretCast<unsigned char *>(&decoded[0]),
&length); &length);
} }
else else
{ {
status = ::base64_decode(AuReinterpretCast<const char *>(decoded.writePtr), iRet = ::base64_decode(AuReinterpretCast<const char *>(decoded.writePtr),
(unsigned long)length, (unsigned long)length,
AuReinterpretCast<unsigned char *>(&decoded[0]), AuReinterpretCast<unsigned char *>(&decoded[0]),
&length); &length);
}
if (iRet != CRYPT_OK)
{
return false;
} }
decoded.writePtr += length; decoded.writePtr += length;
return status == CRYPT_OK; return true;
} }
AUKN_SYM bool Base64Encode(const Memory::MemoryViewRead &input, AuString &encoded, bool url) AUKN_SYM bool Base64Encode(const Memory::MemoryViewRead &input, AuString &encoded, bool url)
{ {
int iRet;
unsigned long outLength = input.length + (input.length / 3.0) + 16; unsigned long outLength = input.length + (input.length / 3.0) + 16;
if (!AuTryResize(encoded, outLength)) if (!AuTryResize(encoded, outLength))
@ -52,14 +58,19 @@ namespace Aurora::Parse
return false; return false;
} }
int status;
if (url) if (url)
{ {
status = base64url_encode(reinterpret_cast<const unsigned char*>(input.ptr), (unsigned long)input.length, &encoded[0], &outLength); iRet = ::base64url_encode(AuReinterpretCast<const unsigned char*>(input.ptr),
(unsigned long)input.length,
&encoded[0],
&outLength);
} }
else else
{ {
status = base64_encode(reinterpret_cast<const unsigned char*>(input.ptr), (unsigned long)input.length, &encoded[0], &outLength); iRet =::base64_encode(AuReinterpretCast<const unsigned char*>(input.ptr),
(unsigned long)input.length,
&encoded[0],
&outLength);
} }
if (!AuTryResize(encoded, outLength)) if (!AuTryResize(encoded, outLength))
@ -68,6 +79,6 @@ namespace Aurora::Parse
return false; return false;
} }
return status == CRYPT_OK; return iRet == CRYPT_OK;
} }
} }