AuroraRuntime/Source/AuCrypto.cpp
Reece Wilson d63571e4b5 [+] AuCompression::CompressionInterceptor
[+] AuCrypto::CBC::CBCContext
[+] AuFS::ReadDirRecursive
[+] AuFS::DirDeleter
[+] AuCrypto::PBKDF2
[+] AuCrypto::AES::CBCEncrypt
[+] AuCrypto::AES::CBCDecrypt
[+] AuCrypto::TDES::CBCEncrypt
[+] AuCrypto::TDES::CBCDecrypt
[+] Optimize read write locks
[*] Added `ContextFlags = CONTEXT_ALL` to Win32 PlatformWalkCallStack
2022-11-06 13:23:22 +00:00

111 lines
3.3 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Crypto.cpp
Date: 2021-6-17
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "AuCrypto.hpp"
#include <tomcrypt.h>
namespace Crypto
{
static prng_state gPrng;
static void TomCryptInit()
{
crypt_mp_init("ltm");
yarrow_start(&gPrng);
gHashTiger = register_hash(&tiger_desc);
register_hash(&md5_desc);
gHashSha1 = register_hash(&sha1_desc);
gHashSha256 = register_hash(&sha256_desc);
gHashSha384 = register_hash(&sha384_desc);
gHashSha512 = register_hash(&sha512_desc);
gHashSha3_224 = register_hash(&sha3_224_desc);
gHashSha3_256 = register_hash(&sha3_256_desc);
gHashSha3_384 = register_hash(&sha3_384_desc);
gHashSha3_512 = register_hash(&sha3_512_desc);
gHashMD5 = register_hash(&md5_desc);
gHashMD4 = register_hash(&md4_desc);
gHashRMD128 = register_hash(&rmd128_desc);
gHashRMD160 = register_hash(&rmd160_desc);
gHashRMD256 = register_hash(&rmd256_desc);
gHashRMD320 = register_hash(&rmd320_desc);
gPrngYarrow = register_prng(&yarrow_desc);
gAesCipher = register_cipher(&aes_desc);
gDesCipher = register_cipher(&des3_desc);
}
static void MBedTlsInit()
{
}
void InitCrypto()
{
TomCryptInit();
MBedTlsInit();
}
int PaddingToType(Aurora::Crypto::EPaddingType type)
{
switch (type)
{
case Aurora::Crypto::EPaddingType::ePaddingNone:
return 0;
case Aurora::Crypto::EPaddingType::ePKCS_1_5:
return LTC_PKCS_1_V1_5;
case Aurora::Crypto::EPaddingType::ePKCS_1_5_NA1:
return LTC_PKCS_1_V1_5_NA1;
case Aurora::Crypto::EPaddingType::ePKCS_OAEP:
return LTC_PKCS_1_OAEP;
case Aurora::Crypto::EPaddingType::ePKCS_1_PSS:
return LTC_PKCS_1_PSS;
default:
return 0xFF;
}
}
int HashMethodToId(Aurora::Hashing::EHashType type)
{
switch (type)
{
case AuHashing::EHashType::eMD4:
return gHashMD4;
case AuHashing::EHashType::eMD5:
return gHashMD5;
case AuHashing::EHashType::eRMD128:
return gHashRMD128;
case AuHashing::EHashType::eRMD160:
return gHashRMD160;
case AuHashing::EHashType::eRMD256:
return gHashRMD256;
case AuHashing::EHashType::eRMD320:
return gHashRMD320;
case AuHashing::EHashType::eSHA1:
return gHashSha1;
case AuHashing::EHashType::eSHA2_32:
return gHashSha256;
case AuHashing::EHashType::eSHA2_64:
return gHashSha512;
case AuHashing::EHashType::eSHA2_48:
return gHashSha384;
case AuHashing::EHashType::eTiger:
return gHashTiger;
case AuHashing::EHashType::eSHA3_28:
return gHashSha3_224;
case AuHashing::EHashType::eSHA3_32:
return gHashSha3_256;
case AuHashing::EHashType::eSHA3_48:
return gHashSha3_384;
case AuHashing::EHashType::eSHA3_64:
return gHashSha3_512;
default:
return 0xFF;
}
}
}