2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-07-04 02:01:51 +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

@ -40,8 +40,8 @@ void AbstractSalsa20Processor::InitStreams(const std::string& zoneName, const ui
{
m_stream_block_indices[stream] = 0;
m_stream_contexts[stream].m_salsa20 = Crypto::CreateSalsa20(salsa20Key, keySize);
m_stream_contexts[stream].m_sha1 = Crypto::CreateSHA1();
m_stream_contexts[stream].m_salsa20 = cryptography::CreateSalsa20(salsa20Key, keySize);
m_stream_contexts[stream].m_sha1 = cryptography::CreateSha1();
}
}

View File

@ -1,5 +1,6 @@
#pragma once
#include "Crypto.h"
#include "Cryptography.h"
#include "Utils/ClassUtils.h"
#include "Utils/ICapturedDataProvider.h"
@ -17,8 +18,8 @@ protected:
class StreamContext
{
public:
std::unique_ptr<IStreamCipher> m_salsa20;
std::unique_ptr<IHashFunction> m_sha1;
std::unique_ptr<cryptography::IStreamCipher> m_salsa20;
std::unique_ptr<cryptography::IHashFunction> m_sha1;
};
int m_stream_count;

View File

@ -1,7 +1,7 @@
#include "XChunkProcessorSalsa20Decryption.h"
#include "AbstractSalsa20Processor.h"
#include "Crypto.h"
#include "Cryptography.h"
#include <cassert>
@ -21,10 +21,10 @@ size_t XChunkProcessorSalsa20Decryption::Process(
assert(output != nullptr);
assert(inputLength <= outputBufferSize);
auto& streamContext = m_stream_contexts[streamNumber];
const auto& streamContext = m_stream_contexts[streamNumber];
// Initialize Salsa20 with an IV of the first 8 bytes of the current hash block
streamContext.m_salsa20->SetIV(GetHashBlock(streamNumber), SALSA20_IV_SIZE);
streamContext.m_salsa20->SetIv(GetHashBlock(streamNumber), SALSA20_IV_SIZE);
streamContext.m_salsa20->Process(input, output, inputLength);
// Hash decrypted XChunk

View File

@ -27,7 +27,7 @@ size_t XChunkProcessorSalsa20Encryption::Process(
streamContext.m_sha1->Finish(&blockSha1Hash);
// Initialize Salsa20 with an IV of the first 8 bytes of the current hash block
streamContext.m_salsa20->SetIV(GetHashBlock(streamNumber), SALSA20_IV_SIZE);
streamContext.m_salsa20->SetIv(GetHashBlock(streamNumber), SALSA20_IV_SIZE);
streamContext.m_salsa20->Process(input, output, inputLength);
// Advance index to next hash block