strat: use m_ for member variables
This commit is contained in:
@@ -19,30 +19,30 @@
|
||||
namespace ams::spl {
|
||||
|
||||
void CtrDrbg::Update(const void *data) {
|
||||
aes128ContextCreate(std::addressof(this->aes_ctx), this->key, true);
|
||||
for (size_t offset = 0; offset < sizeof(this->work[1]); offset += BlockSize) {
|
||||
IncrementCounter(this->counter);
|
||||
aes128EncryptBlock(std::addressof(this->aes_ctx), std::addressof(this->work[1][offset]), this->counter);
|
||||
aes128ContextCreate(std::addressof(m_aes_ctx), m_key, true);
|
||||
for (size_t offset = 0; offset < sizeof(m_work[1]); offset += BlockSize) {
|
||||
IncrementCounter(m_counter);
|
||||
aes128EncryptBlock(std::addressof(m_aes_ctx), std::addressof(m_work[1][offset]), m_counter);
|
||||
}
|
||||
|
||||
Xor(this->work[1], data, sizeof(this->work[1]));
|
||||
Xor(m_work[1], data, sizeof(m_work[1]));
|
||||
|
||||
std::memcpy(this->key, std::addressof(this->work[1][0]), sizeof(this->key));
|
||||
std::memcpy(this->counter, std::addressof(this->work[1][BlockSize]), sizeof(this->key));
|
||||
std::memcpy(m_key, std::addressof(m_work[1][0]), sizeof(m_key));
|
||||
std::memcpy(m_counter, std::addressof(m_work[1][BlockSize]), sizeof(m_key));
|
||||
}
|
||||
|
||||
void CtrDrbg::Initialize(const void *seed) {
|
||||
std::memcpy(this->work[0], seed, sizeof(this->work[0]));
|
||||
std::memset(this->key, 0, sizeof(this->key));
|
||||
std::memset(this->counter, 0, sizeof(this->counter));
|
||||
this->Update(this->work[0]);
|
||||
this->reseed_counter = 1;
|
||||
std::memcpy(m_work[0], seed, sizeof(m_work[0]));
|
||||
std::memset(m_key, 0, sizeof(m_key));
|
||||
std::memset(m_counter, 0, sizeof(m_counter));
|
||||
this->Update(m_work[0]);
|
||||
m_reseed_counter = 1;
|
||||
}
|
||||
|
||||
void CtrDrbg::Reseed(const void *seed) {
|
||||
std::memcpy(this->work[0], seed, sizeof(this->work[0]));
|
||||
this->Update(this->work[0]);
|
||||
this->reseed_counter = 1;
|
||||
std::memcpy(m_work[0], seed, sizeof(m_work[0]));
|
||||
this->Update(m_work[0]);
|
||||
m_reseed_counter = 1;
|
||||
}
|
||||
|
||||
bool CtrDrbg::GenerateRandomBytes(void *out, size_t size) {
|
||||
@@ -50,30 +50,30 @@ namespace ams::spl {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this->reseed_counter > ReseedInterval) {
|
||||
if (m_reseed_counter > ReseedInterval) {
|
||||
return false;
|
||||
}
|
||||
|
||||
aes128ContextCreate(std::addressof(this->aes_ctx), this->key, true);
|
||||
aes128ContextCreate(std::addressof(m_aes_ctx), m_key, true);
|
||||
u8 *cur_dst = reinterpret_cast<u8 *>(out);
|
||||
|
||||
size_t aligned_size = (size & ~(BlockSize - 1));
|
||||
for (size_t offset = 0; offset < aligned_size; offset += BlockSize) {
|
||||
IncrementCounter(this->counter);
|
||||
aes128EncryptBlock(std::addressof(this->aes_ctx), cur_dst, this->counter);
|
||||
IncrementCounter(m_counter);
|
||||
aes128EncryptBlock(std::addressof(m_aes_ctx), cur_dst, m_counter);
|
||||
cur_dst += BlockSize;
|
||||
}
|
||||
|
||||
if (size > aligned_size) {
|
||||
IncrementCounter(this->counter);
|
||||
aes128EncryptBlock(std::addressof(this->aes_ctx), this->work[1], this->counter);
|
||||
std::memcpy(cur_dst, this->work[1], size - aligned_size);
|
||||
IncrementCounter(m_counter);
|
||||
aes128EncryptBlock(std::addressof(m_aes_ctx), m_work[1], m_counter);
|
||||
std::memcpy(cur_dst, m_work[1], size - aligned_size);
|
||||
}
|
||||
|
||||
std::memset(this->work[0], 0, sizeof(this->work[0]));
|
||||
this->Update(this->work[0]);
|
||||
std::memset(m_work[0], 0, sizeof(m_work[0]));
|
||||
this->Update(m_work[0]);
|
||||
|
||||
this->reseed_counter++;
|
||||
m_reseed_counter++;
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user