strat: use m_ for member variables
This commit is contained in:
@@ -186,25 +186,25 @@ namespace ams::spl::impl {
|
||||
/* Type definitions. */
|
||||
class ScopedAesKeySlot {
|
||||
private:
|
||||
s32 slot;
|
||||
bool has_slot;
|
||||
s32 m_slot;
|
||||
bool m_has_slot;
|
||||
public:
|
||||
ScopedAesKeySlot() : slot(-1), has_slot(false) {
|
||||
ScopedAesKeySlot() : m_slot(-1), m_has_slot(false) {
|
||||
/* ... */
|
||||
}
|
||||
~ScopedAesKeySlot() {
|
||||
if (this->has_slot) {
|
||||
DeallocateAesKeySlot(slot, this);
|
||||
if (m_has_slot) {
|
||||
DeallocateAesKeySlot(m_slot, this);
|
||||
}
|
||||
}
|
||||
|
||||
u32 GetKeySlot() const {
|
||||
return this->slot;
|
||||
return m_slot;
|
||||
}
|
||||
|
||||
Result Allocate() {
|
||||
R_TRY(AllocateAesKeySlot(std::addressof(this->slot), this));
|
||||
this->has_slot = true;
|
||||
R_TRY(AllocateAesKeySlot(std::addressof(m_slot), this));
|
||||
m_has_slot = true;
|
||||
return ResultSuccess();
|
||||
}
|
||||
};
|
||||
@@ -222,17 +222,17 @@ namespace ams::spl::impl {
|
||||
|
||||
class DeviceAddressSpaceMapHelper {
|
||||
private:
|
||||
os::NativeHandle das_hnd;
|
||||
u64 dst_addr;
|
||||
u64 src_addr;
|
||||
size_t size;
|
||||
svc::MemoryPermission perm;
|
||||
os::NativeHandle m_handle;
|
||||
u64 m_dst_addr;
|
||||
u64 m_src_addr;
|
||||
size_t m_size;
|
||||
svc::MemoryPermission m_perm;
|
||||
public:
|
||||
DeviceAddressSpaceMapHelper(os::NativeHandle h, u64 dst, u64 src, size_t sz, svc::MemoryPermission p) : das_hnd(h), dst_addr(dst), src_addr(src), size(sz), perm(p) {
|
||||
R_ABORT_UNLESS(svc::MapDeviceAddressSpaceAligned(this->das_hnd, dd::GetCurrentProcessHandle(), this->src_addr, this->size, this->dst_addr, this->perm));
|
||||
DeviceAddressSpaceMapHelper(os::NativeHandle h, u64 dst, u64 src, size_t sz, svc::MemoryPermission p) : m_handle(h), m_dst_addr(dst), m_src_addr(src), m_size(sz), m_perm(p) {
|
||||
R_ABORT_UNLESS(svc::MapDeviceAddressSpaceAligned(m_handle, dd::GetCurrentProcessHandle(), m_src_addr, m_size, m_dst_addr, m_perm));
|
||||
}
|
||||
~DeviceAddressSpaceMapHelper() {
|
||||
R_ABORT_UNLESS(svc::UnmapDeviceAddressSpace(this->das_hnd, dd::GetCurrentProcessHandle(), this->src_addr, this->size, this->dst_addr));
|
||||
R_ABORT_UNLESS(svc::UnmapDeviceAddressSpace(m_handle, dd::GetCurrentProcessHandle(), m_src_addr, m_size, m_dst_addr));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -26,11 +26,11 @@ namespace ams::spl {
|
||||
static constexpr size_t BlockSize = AES_BLOCK_SIZE;
|
||||
static constexpr size_t SeedSize = 2 * AES_BLOCK_SIZE;
|
||||
private:
|
||||
Aes128Context aes_ctx;
|
||||
u8 counter[BlockSize];
|
||||
u8 key[BlockSize];
|
||||
u8 work[2][SeedSize];
|
||||
u32 reseed_counter;
|
||||
Aes128Context m_aes_ctx;
|
||||
u8 m_counter[BlockSize];
|
||||
u8 m_key[BlockSize];
|
||||
u8 m_work[2][SeedSize];
|
||||
u32 m_reseed_counter;
|
||||
private:
|
||||
static void Xor(void *dst, const void *src, size_t size) {
|
||||
const u8 *src_u8 = reinterpret_cast<const u8 *>(src);
|
||||
|
||||
@@ -26,25 +26,25 @@ namespace ams::spl {
|
||||
public:
|
||||
static constexpr size_t KeySize = crypto::AesDecryptor128::KeySize;
|
||||
private:
|
||||
const s32 slot_index;
|
||||
s32 virtual_slot;
|
||||
const s32 m_slot_index;
|
||||
s32 m_virtual_slot;
|
||||
public:
|
||||
explicit KeySlotCacheEntry(s32 idx) : slot_index(idx), virtual_slot(-1) { /* ... */ }
|
||||
explicit KeySlotCacheEntry(s32 idx) : m_slot_index(idx), m_virtual_slot(-1) { /* ... */ }
|
||||
|
||||
bool Contains(s32 virtual_slot) const {
|
||||
return virtual_slot == this->virtual_slot;
|
||||
return virtual_slot == m_virtual_slot;
|
||||
}
|
||||
|
||||
s32 GetPhysicalKeySlotIndex() const { return this->slot_index; }
|
||||
s32 GetPhysicalKeySlotIndex() const { return m_slot_index; }
|
||||
|
||||
s32 GetVirtualKeySlotIndex() const { return this->virtual_slot; }
|
||||
s32 GetVirtualKeySlotIndex() const { return m_virtual_slot; }
|
||||
|
||||
void SetVirtualSlot(s32 virtual_slot) {
|
||||
this->virtual_slot = virtual_slot;
|
||||
m_virtual_slot = virtual_slot;
|
||||
}
|
||||
|
||||
void ClearVirtualSlot() {
|
||||
this->virtual_slot = -1;
|
||||
m_virtual_slot = -1;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -54,16 +54,16 @@ namespace ams::spl {
|
||||
private:
|
||||
using KeySlotCacheEntryList = util::IntrusiveListBaseTraits<KeySlotCacheEntry>::ListType;
|
||||
private:
|
||||
KeySlotCacheEntryList mru_list;
|
||||
KeySlotCacheEntryList m_mru_list;
|
||||
public:
|
||||
constexpr KeySlotCache() : mru_list() { /* ... */ }
|
||||
constexpr KeySlotCache() : m_mru_list() { /* ... */ }
|
||||
|
||||
s32 Allocate(s32 virtual_slot) {
|
||||
return this->AllocateFromLru(virtual_slot);
|
||||
}
|
||||
|
||||
bool Find(s32 *out, s32 virtual_slot) {
|
||||
for (auto it = this->mru_list.begin(); it != this->mru_list.end(); ++it) {
|
||||
for (auto it = m_mru_list.begin(); it != m_mru_list.end(); ++it) {
|
||||
if (it->Contains(virtual_slot)) {
|
||||
*out = it->GetPhysicalKeySlotIndex();
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace ams::spl {
|
||||
}
|
||||
|
||||
bool Release(s32 *out, s32 virtual_slot) {
|
||||
for (auto it = this->mru_list.begin(); it != this->mru_list.end(); ++it) {
|
||||
for (auto it = m_mru_list.begin(); it != m_mru_list.end(); ++it) {
|
||||
if (it->Contains(virtual_slot)) {
|
||||
*out = it->GetPhysicalKeySlotIndex();
|
||||
it->ClearVirtualSlot();
|
||||
@@ -90,7 +90,7 @@ namespace ams::spl {
|
||||
}
|
||||
|
||||
bool FindPhysical(s32 physical_slot) {
|
||||
for (auto it = this->mru_list.begin(); it != this->mru_list.end(); ++it) {
|
||||
for (auto it = m_mru_list.begin(); it != m_mru_list.end(); ++it) {
|
||||
if (it->GetPhysicalKeySlotIndex() == physical_slot) {
|
||||
this->UpdateMru(it);
|
||||
|
||||
@@ -106,32 +106,32 @@ namespace ams::spl {
|
||||
}
|
||||
|
||||
void AddEntry(KeySlotCacheEntry *entry) {
|
||||
this->mru_list.push_front(*entry);
|
||||
m_mru_list.push_front(*entry);
|
||||
}
|
||||
private:
|
||||
s32 AllocateFromLru(s32 virtual_slot) {
|
||||
AMS_ASSERT(!this->mru_list.empty());
|
||||
AMS_ASSERT(!m_mru_list.empty());
|
||||
|
||||
auto it = this->mru_list.rbegin();
|
||||
auto it = m_mru_list.rbegin();
|
||||
it->SetVirtualSlot(virtual_slot);
|
||||
|
||||
auto *entry = std::addressof(*it);
|
||||
this->mru_list.pop_back();
|
||||
this->mru_list.push_front(*entry);
|
||||
m_mru_list.pop_back();
|
||||
m_mru_list.push_front(*entry);
|
||||
|
||||
return entry->GetPhysicalKeySlotIndex();
|
||||
}
|
||||
|
||||
void UpdateMru(KeySlotCacheEntryList::iterator it) {
|
||||
auto *entry = std::addressof(*it);
|
||||
this->mru_list.erase(it);
|
||||
this->mru_list.push_front(*entry);
|
||||
m_mru_list.erase(it);
|
||||
m_mru_list.push_front(*entry);
|
||||
}
|
||||
|
||||
void UpdateLru(KeySlotCacheEntryList::iterator it) {
|
||||
auto *entry = std::addressof(*it);
|
||||
this->mru_list.erase(it);
|
||||
this->mru_list.push_back(*entry);
|
||||
m_mru_list.erase(it);
|
||||
m_mru_list.push_back(*entry);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user