mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-07-04 18:47:53 -05:00
Read IW4 signed headers
This commit is contained in:
63
src/Crypto/Impl/AlgorithmSHA256.cpp
Normal file
63
src/Crypto/Impl/AlgorithmSHA256.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
#include "AlgorithmSHA256.h"
|
||||
|
||||
#include "CryptoLibrary.h"
|
||||
#include <cstdint>
|
||||
|
||||
class AlgorithmSHA256::Impl
|
||||
{
|
||||
hash_state m_state{};
|
||||
|
||||
public:
|
||||
Impl()
|
||||
{
|
||||
CryptoLibrary::Init();
|
||||
|
||||
Init();
|
||||
}
|
||||
|
||||
void Init()
|
||||
{
|
||||
sha256_init(&m_state);
|
||||
}
|
||||
|
||||
void Process(const void* input, const size_t inputSize)
|
||||
{
|
||||
sha256_process(&m_state, static_cast<const uint8_t*>(input), inputSize);
|
||||
}
|
||||
|
||||
void Finish(void* hashBuffer)
|
||||
{
|
||||
sha256_done(&m_state, static_cast<uint8_t*>(hashBuffer));
|
||||
}
|
||||
};
|
||||
|
||||
AlgorithmSHA256::AlgorithmSHA256()
|
||||
{
|
||||
m_impl = new Impl();
|
||||
}
|
||||
|
||||
AlgorithmSHA256::~AlgorithmSHA256()
|
||||
{
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
}
|
||||
|
||||
size_t AlgorithmSHA256::GetHashSize()
|
||||
{
|
||||
return HASH_SIZE;
|
||||
}
|
||||
|
||||
void AlgorithmSHA256::Init()
|
||||
{
|
||||
m_impl->Init();
|
||||
}
|
||||
|
||||
void AlgorithmSHA256::Process(const void* input, const size_t inputSize)
|
||||
{
|
||||
m_impl->Process(input, inputSize);
|
||||
}
|
||||
|
||||
void AlgorithmSHA256::Finish(void* hashBuffer)
|
||||
{
|
||||
m_impl->Finish(hashBuffer);
|
||||
}
|
20
src/Crypto/Impl/AlgorithmSHA256.h
Normal file
20
src/Crypto/Impl/AlgorithmSHA256.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include "IHashFunction.h"
|
||||
|
||||
class AlgorithmSHA256 : public IHashFunction
|
||||
{
|
||||
class Impl;
|
||||
Impl* m_impl;
|
||||
|
||||
public:
|
||||
static const int HASH_SIZE = 32;
|
||||
|
||||
AlgorithmSHA256();
|
||||
~AlgorithmSHA256() override;
|
||||
|
||||
size_t GetHashSize() override;
|
||||
|
||||
void Init() override;
|
||||
void Process(const void* input, size_t inputSize) override;
|
||||
void Finish(void* hashBuffer) override;
|
||||
};
|
Reference in New Issue
Block a user