2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-06-26 06:11:53 +00:00

refactor: cryptography component

This commit is contained in:
Jan
2025-04-25 21:26:44 +01:00
committed by Jan Laupetin
parent 60f5c1a18f
commit 5635470b6e
63 changed files with 550 additions and 723 deletions

View File

@ -91,11 +91,11 @@ namespace
#undef XBLOCK_DEF
}
std::unique_ptr<IPublicKeyAlgorithm> SetupRSA(const bool isOfficial)
std::unique_ptr<cryptography::IPublicKeyAlgorithm> SetupRsa(const bool isOfficial)
{
if (isOfficial)
{
auto rsa = Crypto::CreateRSA(IPublicKeyAlgorithm::HashingAlgorithm::RSA_HASH_SHA256, Crypto::RSAPaddingMode::RSA_PADDING_PSS);
auto rsa = cryptography::CreateRsa(cryptography::HashingAlgorithm::RSA_HASH_SHA256, cryptography::RsaPaddingMode::RSA_PADDING_PSS);
if (!rsa->SetKey(ZoneConstants::RSA_PUBLIC_KEY_INFINITY_WARD, sizeof(ZoneConstants::RSA_PUBLIC_KEY_INFINITY_WARD)))
{
@ -121,7 +121,7 @@ namespace
return;
// If file is signed setup a RSA instance.
auto rsa = SetupRSA(isOfficial);
auto rsa = SetupRsa(isOfficial);
zoneLoader.AddLoadingStep(std::make_unique<StepVerifyMagic>(ZoneConstants::MAGIC_AUTH_HEADER));
zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
@ -147,8 +147,7 @@ namespace
auto* masterBlockHashesPtr = masterBlockHashes.get();
zoneLoader.AddLoadingStep(std::move(masterBlockHashes));
zoneLoader.AddLoadingStep(
std::make_unique<StepVerifyHash>(std::unique_ptr<IHashFunction>(Crypto::CreateSHA256()), 0, subHeaderHashPtr, subHeaderCapturePtr));
zoneLoader.AddLoadingStep(std::make_unique<StepVerifyHash>(cryptography::CreateSha256(), 0, subHeaderHashPtr, subHeaderCapturePtr));
zoneLoader.AddLoadingStep(std::make_unique<StepRemoveProcessor>(subHeaderCapturePtr));
// Skip the rest of the first chunk
@ -158,7 +157,7 @@ namespace
std::make_unique<StepAddProcessor>(std::make_unique<ProcessorAuthedBlocks>(ZoneConstants::AUTHED_CHUNK_COUNT_PER_GROUP,
ZoneConstants::AUTHED_CHUNK_SIZE,
std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>,
Crypto::CreateSHA256(),
cryptography::CreateSha256(),
masterBlockHashesPtr)));
}
} // namespace

View File

@ -75,11 +75,11 @@ namespace
#undef XBLOCK_DEF
}
std::unique_ptr<IPublicKeyAlgorithm> SetupRSA(const bool isOfficial)
std::unique_ptr<cryptography::IPublicKeyAlgorithm> SetupRsa(const bool isOfficial)
{
if (isOfficial)
{
auto rsa = Crypto::CreateRSA(IPublicKeyAlgorithm::HashingAlgorithm::RSA_HASH_SHA256, Crypto::RSAPaddingMode::RSA_PADDING_PSS);
auto rsa = cryptography::CreateRsa(cryptography::HashingAlgorithm::RSA_HASH_SHA256, cryptography::RsaPaddingMode::RSA_PADDING_PSS);
if (!rsa->SetKey(ZoneConstants::RSA_PUBLIC_KEY_INFINITY_WARD, sizeof(ZoneConstants::RSA_PUBLIC_KEY_INFINITY_WARD)))
{
@ -105,7 +105,7 @@ namespace
return;
// If file is signed setup a RSA instance.
auto rsa = SetupRSA(isOfficial);
auto rsa = SetupRsa(isOfficial);
zoneLoader.AddLoadingStep(std::make_unique<StepVerifyMagic>(ZoneConstants::MAGIC_AUTH_HEADER));
zoneLoader.AddLoadingStep(std::make_unique<StepSkipBytes>(4)); // Skip reserved
@ -131,8 +131,7 @@ namespace
auto* masterBlockHashesPtr = masterBlockHashes.get();
zoneLoader.AddLoadingStep(std::move(masterBlockHashes));
zoneLoader.AddLoadingStep(
std::make_unique<StepVerifyHash>(std::unique_ptr<IHashFunction>(Crypto::CreateSHA256()), 0, subHeaderHashPtr, subHeaderCapturePtr));
zoneLoader.AddLoadingStep(std::make_unique<StepVerifyHash>(cryptography::CreateSha256(), 0, subHeaderHashPtr, subHeaderCapturePtr));
zoneLoader.AddLoadingStep(std::make_unique<StepRemoveProcessor>(subHeaderCapturePtr));
// Skip the rest of the first chunk
@ -142,7 +141,7 @@ namespace
std::make_unique<StepAddProcessor>(std::make_unique<ProcessorAuthedBlocks>(ZoneConstants::AUTHED_CHUNK_COUNT_PER_GROUP,
ZoneConstants::AUTHED_CHUNK_SIZE,
std::extent_v<decltype(DB_AuthSubHeader::masterBlockHashes)>,
Crypto::CreateSHA256(),
cryptography::CreateSha256(),
masterBlockHashesPtr)));
}
} // namespace

View File

@ -105,11 +105,11 @@ namespace
#undef XBLOCK_DEF
}
std::unique_ptr<IPublicKeyAlgorithm> SetupRSA(const bool isOfficial)
std::unique_ptr<cryptography::IPublicKeyAlgorithm> SetupRsa(const bool isOfficial)
{
if (isOfficial)
{
auto rsa = Crypto::CreateRSA(IPublicKeyAlgorithm::HashingAlgorithm::RSA_HASH_SHA256, Crypto::RSAPaddingMode::RSA_PADDING_PSS);
auto rsa = cryptography::CreateRsa(cryptography::HashingAlgorithm::RSA_HASH_SHA256, cryptography::RsaPaddingMode::RSA_PADDING_PSS);
if (!rsa->SetKey(ZoneConstants::RSA_PUBLIC_KEY_TREYARCH, sizeof(ZoneConstants::RSA_PUBLIC_KEY_TREYARCH)))
{
@ -190,7 +190,7 @@ std::unique_ptr<ZoneLoader> ZoneLoaderFactory::CreateLoaderForHeader(ZoneHeader&
SetupBlock(*zoneLoader);
// If file is signed setup a RSA instance.
auto rsa = isSecure ? SetupRSA(isOfficial) : nullptr;
auto rsa = isSecure ? SetupRsa(isOfficial) : nullptr;
// Add steps for loading the auth header which also contain the signature of the zone if it is signed.
ISignatureProvider* signatureProvider = AddAuthHeaderSteps(isSecure, *zoneLoader, fileName);