exo/vapours: refactor member variables to m_ over this->

This commit is contained in:
Michael Scire 2021-10-09 15:40:06 -07:00
parent 5a38311ebf
commit 67a45c97ef
55 changed files with 846 additions and 847 deletions

View file

@ -38,8 +38,8 @@ namespace ams::crypto {
static constexpr size_t BlockSize = CtrImpl::BlockSize;
static constexpr size_t IvSize = CtrImpl::BlockSize;
private:
AesImpl aes_impl;
CtrImpl ctr_impl;
AesImpl m_aes_impl;
CtrImpl m_ctr_impl;
public:
AesCtrCryptor() { /* ... */ }
@ -52,16 +52,16 @@ namespace ams::crypto {
AMS_ASSERT(iv_size == IvSize);
AMS_ASSERT(offset >= 0);
this->aes_impl.Initialize(key, key_size);
this->ctr_impl.Initialize(std::addressof(this->aes_impl), iv, iv_size, offset);
m_aes_impl.Initialize(key, key_size);
m_ctr_impl.Initialize(std::addressof(m_aes_impl), iv, iv_size, offset);
}
void SwitchMessage(const void *iv, size_t iv_size) {
return this->ctr_impl.SwitchMessage(iv, iv_size);
return m_ctr_impl.SwitchMessage(iv, iv_size);
}
size_t Update(void *dst, size_t dst_size, const void *src, size_t src_size) {
return this->ctr_impl.Update(dst, dst_size, src, src_size);
return m_ctr_impl.Update(dst, dst_size, src, src_size);
}
};

View file

@ -33,20 +33,20 @@ namespace ams::crypto {
static constexpr size_t BlockSize = Impl::BlockSize;
static constexpr size_t RoundKeySize = Impl::RoundKeySize;
private:
Impl impl;
Impl m_impl;
public:
AesDecryptor() { /* ... */ }
void Initialize(const void *key, size_t key_size) {
this->impl.Initialize(key, key_size, false);
m_impl.Initialize(key, key_size, false);
}
void DecryptBlock(void *dst, size_t dst_size, const void *src, size_t src_size) const {
return this->impl.DecryptBlock(dst, dst_size, src, src_size);
return m_impl.DecryptBlock(dst, dst_size, src, src_size);
}
const u8 *GetRoundKey() const {
return this->impl.GetRoundKey();
return m_impl.GetRoundKey();
}
};

View file

@ -33,20 +33,20 @@ namespace ams::crypto {
static constexpr size_t BlockSize = Impl::BlockSize;
static constexpr size_t RoundKeySize = Impl::RoundKeySize;
private:
Impl impl;
Impl m_impl;
public:
AesEncryptor() { /* ... */ }
void Initialize(const void *key, size_t key_size) {
this->impl.Initialize(key, key_size, true);
m_impl.Initialize(key, key_size, true);
}
void EncryptBlock(void *dst, size_t dst_size, const void *src, size_t src_size) const {
return this->impl.EncryptBlock(dst, dst_size, src, src_size);
return m_impl.EncryptBlock(dst, dst_size, src, src_size);
}
const u8 *GetRoundKey() const {
return this->impl.GetRoundKey();
return m_impl.GetRoundKey();
}
};

View file

@ -37,30 +37,30 @@ namespace ams::crypto {
static constexpr size_t BlockSize = AesImpl::BlockSize;
static constexpr size_t MacSize = AesImpl::BlockSize;
private:
AesImpl aes_impl;
GcmImpl gcm_impl;
AesImpl m_aes_impl;
GcmImpl m_gcm_impl;
public:
AesGcmEncryptor() { /* ... */ }
void Initialize(const void *key, size_t key_size, const void *iv, size_t iv_size) {
this->aes_impl.Initialize(key, key_size);
this->gcm_impl.Initialize(std::addressof(this->aes_impl), iv, iv_size);
m_aes_impl.Initialize(key, key_size);
m_gcm_impl.Initialize(std::addressof(m_aes_impl), iv, iv_size);
}
void Reset(const void *iv, size_t iv_size) {
this->gcm_impl.Reset(iv, iv_size);
m_gcm_impl.Reset(iv, iv_size);
}
size_t Update(void *dst, size_t dst_size, const void *src, size_t src_size) {
return this->gcm_impl.Update(dst, dst_size, src, src_size);
return m_gcm_impl.Update(dst, dst_size, src, src_size);
}
void UpdateAad(const void *aad, size_t aad_size) {
return this->gcm_impl.UpdateAad(aad, aad_size);
return m_gcm_impl.UpdateAad(aad, aad_size);
}
void GetMac(void *dst, size_t dst_size) {
return this->gcm_impl.GetMac(dst, dst_size);
return m_gcm_impl.GetMac(dst, dst_size);
}
};

View file

@ -42,9 +42,9 @@ namespace ams::crypto {
static_assert(AesImpl1::KeySize == AesImpl2::KeySize);
static_assert(AesImpl1::BlockSize == AesImpl2::BlockSize);
private:
AesImpl1 aes_impl_1;
AesImpl2 aes_impl_2;
XtsImpl xts_impl;
AesImpl1 m_aes_impl_1;
AesImpl2 m_aes_impl_2;
XtsImpl m_xts_impl;
public:
AesXtsCryptor() { /* ... */ }
@ -52,17 +52,17 @@ namespace ams::crypto {
AMS_ASSERT(key_size == KeySize);
AMS_ASSERT(iv_size == IvSize);
this->aes_impl_1.Initialize(key1, key_size);
this->aes_impl_2.Initialize(key2, key_size);
this->xts_impl.Initialize(std::addressof(this->aes_impl_1), std::addressof(this->aes_impl_2), iv, iv_size);
m_aes_impl_1.Initialize(key1, key_size);
m_aes_impl_2.Initialize(key2, key_size);
m_xts_impl.Initialize(std::addressof(m_aes_impl_1), std::addressof(m_aes_impl_2), iv, iv_size);
}
size_t Update(void *dst, size_t dst_size, const void *src, size_t src_size) {
return this->xts_impl.Update(dst, dst_size, src, src_size);
return m_xts_impl.Update(dst, dst_size, src, src_size);
}
size_t Finalize(void *dst, size_t dst_size) {
return this->xts_impl.Finalize(dst, dst_size);
return m_xts_impl.Finalize(dst, dst_size);
}
};

View file

@ -35,24 +35,24 @@ namespace ams::crypto {
static constexpr size_t BlockSize = Impl::BlockSize;
static constexpr size_t IvSize = Impl::IvSize;
private:
Impl impl;
Impl m_impl;
public:
CtrDecryptor() { /* ... */ }
void Initialize(const BlockCipher *cipher, const void *iv, size_t iv_size) {
this->impl.Initialize(cipher, iv, iv_size);
m_impl.Initialize(cipher, iv, iv_size);
}
void Initialize(const BlockCipher *cipher, const void *iv, size_t iv_size, s64 offset) {
this->impl.Initialize(cipher, iv, iv_size, offset);
m_impl.Initialize(cipher, iv, iv_size, offset);
}
void SwitchMessage(const void *iv, size_t iv_size) {
this->impl.SwitchMessage(iv, iv_size);
m_impl.SwitchMessage(iv, iv_size);
}
size_t Update(void *dst, size_t dst_size, const void *src, size_t src_size) {
return this->impl.Update(dst, dst_size, src, src_size);
return m_impl.Update(dst, dst_size, src, src_size);
}
};

View file

@ -35,24 +35,24 @@ namespace ams::crypto {
static constexpr size_t BlockSize = Impl::BlockSize;
static constexpr size_t IvSize = Impl::IvSize;
private:
Impl impl;
Impl m_impl;
public:
CtrEncryptor() { /* ... */ }
void Initialize(const BlockCipher *cipher, const void *iv, size_t iv_size) {
this->impl.Initialize(cipher, iv, iv_size);
m_impl.Initialize(cipher, iv, iv_size);
}
void Initialize(const BlockCipher *cipher, const void *iv, size_t iv_size, s64 offset) {
this->impl.Initialize(cipher, iv, iv_size, offset);
m_impl.Initialize(cipher, iv, iv_size, offset);
}
void SwitchMessage(const void *iv, size_t iv_size) {
this->impl.SwitchMessage(iv, iv_size);
m_impl.SwitchMessage(iv, iv_size);
}
size_t Update(void *dst, size_t dst_size, const void *src, size_t src_size) {
return this->impl.Update(dst, dst_size, src, src_size);
return m_impl.Update(dst, dst_size, src, src_size);
}
};

View file

@ -35,29 +35,29 @@ namespace ams::crypto {
static constexpr size_t BlockSize = Impl::BlockSize;
static constexpr size_t MacSize = Impl::MacSize;
private:
Impl impl;
Impl m_impl;
public:
GcmEncryptor() { /* ... */ }
void Initialize(const BlockCipher *cipher, const void *iv, size_t iv_size) {
this->impl.Initialize(cipher);
this->impl.Reset(iv, iv_size);
m_impl.Initialize(cipher);
m_impl.Reset(iv, iv_size);
}
void Reset(const void *iv, size_t iv_size) {
this->impl.Reset(iv, iv_size);
m_impl.Reset(iv, iv_size);
}
size_t Update(void *dst, size_t dst_size, const void *src, size_t src_size) {
return this->impl.Update(dst, dst_size, src, src_size);
return m_impl.Update(dst, dst_size, src, src_size);
}
void UpdateAad(const void *aad, size_t aad_size) {
return this->impl.UpdateAad(aad, aad_size);
return m_impl.UpdateAad(aad, aad_size);
}
void GetMac(void *dst, size_t dst_size) {
return this->impl.GetMac(dst, dst_size);
return m_impl.GetMac(dst, dst_size);
}
};

View file

@ -32,20 +32,20 @@ namespace ams::crypto {
static constexpr size_t HashSize = Impl::HashSize;
static constexpr size_t BlockSize = Impl::BlockSize;
private:
Impl impl;
Impl m_impl;
public:
HmacGenerator() { /* ... */ }
void Initialize(const void *key, size_t key_size) {
return this->impl.Initialize(key, key_size);
return m_impl.Initialize(key, key_size);
}
void Update(const void *data, size_t size) {
return this->impl.Update(data, size);
return m_impl.Update(data, size);
}
void GetMac(void *dst, size_t dst_size) {
return this->impl.GetMac(dst, dst_size);
return m_impl.GetMac(dst, dst_size);
}
};
}

View file

@ -29,17 +29,17 @@ namespace ams::crypto {
public:
static constexpr inline size_t RequiredWorkBufferSize = 0x10 * ModulusSize;
private:
impl::StaticBigNum<ModulusSize * BITSIZEOF(u8)> modulus;
impl::StaticBigNum<ExponentSize * BITSIZEOF(u8)> exponent;
impl::StaticBigNum<ModulusSize * BITSIZEOF(u8)> m_modulus;
impl::StaticBigNum<ExponentSize * BITSIZEOF(u8)> m_exponent;
public:
RsaCalculator() { /* ... */ }
~RsaCalculator() { this->exponent.ClearToZero(); }
~RsaCalculator() { m_exponent.ClearToZero(); }
bool Initialize(const void *mod, size_t mod_size, const void *exp, size_t exp_size) {
if (!this->modulus.Import(mod, mod_size) || this->modulus.IsZero()) {
if (!m_modulus.Import(mod, mod_size) || m_modulus.IsZero()) {
return false;
}
if (!this->exponent.Import(exp, exp_size) || this->exponent.IsZero()) {
if (!m_exponent.Import(exp, exp_size) || m_exponent.IsZero()) {
return false;
}
return true;
@ -48,7 +48,7 @@ namespace ams::crypto {
bool ExpMod(void *dst, const void *src, size_t size, void *work_buf, size_t work_buf_size) {
AMS_ASSERT(work_buf_size >= RequiredWorkBufferSize);
return this->modulus.ExpMod(dst, src, size, this->exponent, static_cast<u32 *>(work_buf), work_buf_size);
return m_modulus.ExpMod(dst, src, size, m_exponent, static_cast<u32 *>(work_buf), work_buf_size);
}
bool ExpMod(void *dst, const void *src, size_t size) {

View file

@ -39,23 +39,23 @@ namespace ams::crypto {
Done,
};
private:
RsaCalculator<ModulusSize, MaximumExponentSize> calculator;
Hash hash;
bool set_label_digest;
u8 label_digest[HashSize];
State state;
RsaCalculator<ModulusSize, MaximumExponentSize> m_calculator;
Hash m_hash;
bool m_set_label_digest;
u8 m_label_digest[HashSize];
State m_state;
public:
RsaOaepDecryptor() : set_label_digest(false), state(State::None) { std::memset(this->label_digest, 0, sizeof(this->label_digest)); }
RsaOaepDecryptor() : m_set_label_digest(false), m_state(State::None) { std::memset(m_label_digest, 0, sizeof(m_label_digest)); }
~RsaOaepDecryptor() {
ClearMemory(this->label_digest, sizeof(this->label_digest));
ClearMemory(m_label_digest, sizeof(m_label_digest));
}
bool Initialize(const void *mod, size_t mod_size, const void *exp, size_t exp_size) {
this->hash.Initialize();
this->set_label_digest = false;
if (this->calculator.Initialize(mod, mod_size, exp, exp_size)) {
this->state = State::Initialized;
m_hash.Initialize();
m_set_label_digest = false;
if (m_calculator.Initialize(mod, mod_size, exp, exp_size)) {
m_state = State::Initialized;
return true;
} else {
return false;
@ -63,58 +63,58 @@ namespace ams::crypto {
}
void UpdateLabel(const void *data, size_t size) {
AMS_ASSERT(this->state == State::Initialized);
AMS_ASSERT(m_state == State::Initialized);
this->hash.Update(data, size);
m_hash.Update(data, size);
}
void SetLabelDigest(const void *digest, size_t digest_size) {
AMS_ASSERT(this->state == State::Initialized);
AMS_ABORT_UNLESS(digest_size == sizeof(this->label_digest));
AMS_ASSERT(m_state == State::Initialized);
AMS_ABORT_UNLESS(digest_size == sizeof(m_label_digest));
std::memcpy(this->label_digest, digest, digest_size);
this->set_label_digest = true;
std::memcpy(m_label_digest, digest, digest_size);
m_set_label_digest = true;
}
size_t Decrypt(void *dst, size_t dst_size, const void *src, size_t src_size) {
AMS_ASSERT(this->state == State::Initialized);
AMS_ASSERT(m_state == State::Initialized);
impl::RsaOaepImpl<Hash> impl;
u8 message[BlockSize];
ON_SCOPE_EXIT { ClearMemory(message, sizeof(message)); };
if (!this->calculator.ExpMod(message, src, src_size)) {
if (!m_calculator.ExpMod(message, src, src_size)) {
std::memset(dst, 0, dst_size);
return false;
}
if (!this->set_label_digest) {
this->hash.GetHash(this->label_digest, sizeof(this->label_digest));
if (!m_set_label_digest) {
m_hash.GetHash(m_label_digest, sizeof(m_label_digest));
}
ON_SCOPE_EXIT { this->state = State::Done; };
ON_SCOPE_EXIT { m_state = State::Done; };
return impl.Decode(dst, dst_size, this->label_digest, sizeof(this->label_digest), message, sizeof(message));
return impl.Decode(dst, dst_size, m_label_digest, sizeof(m_label_digest), message, sizeof(message));
}
size_t Decrypt(void *dst, size_t dst_size, const void *src, size_t src_size, void *work_buf, size_t work_buf_size) {
AMS_ASSERT(this->state == State::Initialized);
ON_SCOPE_EXIT { this->state = State::Done; };
AMS_ASSERT(m_state == State::Initialized);
ON_SCOPE_EXIT { m_state = State::Done; };
impl::RsaOaepImpl<Hash> impl;
u8 message[BlockSize];
ON_SCOPE_EXIT { ClearMemory(message, sizeof(message)); };
if (!this->calculator.ExpMod(message, src, src_size, work_buf, work_buf_size)) {
if (!m_calculator.ExpMod(message, src, src_size, work_buf, work_buf_size)) {
return false;
}
if (!this->set_label_digest) {
this->hash.GetHash(this->label_digest, sizeof(this->label_digest));
this->set_label_digest = true;
if (!m_set_label_digest) {
m_hash.GetHash(m_label_digest, sizeof(m_label_digest));
m_set_label_digest = true;
}
return impl.Decode(dst, dst_size, this->label_digest, sizeof(this->label_digest), message, sizeof(message));
return impl.Decode(dst, dst_size, m_label_digest, sizeof(m_label_digest), message, sizeof(message));
}
static size_t Decrypt(void *dst, size_t dst_size, const void *mod, size_t mod_size, const void *exp, size_t exp_size, const void *msg, size_t msg_size, const void *lab, size_t lab_size) {

View file

@ -39,23 +39,23 @@ namespace ams::crypto {
Done,
};
private:
RsaCalculator<ModulusSize, MaximumExponentSize> calculator;
Hash hash;
bool set_label_digest;
u8 label_digest[HashSize];
State state;
RsaCalculator<ModulusSize, MaximumExponentSize> m_calculator;
Hash m_hash;
bool m_set_label_digest;
u8 m_label_digest[HashSize];
State m_state;
public:
RsaOaepEncryptor() : set_label_digest(false), state(State::None) { std::memset(this->label_digest, 0, sizeof(this->label_digest)); }
RsaOaepEncryptor() : m_set_label_digest(false), m_state(State::None) { std::memset(m_label_digest, 0, sizeof(m_label_digest)); }
~RsaOaepEncryptor() {
ClearMemory(this->label_digest, sizeof(this->label_digest));
ClearMemory(m_label_digest, sizeof(m_label_digest));
}
bool Initialize(const void *mod, size_t mod_size, const void *exp, size_t exp_size) {
this->hash.Initialize();
this->set_label_digest = false;
if (this->calculator.Initialize(mod, mod_size, exp, exp_size)) {
this->state = State::Initialized;
m_hash.Initialize();
m_set_label_digest = false;
if (m_calculator.Initialize(mod, mod_size, exp, exp_size)) {
m_state = State::Initialized;
return true;
} else {
return false;
@ -63,54 +63,54 @@ namespace ams::crypto {
}
void UpdateLabel(const void *data, size_t size) {
AMS_ASSERT(this->state == State::Initialized);
AMS_ASSERT(m_state == State::Initialized);
this->hash.Update(data, size);
m_hash.Update(data, size);
}
void SetLabelDigest(const void *digest, size_t digest_size) {
AMS_ASSERT(this->state == State::Initialized);
AMS_ABORT_UNLESS(digest_size == sizeof(this->label_digest));
AMS_ASSERT(m_state == State::Initialized);
AMS_ABORT_UNLESS(digest_size == sizeof(m_label_digest));
std::memcpy(this->label_digest, digest, digest_size);
this->set_label_digest = true;
std::memcpy(m_label_digest, digest, digest_size);
m_set_label_digest = true;
}
bool Encrypt(void *dst, size_t dst_size, const void *src, size_t src_size, const void *salt, size_t salt_size) {
AMS_ASSERT(this->state == State::Initialized);
AMS_ASSERT(m_state == State::Initialized);
impl::RsaOaepImpl<Hash> impl;
if (!this->set_label_digest) {
this->hash.GetHash(this->label_digest, sizeof(this->label_digest));
if (!m_set_label_digest) {
m_hash.GetHash(m_label_digest, sizeof(m_label_digest));
}
impl.Encode(dst, dst_size, this->label_digest, sizeof(this->label_digest), src, src_size, salt, salt_size);
impl.Encode(dst, dst_size, m_label_digest, sizeof(m_label_digest), src, src_size, salt, salt_size);
if (!this->calculator.ExpMod(dst, dst, dst_size)) {
if (!m_calculator.ExpMod(dst, dst, dst_size)) {
std::memset(dst, 0, dst_size);
return false;
}
this->state = State::Done;
m_state = State::Done;
return true;
}
bool Encrypt(void *dst, size_t dst_size, const void *src, size_t src_size, const void *salt, size_t salt_size, void *work, size_t work_size) {
AMS_ASSERT(this->state == State::Initialized);
AMS_ASSERT(m_state == State::Initialized);
impl::RsaOaepImpl<Hash> impl;
if (!this->set_label_digest) {
this->hash.GetHash(this->label_digest, sizeof(this->label_digest));
if (!m_set_label_digest) {
m_hash.GetHash(m_label_digest, sizeof(m_label_digest));
}
impl.Encode(dst, dst_size, this->label_digest, sizeof(this->label_digest), src, src_size, salt, salt_size);
impl.Encode(dst, dst_size, m_label_digest, sizeof(m_label_digest), src, src_size, salt, salt_size);
if (!this->calculator.ExpMod(dst, dst, dst_size, work, work_size)) {
if (!m_calculator.ExpMod(dst, dst, dst_size, work, work_size)) {
std::memset(dst, 0, dst_size);
return false;
}
this->state = State::Done;
m_state = State::Done;
return true;
}

View file

@ -41,17 +41,17 @@ namespace ams::crypto {
Done,
};
private:
RsaCalculator<ModulusSize, MaximumExponentSize> calculator;
Hash hash;
State state;
RsaCalculator<ModulusSize, MaximumExponentSize> m_calculator;
Hash m_hash;
State m_state;
public:
RsaPssVerifier() : state(State::None) { /* ... */ }
RsaPssVerifier() : m_state(State::None) { /* ... */ }
~RsaPssVerifier() { }
bool Initialize(const void *mod, size_t mod_size, const void *exp, size_t exp_size) {
this->hash.Initialize();
if (this->calculator.Initialize(mod, mod_size, exp, exp_size)) {
this->state = State::Initialized;
m_hash.Initialize();
if (m_calculator.Initialize(mod, mod_size, exp, exp_size)) {
m_state = State::Initialized;
return true;
} else {
return false;
@ -59,62 +59,62 @@ namespace ams::crypto {
}
void Update(const void *data, size_t size) {
return this->hash.Update(data, size);
return m_hash.Update(data, size);
}
bool Verify(const void *signature, size_t size) {
AMS_ASSERT(this->state == State::Initialized);
AMS_ASSERT(m_state == State::Initialized);
AMS_ASSERT(size == SignatureSize);
AMS_UNUSED(size);
ON_SCOPE_EXIT { this->state = State::Done; };
ON_SCOPE_EXIT { m_state = State::Done; };
impl::RsaPssImpl<Hash> impl;
u8 message[SignatureSize];
ON_SCOPE_EXIT { ClearMemory(message, sizeof(message)); };
if (!this->calculator.ExpMod(message, signature, SignatureSize)) {
if (!m_calculator.ExpMod(message, signature, SignatureSize)) {
return false;
}
u8 calc_hash[Hash::HashSize];
this->hash.GetHash(calc_hash, sizeof(calc_hash));
m_hash.GetHash(calc_hash, sizeof(calc_hash));
ON_SCOPE_EXIT { ClearMemory(calc_hash, sizeof(calc_hash)); };
return impl.Verify(message, sizeof(message), calc_hash, sizeof(calc_hash));
}
bool Verify(const void *signature, size_t size, void *work_buf, size_t work_buf_size) {
AMS_ASSERT(this->state == State::Initialized);
AMS_ASSERT(m_state == State::Initialized);
AMS_ASSERT(size == SignatureSize);
AMS_UNUSED(size);
ON_SCOPE_EXIT { this->state = State::Done; };
ON_SCOPE_EXIT { m_state = State::Done; };
impl::RsaPssImpl<Hash> impl;
u8 message[SignatureSize];
ON_SCOPE_EXIT { ClearMemory(message, sizeof(message)); };
if (!this->calculator.ExpMod(message, signature, SignatureSize, work_buf, work_buf_size)) {
if (!m_calculator.ExpMod(message, signature, SignatureSize, work_buf, work_buf_size)) {
return false;
}
u8 calc_hash[Hash::HashSize];
this->hash.GetHash(calc_hash, sizeof(calc_hash));
m_hash.GetHash(calc_hash, sizeof(calc_hash));
ON_SCOPE_EXIT { ClearMemory(calc_hash, sizeof(calc_hash)); };
return impl.Verify(message, sizeof(message), calc_hash, sizeof(calc_hash));
}
bool VerifyWithHash(const void *signature, size_t size, const void *hash, size_t hash_size) {
AMS_ASSERT(this->state == State::Initialized);
AMS_ASSERT(m_state == State::Initialized);
AMS_ASSERT(size == SignatureSize);
AMS_UNUSED(size);
ON_SCOPE_EXIT { this->state = State::Done; };
ON_SCOPE_EXIT { m_state = State::Done; };
impl::RsaPssImpl<Hash> impl;
u8 message[SignatureSize];
ON_SCOPE_EXIT { ClearMemory(message, sizeof(message)); };
if (!this->calculator.ExpMod(message, signature, SignatureSize)) {
if (!m_calculator.ExpMod(message, signature, SignatureSize)) {
return false;
}
@ -122,16 +122,16 @@ namespace ams::crypto {
}
bool VerifyWithHash(const void *signature, size_t size, const void *hash, size_t hash_size, void *work_buf, size_t work_buf_size) {
AMS_ASSERT(this->state == State::Initialized);
AMS_ASSERT(m_state == State::Initialized);
AMS_ASSERT(size == SignatureSize);
AMS_UNUSED(size);
ON_SCOPE_EXIT { this->state = State::Done; };
ON_SCOPE_EXIT { m_state = State::Done; };
impl::RsaPssImpl<Hash> impl;
u8 message[SignatureSize];
ON_SCOPE_EXIT { ClearMemory(message, sizeof(message)); };
if (!this->calculator.ExpMod(message, signature, SignatureSize, work_buf, work_buf_size)) {
if (!m_calculator.ExpMod(message, signature, SignatureSize, work_buf, work_buf_size)) {
return false;
}

View file

@ -41,20 +41,20 @@ namespace ams::crypto {
};
static constexpr size_t Asn1IdentifierSize = util::size(Asn1Identifier);
private:
Impl impl;
Impl m_impl;
public:
Sha1Generator() { /* ... */ }
void Initialize() {
this->impl.Initialize();
m_impl.Initialize();
}
void Update(const void *data, size_t size) {
this->impl.Update(data, size);
m_impl.Update(data, size);
}
void GetHash(void *dst, size_t size) {
this->impl.GetHash(dst, size);
m_impl.GetHash(dst, size);
}
};

View file

@ -46,36 +46,36 @@ namespace ams::crypto {
};
static constexpr size_t Asn1IdentifierSize = util::size(Asn1Identifier);
private:
Impl impl;
Impl m_impl;
public:
Sha256Generator() { /* ... */ }
void Initialize() {
this->impl.Initialize();
m_impl.Initialize();
}
void Update(const void *data, size_t size) {
this->impl.Update(data, size);
m_impl.Update(data, size);
}
void GetHash(void *dst, size_t size) {
this->impl.GetHash(dst, size);
m_impl.GetHash(dst, size);
}
void InitializeWithContext(const Sha256Context *context) {
this->impl.InitializeWithContext(context);
m_impl.InitializeWithContext(context);
}
size_t GetContext(Sha256Context *context) const {
return this->impl.GetContext(context);
return m_impl.GetContext(context);
}
size_t GetBufferedDataSize() const {
return this->impl.GetBufferedDataSize();
return m_impl.GetBufferedDataSize();
}
void GetBufferedData(void *dst, size_t dst_size) const {
return this->impl.GetBufferedData(dst, dst_size);
return m_impl.GetBufferedData(dst, dst_size);
}
};

View file

@ -34,21 +34,21 @@ namespace ams::crypto {
static constexpr size_t BlockSize = Impl::BlockSize;
static constexpr size_t IvSize = Impl::IvSize;
private:
Impl impl;
Impl m_impl;
public:
XtsDecryptor() { /* ... */ }
template<typename BlockCipher2>
void Initialize(const BlockCipher *cipher1, const BlockCipher2 *cipher2, const void *iv, size_t iv_size) {
this->impl.InitializeDecryption(cipher1, cipher2, iv, iv_size);
m_impl.InitializeDecryption(cipher1, cipher2, iv, iv_size);
}
size_t Update(void *dst, size_t dst_size, const void *src, size_t src_size) {
return this->impl.template Update<BlockCipher>(dst, dst_size, src, src_size);
return m_impl.template Update<BlockCipher>(dst, dst_size, src, src_size);
}
size_t Finalize(void *dst, size_t dst_size) {
return this->impl.FinalizeDecryption(dst, dst_size);
return m_impl.FinalizeDecryption(dst, dst_size);
}
};

View file

@ -34,21 +34,21 @@ namespace ams::crypto {
static constexpr size_t BlockSize = Impl::BlockSize;
static constexpr size_t IvSize = Impl::IvSize;
private:
Impl impl;
Impl m_impl;
public:
XtsEncryptor() { /* ... */ }
template<typename BlockCipher2>
void Initialize(const BlockCipher *cipher1, const BlockCipher2 *cipher2, const void *iv, size_t iv_size) {
this->impl.InitializeEncryption(cipher1, cipher2, iv, iv_size);
m_impl.InitializeEncryption(cipher1, cipher2, iv, iv_size);
}
size_t Update(void *dst, size_t dst_size, const void *src, size_t src_size) {
return this->impl.template Update<BlockCipher>(dst, dst_size, src, src_size);
return m_impl.template Update<BlockCipher>(dst, dst_size, src, src_size);
}
size_t Finalize(void *dst, size_t dst_size) {
return this->impl.FinalizeEncryption(dst, dst_size);
return m_impl.FinalizeEncryption(dst, dst_size);
}
};

View file

@ -31,10 +31,10 @@ namespace ams::crypto::impl {
static constexpr size_t RoundKeySize = BlockSize * (RoundCount + 1);
private:
#ifdef ATMOSPHERE_IS_EXOSPHERE
int slot;
int m_slot;
#endif
#ifdef ATMOSPHERE_IS_STRATOSPHERE
u32 round_keys[RoundKeySize / sizeof(u32)];
u32 m_round_keys[RoundKeySize / sizeof(u32)];
#endif
public:
~AesImpl();
@ -45,7 +45,7 @@ namespace ams::crypto::impl {
#ifdef ATMOSPHERE_IS_STRATOSPHERE
const u8 *GetRoundKey() const {
return reinterpret_cast<const u8 *>(this->round_keys);
return reinterpret_cast<const u8 *>(m_round_keys);
}
#endif
};

View file

@ -46,43 +46,43 @@ namespace ams::crypto::impl {
private:
friend class WordAllocator;
private:
WordAllocator *allocator;
Word *buffer;
size_t count;
WordAllocator *m_allocator;
Word *m_buffer;
size_t m_count;
private:
constexpr ALWAYS_INLINE Allocation(WordAllocator *a, Word *w, size_t c) : allocator(a), buffer(w), count(c) { /* ... */ }
constexpr ALWAYS_INLINE Allocation(WordAllocator *a, Word *w, size_t c) : m_allocator(a), m_buffer(w), m_count(c) { /* ... */ }
public:
ALWAYS_INLINE ~Allocation() { if (allocator) { allocator->Free(this->buffer, this->count); } }
ALWAYS_INLINE ~Allocation() { if (m_allocator) { m_allocator->Free(m_buffer, m_count); } }
constexpr ALWAYS_INLINE Word *GetBuffer() const { return this->buffer; }
constexpr ALWAYS_INLINE size_t GetCount() const { return this->count; }
constexpr ALWAYS_INLINE bool IsValid() const { return this->buffer != nullptr; }
constexpr ALWAYS_INLINE Word *GetBuffer() const { return m_buffer; }
constexpr ALWAYS_INLINE size_t GetCount() const { return m_count; }
constexpr ALWAYS_INLINE bool IsValid() const { return m_buffer != nullptr; }
};
friend class Allocation;
private:
Word *buffer;
size_t count;
size_t max_count;
size_t min_count;
Word *m_buffer;
size_t m_count;
size_t m_max_count;
size_t m_min_count;
private:
ALWAYS_INLINE void Free(void *words, size_t num) {
this->buffer -= num;
this->count += num;
m_buffer -= num;
m_count += num;
AMS_ASSERT(words == this->buffer);
AMS_ASSERT(words == m_buffer);
AMS_UNUSED(words);
}
public:
constexpr ALWAYS_INLINE WordAllocator(Word *buf, size_t c) : buffer(buf), count(c), max_count(c), min_count(c) { /* ... */ }
constexpr ALWAYS_INLINE WordAllocator(Word *buf, size_t c) : m_buffer(buf), m_count(c), m_max_count(c), m_min_count(c) { /* ... */ }
ALWAYS_INLINE Allocation Allocate(size_t num) {
if (num <= this->count) {
Word *allocated = this->buffer;
if (num <= m_count) {
Word *allocated = m_buffer;
this->buffer += num;
this->count -= num;
this->min_count = std::min(this->count, this->min_count);
m_buffer += num;
m_count -= num;
m_min_count = std::min(m_count, m_min_count);
return Allocation(this, allocated, num);
} else {
@ -91,23 +91,23 @@ namespace ams::crypto::impl {
}
constexpr ALWAYS_INLINE size_t GetMaxUsedSize() const {
return (this->max_count - this->min_count) * sizeof(Word);
return (m_max_count - m_min_count) * sizeof(Word);
}
};
private:
Word *words;
size_t num_words;
size_t max_words;
Word *m_words;
size_t m_num_words;
size_t m_max_words;
private:
static void ImportImpl(Word *out, size_t out_size, const u8 *src, size_t src_size);
static void ExportImpl(u8 *out, size_t out_size, const Word *src, size_t src_size);
public:
constexpr BigNum() : words(), num_words(), max_words() { /* ... */ }
constexpr BigNum() : m_words(), m_num_words(), m_max_words() { /* ... */ }
~BigNum() { /* ... */ }
constexpr void ReserveStatic(Word *buf, size_t capacity) {
this->words = buf;
this->max_words = capacity;
m_words = buf;
m_max_words = capacity;
}
bool Import(const void *src, size_t src_size);
@ -116,7 +116,7 @@ namespace ams::crypto::impl {
size_t GetSize() const;
bool IsZero() const {
return this->num_words == 0;
return m_num_words == 0;
}
bool ExpMod(void *dst, const void *src, size_t size, const BigNum &exp, u32 *work_buf, size_t work_buf_size) const;
@ -154,10 +154,10 @@ namespace ams::crypto::impl {
static constexpr size_t NumWords = util::AlignUp(NumBits, BitsPerWord) / BitsPerWord;
static constexpr size_t NumBytes = NumWords * sizeof(Word);
private:
Word word_buf[NumWords];
Word m_word_buf[NumWords];
public:
constexpr StaticBigNum() : word_buf() {
this->ReserveStatic(word_buf, NumWords);
constexpr StaticBigNum() : m_word_buf() {
this->ReserveStatic(m_word_buf, NumWords);
}
};

View file

@ -37,13 +37,13 @@ namespace ams::crypto::impl {
State_Initialized,
};
private:
const BlockCipher *block_cipher;
u8 counter[IvSize];
u8 encrypted_counter[BlockSize];
size_t buffer_offset;
State state;
const BlockCipher *m_block_cipher;
u8 m_counter[IvSize];
u8 m_encrypted_counter[BlockSize];
size_t m_buffer_offset;
State m_state;
public:
CtrModeImpl() : state(State_None) { /* ... */ }
CtrModeImpl() : m_state(State_None) { /* ... */ }
~CtrModeImpl() {
ClearMemory(this, sizeof(*this));
@ -57,8 +57,8 @@ namespace ams::crypto::impl {
AMS_ASSERT(iv_size == IvSize);
AMS_ASSERT(offset >= 0);
this->block_cipher = block_cipher;
this->state = State_Initialized;
m_block_cipher = block_cipher;
m_state = State_Initialized;
this->SwitchMessage(iv, iv_size);
@ -69,32 +69,32 @@ namespace ams::crypto::impl {
}
if (size_t remaining = static_cast<size_t>(offset % BlockSize); remaining != 0) {
this->block_cipher->EncryptBlock(this->encrypted_counter, sizeof(this->encrypted_counter), this->counter, sizeof(this->counter));
m_block_cipher->EncryptBlock(m_encrypted_counter, sizeof(m_encrypted_counter), m_counter, sizeof(m_counter));
this->IncrementCounter();
this->buffer_offset = remaining;
m_buffer_offset = remaining;
}
}
}
void SwitchMessage(const void *iv, size_t iv_size) {
AMS_ASSERT(this->state == State_Initialized);
AMS_ASSERT(m_state == State_Initialized);
AMS_ASSERT(iv_size == IvSize);
std::memcpy(this->counter, iv, iv_size);
this->buffer_offset = 0;
std::memcpy(m_counter, iv, iv_size);
m_buffer_offset = 0;
}
void IncrementCounter() {
for (s32 i = IvSize - 1; i >= 0; --i) {
if (++this->counter[i] != 0) {
if (++m_counter[i] != 0) {
break;
}
}
}
size_t Update(void *_dst, size_t dst_size, const void *_src, size_t src_size) {
AMS_ASSERT(this->state == State_Initialized);
AMS_ASSERT(m_state == State_Initialized);
AMS_ASSERT(dst_size >= src_size);
AMS_UNUSED(dst_size);
@ -102,10 +102,10 @@ namespace ams::crypto::impl {
const u8 *src = static_cast<const u8 *>(_src);
size_t remaining = src_size;
if (this->buffer_offset > 0) {
const size_t xor_size = std::min(BlockSize - this->buffer_offset, remaining);
if (m_buffer_offset > 0) {
const size_t xor_size = std::min(BlockSize - m_buffer_offset, remaining);
const u8 *ctr = this->encrypted_counter + this->buffer_offset;
const u8 *ctr = m_encrypted_counter + m_buffer_offset;
for (size_t i = 0; i < xor_size; i++) {
dst[i] = src[i] ^ ctr[i];
}
@ -113,10 +113,10 @@ namespace ams::crypto::impl {
src += xor_size;
dst += xor_size;
remaining -= xor_size;
this->buffer_offset += xor_size;
m_buffer_offset += xor_size;
if (this->buffer_offset == BlockSize) {
this->buffer_offset = 0;
if (m_buffer_offset == BlockSize) {
m_buffer_offset = 0;
}
}
@ -133,7 +133,7 @@ namespace ams::crypto::impl {
if (remaining > 0) {
this->ProcessBlock(dst, src, remaining);
this->buffer_offset = remaining;
m_buffer_offset = remaining;
}
return src_size;
@ -146,18 +146,18 @@ namespace ams::crypto::impl {
u16 acc = 0;
const u8 *block = reinterpret_cast<const u8 *>(_block);
for (s32 i = IvSize - 1; i >= 0; --i) {
acc += (this->counter[i] + block[i]);
this->counter[i] = acc & 0xFF;
acc += (m_counter[i] + block[i]);
m_counter[i] = acc & 0xFF;
acc >>= 8;
}
}
void ProcessBlock(u8 *dst, const u8 *src, size_t src_size) {
this->block_cipher->EncryptBlock(this->encrypted_counter, BlockSize, this->counter, IvSize);
m_block_cipher->EncryptBlock(m_encrypted_counter, BlockSize, m_counter, IvSize);
this->IncrementCounter();
for (size_t i = 0; i < src_size; i++) {
dst[i] = src[i] ^ this->encrypted_counter[i];
dst[i] = src[i] ^ m_encrypted_counter[i];
}
}

View file

@ -63,23 +63,23 @@ namespace ams::crypto::impl {
using CipherFunction = void (*)(void *dst_block, const void *src_block, const void *ctx);
private:
State state;
const BlockCipher *block_cipher;
CipherFunction cipher_func;
u8 pad[sizeof(u64)];
Block block_x;
Block block_y;
Block block_ek;
Block block_ek0;
Block block_tmp;
size_t aad_size;
size_t msg_size;
u32 aad_remaining;
u32 msg_remaining;
u32 counter;
Block h_mult_blocks[16];
State m_state;
const BlockCipher *m_block_cipher;
CipherFunction m_cipher_func;
u8 m_pad[sizeof(u64)];
Block m_block_x;
Block m_block_y;
Block m_block_ek;
Block m_block_ek0;
Block m_block_tmp;
size_t m_aad_size;
size_t m_msg_size;
u32 m_aad_remaining;
u32 m_msg_remaining;
u32 m_counter;
Block m_h_mult_blocks[16];
public:
GcmModeImpl() : state(State_None) { /* ... */ }
GcmModeImpl() : m_state(State_None) { /* ... */ }
~GcmModeImpl() {
ClearMemory(this, sizeof(*this));

View file

@ -43,17 +43,17 @@ namespace ams::crypto::impl {
State_Done = 2,
};
private:
Hash hash_function;
u32 key[BlockSize / sizeof(u32)];
u32 mac[MacSize / sizeof(u32)];
State state;
Hash m_hash_function;
u32 m_key[BlockSize / sizeof(u32)];
u32 m_mac[MacSize / sizeof(u32)];
State m_state;
public:
HmacImpl() : state(State_None) { /* ... */ }
HmacImpl() : m_state(State_None) { /* ... */ }
~HmacImpl() {
static_assert(offsetof(HmacImpl, hash_function) == 0);
static_assert(offsetof(HmacImpl, m_hash_function) == 0);
/* Clear everything except for the hash function. */
ClearMemory(reinterpret_cast<u8 *>(this) + sizeof(this->hash_function), sizeof(*this) - sizeof(this->hash_function));
ClearMemory(reinterpret_cast<u8 *>(this) + sizeof(m_hash_function), sizeof(*this) - sizeof(m_hash_function));
}
void Initialize(const void *key, size_t key_size);
@ -64,64 +64,64 @@ namespace ams::crypto::impl {
template<typename Hash>
inline void HmacImpl<Hash>::Initialize(const void *key, size_t key_size) {
/* Clear the key storage. */
std::memset(this->key, 0, sizeof(this->key));
std::memset(m_key, 0, sizeof(m_key));
/* Set the key storage. */
if (key_size > BlockSize) {
this->hash_function.Initialize();
this->hash_function.Update(key, key_size);
this->hash_function.GetHash(this->key, this->hash_function.HashSize);
m_hash_function.Initialize();
m_hash_function.Update(key, key_size);
m_hash_function.GetHash(m_key, m_hash_function.HashSize);
} else {
std::memcpy(this->key, key, key_size);
std::memcpy(m_key, key, key_size);
}
/* Xor the key with the ipad. */
for (size_t i = 0; i < util::size(this->key); i++) {
this->key[i] ^= IpadMagic;
for (size_t i = 0; i < util::size(m_key); i++) {
m_key[i] ^= IpadMagic;
}
/* Update the hash function with the xor'd key. */
this->hash_function.Initialize();
this->hash_function.Update(this->key, BlockSize);
m_hash_function.Initialize();
m_hash_function.Update(m_key, BlockSize);
/* Mark initialized. */
this->state = State_Initialized;
m_state = State_Initialized;
}
template<typename Hash>
inline void HmacImpl<Hash>::Update(const void *data, size_t data_size) {
AMS_ASSERT(this->state == State_Initialized);
AMS_ASSERT(m_state == State_Initialized);
this->hash_function.Update(data, data_size);
m_hash_function.Update(data, data_size);
}
template<typename Hash>
inline void HmacImpl<Hash>::GetMac(void *dst, size_t dst_size) {
AMS_ASSERT(this->state == State_Initialized || this->state == State_Done);
AMS_ASSERT(m_state == State_Initialized || m_state == State_Done);
AMS_ASSERT(dst_size >= MacSize);
AMS_UNUSED(dst_size);
/* If we're not already finalized, get the final mac. */
if (this->state == State_Initialized) {
if (m_state == State_Initialized) {
/* Get the hash of ((key ^ ipad) || data). */
this->hash_function.GetHash(this->mac, MacSize);
m_hash_function.GetHash(m_mac, MacSize);
/* Xor the key with the opad. */
for (size_t i = 0; i < util::size(this->key); i++) {
this->key[i] ^= IpadMagicXorOpadMagic;
for (size_t i = 0; i < util::size(m_key); i++) {
m_key[i] ^= IpadMagicXorOpadMagic;
}
/* Calculate the final mac as hash of ((key ^ opad) || hash((key ^ ipad) || data)) */
this->hash_function.Initialize();
this->hash_function.Update(this->key, BlockSize);
this->hash_function.Update(this->mac, MacSize);
this->hash_function.GetHash(this->mac, MacSize);
m_hash_function.Initialize();
m_hash_function.Update(m_key, BlockSize);
m_hash_function.Update(m_mac, MacSize);
m_hash_function.GetHash(m_mac, MacSize);
/* Set our state as done. */
this->state = State_Done;
m_state = State_Done;
}
std::memcpy(dst, this->mac, MacSize);
std::memcpy(dst, m_mac, MacSize);
}
}

View file

@ -37,12 +37,12 @@ namespace ams::crypto::impl {
bool finalized;
};
private:
State state;
State m_state;
public:
Sha1Impl() { /* ... */ }
~Sha1Impl() {
static_assert(std::is_trivially_destructible<State>::value);
ClearMemory(std::addressof(this->state), sizeof(this->state));
ClearMemory(std::addressof(m_state), sizeof(m_state));
}
void Initialize();

View file

@ -42,12 +42,12 @@ namespace ams::crypto::impl {
bool finalized;
};
private:
State state;
State m_state;
public:
Sha256Impl() { /* ... */ }
~Sha256Impl() {
static_assert(std::is_trivially_destructible<State>::value);
ClearMemory(std::addressof(this->state), sizeof(this->state));
ClearMemory(std::addressof(m_state), sizeof(m_state));
}
void Initialize();
@ -57,13 +57,13 @@ namespace ams::crypto::impl {
void InitializeWithContext(const Sha256Context *context);
size_t GetContext(Sha256Context *context) const;
size_t GetBufferedDataSize() const { return this->state.num_buffered; }
size_t GetBufferedDataSize() const { return m_state.num_buffered; }
void GetBufferedData(void *dst, size_t dst_size) const {
AMS_ASSERT(dst_size >= this->GetBufferedDataSize());
AMS_UNUSED(dst_size);
std::memcpy(dst, this->state.buffer, this->GetBufferedDataSize());
std::memcpy(dst, m_state.buffer, this->GetBufferedDataSize());
}
};

View file

@ -38,15 +38,15 @@ namespace ams::crypto::impl {
State_Done
};
private:
u8 buffer[BlockSize];
u8 tweak[BlockSize];
u8 last_block[BlockSize];
size_t num_buffered;
const void *cipher_ctx;
void (*cipher_func)(void *dst_block, const void *src_block, const void *cipher_ctx);
State state;
u8 m_buffer[BlockSize];
u8 m_tweak[BlockSize];
u8 m_last_block[BlockSize];
size_t m_num_buffered;
const void *m_cipher_ctx;
void (*m_cipher_func)(void *dst_block, const void *src_block, const void *cipher_ctx);
State m_state;
public:
XtsModeImpl() : num_buffered(0), state(State_None) { /* ... */ }
XtsModeImpl() : m_num_buffered(0), m_state(State_None) { /* ... */ }
~XtsModeImpl() {
ClearMemory(this, sizeof(*this));
@ -67,10 +67,10 @@ namespace ams::crypto::impl {
AMS_ASSERT(tweak_size == IvSize);
AMS_UNUSED(tweak_size);
cipher->EncryptBlock(this->tweak, IvSize, tweak, IvSize);
cipher->EncryptBlock(m_tweak, IvSize, tweak, IvSize);
this->num_buffered = 0;
this->state = State_Initialized;
m_num_buffered = 0;
m_state = State_Initialized;
}
void ProcessBlock(u8 *dst, const u8 *src);
@ -80,8 +80,8 @@ namespace ams::crypto::impl {
static_assert(BlockCipher1::BlockSize == BlockSize);
static_assert(BlockCipher2::BlockSize == BlockSize);
this->cipher_ctx = cipher1;
this->cipher_func = EncryptBlockCallback<BlockCipher1>;
m_cipher_ctx = cipher1;
m_cipher_func = EncryptBlockCallback<BlockCipher1>;
this->Initialize(cipher2, tweak, tweak_size);
}
@ -91,8 +91,8 @@ namespace ams::crypto::impl {
static_assert(BlockCipher1::BlockSize == BlockSize);
static_assert(BlockCipher2::BlockSize == BlockSize);
this->cipher_ctx = cipher1;
this->cipher_func = DecryptBlockCallback<BlockCipher1>;
m_cipher_ctx = cipher1;
m_cipher_func = DecryptBlockCallback<BlockCipher1>;
this->Initialize(cipher2, tweak, tweak_size);
}
@ -108,7 +108,7 @@ namespace ams::crypto::impl {
}
size_t GetBufferedDataSize() const {
return this->num_buffered;
return m_num_buffered;
}
constexpr size_t GetBlockSize() const {

View file

@ -29,11 +29,11 @@ namespace ams {
/* TODO: Better understand device code components. */
class DeviceCode {
private:
impl::DeviceCodeType inner_value;
impl::DeviceCodeType m_inner_value;
public:
constexpr DeviceCode(impl::DeviceCodeType v) : inner_value(v) { /* ... */ }
constexpr DeviceCode(impl::DeviceCodeType v) : m_inner_value(v) { /* ... */ }
constexpr impl::DeviceCodeType GetInternalValue() const { return this->inner_value; }
constexpr impl::DeviceCodeType GetInternalValue() const { return m_inner_value; }
constexpr bool operator==(const DeviceCode &rhs) const {
return this->GetInternalValue() == rhs.GetInternalValue();

View file

@ -56,31 +56,31 @@ namespace ams::freebsd {
template<typename T>
class RBEntry {
private:
T *rbe_left = nullptr;
T *rbe_right = nullptr;
T *rbe_parent = nullptr;
RBColor rbe_color = RBColor::RB_BLACK;
T *m_rbe_left = nullptr;
T *m_rbe_right = nullptr;
T *m_rbe_parent = nullptr;
RBColor m_rbe_color = RBColor::RB_BLACK;
public:
[[nodiscard]] constexpr ALWAYS_INLINE T *Left() { return this->rbe_left; }
[[nodiscard]] constexpr ALWAYS_INLINE const T *Left() const { return this->rbe_left; }
[[nodiscard]] constexpr ALWAYS_INLINE T *Left() { return m_rbe_left; }
[[nodiscard]] constexpr ALWAYS_INLINE const T *Left() const { return m_rbe_left; }
constexpr ALWAYS_INLINE void SetLeft(T *e) { this->rbe_left = e; }
constexpr ALWAYS_INLINE void SetLeft(T *e) { m_rbe_left = e; }
[[nodiscard]] constexpr ALWAYS_INLINE T *Right() { return this->rbe_right; }
[[nodiscard]] constexpr ALWAYS_INLINE const T *Right() const { return this->rbe_right; }
[[nodiscard]] constexpr ALWAYS_INLINE T *Right() { return m_rbe_right; }
[[nodiscard]] constexpr ALWAYS_INLINE const T *Right() const { return m_rbe_right; }
constexpr ALWAYS_INLINE void SetRight(T *e) { this->rbe_right = e; }
constexpr ALWAYS_INLINE void SetRight(T *e) { m_rbe_right = e; }
[[nodiscard]] constexpr ALWAYS_INLINE T *Parent() { return this->rbe_parent; }
[[nodiscard]] constexpr ALWAYS_INLINE const T *Parent() const { return this->rbe_parent; }
[[nodiscard]] constexpr ALWAYS_INLINE T *Parent() { return m_rbe_parent; }
[[nodiscard]] constexpr ALWAYS_INLINE const T *Parent() const { return m_rbe_parent; }
constexpr ALWAYS_INLINE void SetParent(T *e) { this->rbe_parent = e; }
constexpr ALWAYS_INLINE void SetParent(T *e) { m_rbe_parent = e; }
[[nodiscard]] constexpr ALWAYS_INLINE bool IsBlack() const { return this->rbe_color == RBColor::RB_BLACK; }
[[nodiscard]] constexpr ALWAYS_INLINE bool IsRed() const { return this->rbe_color == RBColor::RB_RED; }
[[nodiscard]] constexpr ALWAYS_INLINE RBColor Color() const { return this->rbe_color; }
[[nodiscard]] constexpr ALWAYS_INLINE bool IsBlack() const { return m_rbe_color == RBColor::RB_BLACK; }
[[nodiscard]] constexpr ALWAYS_INLINE bool IsRed() const { return m_rbe_color == RBColor::RB_RED; }
[[nodiscard]] constexpr ALWAYS_INLINE RBColor Color() const { return m_rbe_color; }
constexpr ALWAYS_INLINE void SetColor(RBColor c) { this->rbe_color = c; }
constexpr ALWAYS_INLINE void SetColor(RBColor c) { m_rbe_color = c; }
};
template<typename T> struct CheckRBEntry { static constexpr bool value = false; };
@ -98,11 +98,11 @@ namespace ams::freebsd {
template<typename T> requires HasRBEntry<T>
class RBHead {
private:
T *rbh_root = nullptr;
T *m_rbh_root = nullptr;
public:
[[nodiscard]] constexpr ALWAYS_INLINE T *Root() { return this->rbh_root; }
[[nodiscard]] constexpr ALWAYS_INLINE const T *Root() const { return this->rbh_root; }
constexpr ALWAYS_INLINE void SetRoot(T *root) { this->rbh_root = root; }
[[nodiscard]] constexpr ALWAYS_INLINE T *Root() { return m_rbh_root; }
[[nodiscard]] constexpr ALWAYS_INLINE const T *Root() const { return m_rbh_root; }
constexpr ALWAYS_INLINE void SetRoot(T *root) { m_rbh_root = root; }
[[nodiscard]] constexpr ALWAYS_INLINE bool IsEmpty() const { return this->Root() == nullptr; }
};

View file

@ -24,7 +24,7 @@ namespace ams {
struct TimeSpanType {
public:
s64 ns;
s64 _ns;
public:
static constexpr ALWAYS_INLINE TimeSpanType FromNanoSeconds(s64 ns) { return {ns}; }
static constexpr ALWAYS_INLINE TimeSpanType FromMicroSeconds(s64 ms) { return FromNanoSeconds(ms * INT64_C(1000)); }
@ -34,7 +34,7 @@ namespace ams {
static constexpr ALWAYS_INLINE TimeSpanType FromHours(s64 h) { return FromMinutes(h * INT64_C(60)); }
static constexpr ALWAYS_INLINE TimeSpanType FromDays(s64 d) { return FromHours(d * INT64_C(24)); }
constexpr ALWAYS_INLINE s64 GetNanoSeconds() const { return this->ns; }
constexpr ALWAYS_INLINE s64 GetNanoSeconds() const { return _ns; }
constexpr ALWAYS_INLINE s64 GetMicroSeconds() const { return this->GetNanoSeconds() / (INT64_C(1000)); }
constexpr ALWAYS_INLINE s64 GetMilliSeconds() const { return this->GetNanoSeconds() / (INT64_C(1000) * INT64_C(1000)); }
constexpr ALWAYS_INLINE s64 GetSeconds() const { return this->GetNanoSeconds() / (INT64_C(1000) * INT64_C(1000) * INT64_C(1000)); }
@ -42,15 +42,15 @@ namespace ams {
constexpr ALWAYS_INLINE s64 GetHours() const { return this->GetNanoSeconds() / (INT64_C(1000) * INT64_C(1000) * INT64_C(1000) * INT64_C( 60) * INT64_C( 60)); }
constexpr ALWAYS_INLINE s64 GetDays() const { return this->GetNanoSeconds() / (INT64_C(1000) * INT64_C(1000) * INT64_C(1000) * INT64_C( 60) * INT64_C( 60) * INT64_C( 24)); }
constexpr ALWAYS_INLINE friend bool operator==(const TimeSpanType &lhs, const TimeSpanType &rhs) { return lhs.ns == rhs.ns; }
constexpr ALWAYS_INLINE friend bool operator!=(const TimeSpanType &lhs, const TimeSpanType &rhs) { return lhs.ns != rhs.ns; }
constexpr ALWAYS_INLINE friend bool operator<=(const TimeSpanType &lhs, const TimeSpanType &rhs) { return lhs.ns <= rhs.ns; }
constexpr ALWAYS_INLINE friend bool operator>=(const TimeSpanType &lhs, const TimeSpanType &rhs) { return lhs.ns >= rhs.ns; }
constexpr ALWAYS_INLINE friend bool operator< (const TimeSpanType &lhs, const TimeSpanType &rhs) { return lhs.ns < rhs.ns; }
constexpr ALWAYS_INLINE friend bool operator> (const TimeSpanType &lhs, const TimeSpanType &rhs) { return lhs.ns > rhs.ns; }
constexpr ALWAYS_INLINE friend bool operator==(const TimeSpanType &lhs, const TimeSpanType &rhs) { return lhs._ns == rhs._ns; }
constexpr ALWAYS_INLINE friend bool operator!=(const TimeSpanType &lhs, const TimeSpanType &rhs) { return lhs._ns != rhs._ns; }
constexpr ALWAYS_INLINE friend bool operator<=(const TimeSpanType &lhs, const TimeSpanType &rhs) { return lhs._ns <= rhs._ns; }
constexpr ALWAYS_INLINE friend bool operator>=(const TimeSpanType &lhs, const TimeSpanType &rhs) { return lhs._ns >= rhs._ns; }
constexpr ALWAYS_INLINE friend bool operator< (const TimeSpanType &lhs, const TimeSpanType &rhs) { return lhs._ns < rhs._ns; }
constexpr ALWAYS_INLINE friend bool operator> (const TimeSpanType &lhs, const TimeSpanType &rhs) { return lhs._ns > rhs._ns; }
constexpr ALWAYS_INLINE TimeSpanType &operator+=(const TimeSpanType &rhs) { this->ns += rhs.ns; return *this; }
constexpr ALWAYS_INLINE TimeSpanType &operator-=(const TimeSpanType &rhs) { this->ns -= rhs.ns; return *this; }
constexpr ALWAYS_INLINE TimeSpanType &operator+=(const TimeSpanType &rhs) { _ns += rhs._ns; return *this; }
constexpr ALWAYS_INLINE TimeSpanType &operator-=(const TimeSpanType &rhs) { _ns -= rhs._ns; return *this; }
constexpr ALWAYS_INLINE friend TimeSpanType operator+(const TimeSpanType &lhs, const TimeSpanType &rhs) { TimeSpanType r(lhs); return r += rhs; }
constexpr ALWAYS_INLINE friend TimeSpanType operator-(const TimeSpanType &lhs, const TimeSpanType &rhs) { TimeSpanType r(lhs); return r -= rhs; }
@ -61,13 +61,13 @@ namespace ams {
private:
using ZeroTag = const class ZeroTagImpl{} *;
private:
TimeSpanType ts;
TimeSpanType m_ts;
public:
constexpr ALWAYS_INLINE TimeSpan(ZeroTag z = nullptr) : ts(TimeSpanType::FromNanoSeconds(0)) { AMS_UNUSED(z); /* ... */ }
constexpr ALWAYS_INLINE TimeSpan(const TimeSpanType &t) : ts(t) { /* ... */ }
constexpr ALWAYS_INLINE TimeSpan(ZeroTag z = nullptr) : m_ts(TimeSpanType::FromNanoSeconds(0)) { AMS_UNUSED(z); /* ... */ }
constexpr ALWAYS_INLINE TimeSpan(const TimeSpanType &t) : m_ts(t) { /* ... */ }
template<typename R, typename P>
constexpr ALWAYS_INLINE TimeSpan(const std::chrono::duration<R, P>& c) : ts(TimeSpanType::FromNanoSeconds(static_cast<std::chrono::nanoseconds>(c).count())) { /* ... */ }
constexpr ALWAYS_INLINE TimeSpan(const std::chrono::duration<R, P>& c) : m_ts(TimeSpanType::FromNanoSeconds(static_cast<std::chrono::nanoseconds>(c).count())) { /* ... */ }
public:
static constexpr ALWAYS_INLINE TimeSpan FromNanoSeconds(s64 ns) { return TimeSpanType::FromNanoSeconds(ns); }
static constexpr ALWAYS_INLINE TimeSpan FromMicroSeconds(s64 ms) { return TimeSpanType::FromMicroSeconds(ms); }
@ -77,29 +77,29 @@ namespace ams {
static constexpr ALWAYS_INLINE TimeSpan FromHours(s64 h) { return TimeSpanType::FromHours(h); }
static constexpr ALWAYS_INLINE TimeSpan FromDays(s64 d) { return TimeSpanType::FromDays(d); }
constexpr ALWAYS_INLINE s64 GetNanoSeconds() const { return this->ts.GetNanoSeconds(); }
constexpr ALWAYS_INLINE s64 GetMicroSeconds() const { return this->ts.GetMicroSeconds(); }
constexpr ALWAYS_INLINE s64 GetMilliSeconds() const { return this->ts.GetMilliSeconds(); }
constexpr ALWAYS_INLINE s64 GetSeconds() const { return this->ts.GetSeconds(); }
constexpr ALWAYS_INLINE s64 GetMinutes() const { return this->ts.GetMinutes(); }
constexpr ALWAYS_INLINE s64 GetHours() const { return this->ts.GetHours(); }
constexpr ALWAYS_INLINE s64 GetDays() const { return this->ts.GetDays(); }
constexpr ALWAYS_INLINE s64 GetNanoSeconds() const { return m_ts.GetNanoSeconds(); }
constexpr ALWAYS_INLINE s64 GetMicroSeconds() const { return m_ts.GetMicroSeconds(); }
constexpr ALWAYS_INLINE s64 GetMilliSeconds() const { return m_ts.GetMilliSeconds(); }
constexpr ALWAYS_INLINE s64 GetSeconds() const { return m_ts.GetSeconds(); }
constexpr ALWAYS_INLINE s64 GetMinutes() const { return m_ts.GetMinutes(); }
constexpr ALWAYS_INLINE s64 GetHours() const { return m_ts.GetHours(); }
constexpr ALWAYS_INLINE s64 GetDays() const { return m_ts.GetDays(); }
constexpr ALWAYS_INLINE friend bool operator==(const TimeSpan &lhs, const TimeSpan &rhs) { return lhs.ts == rhs.ts; }
constexpr ALWAYS_INLINE friend bool operator!=(const TimeSpan &lhs, const TimeSpan &rhs) { return lhs.ts != rhs.ts; }
constexpr ALWAYS_INLINE friend bool operator<=(const TimeSpan &lhs, const TimeSpan &rhs) { return lhs.ts <= rhs.ts; }
constexpr ALWAYS_INLINE friend bool operator>=(const TimeSpan &lhs, const TimeSpan &rhs) { return lhs.ts >= rhs.ts; }
constexpr ALWAYS_INLINE friend bool operator< (const TimeSpan &lhs, const TimeSpan &rhs) { return lhs.ts < rhs.ts; }
constexpr ALWAYS_INLINE friend bool operator> (const TimeSpan &lhs, const TimeSpan &rhs) { return lhs.ts > rhs.ts; }
constexpr ALWAYS_INLINE friend bool operator==(const TimeSpan &lhs, const TimeSpan &rhs) { return lhs.m_ts == rhs.m_ts; }
constexpr ALWAYS_INLINE friend bool operator!=(const TimeSpan &lhs, const TimeSpan &rhs) { return lhs.m_ts != rhs.m_ts; }
constexpr ALWAYS_INLINE friend bool operator<=(const TimeSpan &lhs, const TimeSpan &rhs) { return lhs.m_ts <= rhs.m_ts; }
constexpr ALWAYS_INLINE friend bool operator>=(const TimeSpan &lhs, const TimeSpan &rhs) { return lhs.m_ts >= rhs.m_ts; }
constexpr ALWAYS_INLINE friend bool operator< (const TimeSpan &lhs, const TimeSpan &rhs) { return lhs.m_ts < rhs.m_ts; }
constexpr ALWAYS_INLINE friend bool operator> (const TimeSpan &lhs, const TimeSpan &rhs) { return lhs.m_ts > rhs.m_ts; }
constexpr ALWAYS_INLINE TimeSpan &operator+=(const TimeSpan &rhs) { this->ts += rhs.ts; return *this; }
constexpr ALWAYS_INLINE TimeSpan &operator-=(const TimeSpan &rhs) { this->ts -= rhs.ts; return *this; }
constexpr ALWAYS_INLINE TimeSpan &operator+=(const TimeSpan &rhs) { m_ts += rhs.m_ts; return *this; }
constexpr ALWAYS_INLINE TimeSpan &operator-=(const TimeSpan &rhs) { m_ts -= rhs.m_ts; return *this; }
constexpr ALWAYS_INLINE friend TimeSpan operator+(const TimeSpan &lhs, const TimeSpan &rhs) { TimeSpan r(lhs); return r += rhs; }
constexpr ALWAYS_INLINE friend TimeSpan operator-(const TimeSpan &lhs, const TimeSpan &rhs) { TimeSpan r(lhs); return r -= rhs; }
constexpr ALWAYS_INLINE operator TimeSpanType() const {
return this->ts;
return m_ts;
}
};

View file

@ -27,9 +27,9 @@ namespace ams::util {
static constexpr size_t AlignedSize = ((Size + Alignment - 1) / Alignment) * Alignment;
static_assert(AlignedSize % Alignment == 0);
private:
u8 buffer[Alignment + AlignedSize];
u8 m_buffer[Alignment + AlignedSize];
public:
ALWAYS_INLINE operator u8 *() { return reinterpret_cast<u8 *>(util::AlignUp(reinterpret_cast<uintptr_t>(this->buffer), Alignment)); }
ALWAYS_INLINE operator u8 *() { return reinterpret_cast<u8 *>(util::AlignUp(reinterpret_cast<uintptr_t>(m_buffer), Alignment)); }
};
}

View file

@ -111,17 +111,17 @@ namespace ams::util {
class Reference {
friend struct BitFlagSet<N, T>;
private:
BitFlagSet<N, T> *set;
s32 idx;
BitFlagSet<N, T> *m_set;
s32 m_idx;
private:
constexpr ALWAYS_INLINE Reference() : set(nullptr), idx(0) { /* ... */ }
constexpr ALWAYS_INLINE Reference(BitFlagSet<N, T> &s, s32 i) : set(std::addressof(s)), idx(i) { /* ... */ }
constexpr ALWAYS_INLINE Reference() : m_set(nullptr), m_idx(0) { /* ... */ }
constexpr ALWAYS_INLINE Reference(BitFlagSet<N, T> &s, s32 i) : m_set(std::addressof(s)), m_idx(i) { /* ... */ }
public:
constexpr ALWAYS_INLINE Reference &operator=(bool en) { this->set->Set(this->idx, en); return *this; }
constexpr ALWAYS_INLINE Reference &operator=(const Reference &r) { this->set->Set(this->idx, r); return *this; }
constexpr ALWAYS_INLINE Reference &Negate() { this->set->Negate(this->idx); return *this; }
constexpr ALWAYS_INLINE operator bool() const { return this->set->Test(this->idx); }
constexpr ALWAYS_INLINE bool operator~() const { return !this->set->Test(this->idx); }
constexpr ALWAYS_INLINE Reference &operator=(bool en) { m_set->Set(m_idx, en); return *this; }
constexpr ALWAYS_INLINE Reference &operator=(const Reference &r) { m_set->Set(m_idx, r); return *this; }
constexpr ALWAYS_INLINE Reference &Negate() { m_set->Negate(m_idx); return *this; }
constexpr ALWAYS_INLINE operator bool() const { return m_set->Test(m_idx); }
constexpr ALWAYS_INLINE bool operator~() const { return !m_set->Test(m_idx); }
};
template<s32 _Index>

View file

@ -40,22 +40,22 @@ namespace ams::util {
return Storage(1) << (FlagsPerWord - 1 - bit);
}
private:
Storage words[NumWords];
Storage m_words[NumWords];
public:
constexpr ALWAYS_INLINE BitSet() : words() { /* ... */ }
constexpr ALWAYS_INLINE BitSet() : m_words() { /* ... */ }
constexpr ALWAYS_INLINE void SetBit(size_t i) {
this->words[i / FlagsPerWord] |= GetBitMask(i % FlagsPerWord);
m_words[i / FlagsPerWord] |= GetBitMask(i % FlagsPerWord);
}
constexpr ALWAYS_INLINE void ClearBit(size_t i) {
this->words[i / FlagsPerWord] &= ~GetBitMask(i % FlagsPerWord);
m_words[i / FlagsPerWord] &= ~GetBitMask(i % FlagsPerWord);
}
constexpr ALWAYS_INLINE size_t CountLeadingZero() const {
for (size_t i = 0; i < NumWords; i++) {
if (this->words[i]) {
return FlagsPerWord * i + CountLeadingZeroImpl(this->words[i]);
if (m_words[i]) {
return FlagsPerWord * i + CountLeadingZeroImpl(m_words[i]);
}
}
return FlagsPerWord * NumWords;
@ -63,7 +63,7 @@ namespace ams::util {
constexpr ALWAYS_INLINE size_t GetNextSet(size_t n) const {
for (size_t i = (n + 1) / FlagsPerWord; i < NumWords; i++) {
Storage word = this->words[i];
Storage word = m_words[i];
if (!util::IsAligned(n + 1, FlagsPerWord)) {
word &= GetBitMask(n % FlagsPerWord) - 1;
}

View file

@ -37,32 +37,32 @@ namespace ams::util {
return __builtin_ctzll(static_cast<u64>(v));
}
T value;
T m_value;
public:
/* Note: GCC has a bug in constant-folding here. Workaround: wrap entire caller with constexpr. */
constexpr ALWAYS_INLINE BitsOf(T value = T(0u)) : value(value) {
constexpr ALWAYS_INLINE BitsOf(T value = T(0u)) : m_value(value) {
/* ... */
}
constexpr ALWAYS_INLINE bool operator==(const BitsOf &other) const {
return this->value == other.value;
return m_value == other.m_value;
}
constexpr ALWAYS_INLINE bool operator!=(const BitsOf &other) const {
return this->value != other.value;
return m_value != other.m_value;
}
constexpr ALWAYS_INLINE int operator*() const {
return GetLsbPos(this->value);
return GetLsbPos(m_value);
}
constexpr ALWAYS_INLINE BitsOf &operator++() {
this->value &= ~(T(1u) << GetLsbPos(this->value));
m_value &= ~(T(1u) << GetLsbPos(m_value));
return *this;
}
constexpr ALWAYS_INLINE BitsOf &operator++(int) {
BitsOf ret(this->value);
BitsOf ret(m_value);
++(*this);
return ret;
}

View file

@ -24,20 +24,20 @@ namespace ams::util {
template<class Key, class Value, size_t N>
class BoundedMap {
private:
std::array<util::optional<Key>, N> keys;
std::array<TypedStorage<Value>, N> values;
std::array<util::optional<Key>, N> m_keys;
std::array<TypedStorage<Value>, N> m_values;
private:
ALWAYS_INLINE void FreeEntry(size_t i) {
this->keys[i].reset();
DestroyAt(this->values[i]);
m_keys[i].reset();
DestroyAt(m_values[i]);
}
public:
constexpr BoundedMap() : keys(), values() { /* ... */ }
constexpr BoundedMap() : m_keys(), m_values() { /* ... */ }
Value *Find(const Key &key) {
for (size_t i = 0; i < N; i++) {
if (this->keys[i] && this->keys[i].value() == key) {
return GetPointer(this->values[i]);
if (m_keys[i] && m_keys[i].value() == key) {
return GetPointer(m_values[i]);
}
}
return nullptr;
@ -45,7 +45,7 @@ namespace ams::util {
void Remove(const Key &key) {
for (size_t i = 0; i < N; i++) {
if (this->keys[i] && this->keys[i].value() == key) {
if (m_keys[i] && m_keys[i].value() == key) {
this->FreeEntry(i);
break;
}
@ -60,7 +60,7 @@ namespace ams::util {
bool IsFull() {
for (size_t i = 0; i < N; i++) {
if (!this->keys[i]) {
if (!m_keys[i]) {
return false;
}
}
@ -76,9 +76,9 @@ namespace ams::util {
/* Find a free value. */
for (size_t i = 0; i < N; i++) {
if (!this->keys[i]) {
this->keys[i] = key;
ConstructAt(this->values[i], std::forward<Value>(value));
if (!m_keys[i]) {
m_keys[i] = key;
ConstructAt(m_values[i], std::forward<Value>(value));
return true;
}
}
@ -89,17 +89,17 @@ namespace ams::util {
bool InsertOrAssign(const Key &key, Value &&value) {
/* Try to find and assign an existing value. */
for (size_t i = 0; i < N; i++) {
if (this->keys[i] && this->keys[i].value() == key) {
GetReference(this->values[i]) = std::forward<Value>(value);
if (m_keys[i] && m_keys[i].value() == key) {
GetReference(m_values[i]) = std::forward<Value>(value);
return true;
}
}
/* Find a free value. */
for (size_t i = 0; i < N; i++) {
if (!this->keys[i]) {
this->keys[i] = key;
ConstructAt(this->values[i], std::move(value));
if (!m_keys[i]) {
m_keys[i] = key;
ConstructAt(m_values[i], std::move(value));
return true;
}
}
@ -116,9 +116,9 @@ namespace ams::util {
/* Find a free value. */
for (size_t i = 0; i < N; i++) {
if (!this->keys[i]) {
this->keys[i] = key;
ConstructAt(this->values[i], std::forward<Args>(args)...);
if (!m_keys[i]) {
m_keys[i] = key;
ConstructAt(m_values[i], std::forward<Args>(args)...);
return true;
}
}

View file

@ -119,22 +119,22 @@ namespace ams::util {
private:
friend class ConstIterator;
private:
const FixedTree *m_this;
const FixedTree *m_tree;
int m_index;
protected:
constexpr ALWAYS_INLINE IteratorBase(const FixedTree *tree, int index) : m_this(tree), m_index(index) { /* ... */ }
constexpr ALWAYS_INLINE IteratorBase(const FixedTree *tree, int index) : m_tree(tree), m_index(index) { /* ... */ }
constexpr bool IsEqualImpl(const IteratorBase &rhs) const {
/* Validate pre-conditions. */
AMS_ASSERT(m_this);
AMS_ASSERT(m_tree);
/* Check for tree equality. */
if (m_this != rhs.m_this) {
if (m_tree != rhs.m_tree) {
return false;
}
/* Check for nil. */
if (m_this->IsNil(m_index) && m_this->IsNil(rhs.m_index)) {
if (m_tree->IsNil(m_index) && m_tree->IsNil(rhs.m_index)) {
return true;
}
@ -144,19 +144,19 @@ namespace ams::util {
constexpr IteratorMember &DereferenceImpl() const {
/* Validate pre-conditions. */
AMS_ASSERT(m_this);
AMS_ASSERT(m_tree);
if (!m_this->IsNil(m_index)) {
return m_this->m_nodes[m_index].m_data;
if (!m_tree->IsNil(m_index)) {
return m_tree->m_nodes[m_index].m_data;
} else {
AMS_ASSERT(false);
return m_this->GetNode(std::numeric_limits<int>::max())->m_data;
return m_tree->GetNode(std::numeric_limits<int>::max())->m_data;
}
}
constexpr ALWAYS_INLINE IteratorBase &IncrementImpl() {
/* Validate pre-conditions. */
AMS_ASSERT(m_this);
AMS_ASSERT(m_tree);
this->OperateIndex(true);
return *this;
@ -164,7 +164,7 @@ namespace ams::util {
constexpr ALWAYS_INLINE IteratorBase &DecrementImpl() {
/* Validate pre-conditions. */
AMS_ASSERT(m_this);
AMS_ASSERT(m_tree);
this->OperateIndex(false);
return *this;
@ -176,18 +176,18 @@ namespace ams::util {
if (m_index == Index_BeforeBegin) {
m_index = 0;
} else {
m_index = m_this->UncheckedPP(m_index);
if (m_this->IsNil(m_index)) {
m_index = m_tree->UncheckedPP(m_index);
if (m_tree->IsNil(m_index)) {
m_index = Index_AfterEnd;
}
}
} else {
/* We're decrementing. */
if (m_index == Index_AfterEnd) {
m_index = static_cast<int>(m_this->size()) - 1;
m_index = static_cast<int>(m_tree->size()) - 1;
} else {
m_index = m_this->UncheckedMM(m_index);
if (m_this->IsNil(m_index)) {
m_index = m_tree->UncheckedMM(m_index);
if (m_tree->IsNil(m_index)) {
m_index = Index_BeforeBegin;
}
}
@ -233,7 +233,7 @@ namespace ams::util {
constexpr ALWAYS_INLINE ConstIterator(const FixedTree &tree, int index) : IteratorBase(std::addressof(tree), index) { /* ... */ }
constexpr ALWAYS_INLINE ConstIterator(const ConstIterator &rhs) = default;
constexpr ALWAYS_INLINE ConstIterator(const Iterator &rhs) : IteratorBase(rhs.m_this, rhs.m_index) { /* ... */ }
constexpr ALWAYS_INLINE ConstIterator(const Iterator &rhs) : IteratorBase(rhs.m_tree, rhs.m_index) { /* ... */ }
constexpr ALWAYS_INLINE bool operator==(const ConstIterator &rhs) const {
return this->IsEqualImpl(rhs);

View file

@ -36,13 +36,13 @@ namespace ams::util {
private:
friend class impl::IntrusiveListImpl;
IntrusiveListNode *prev;
IntrusiveListNode *next;
IntrusiveListNode *m_prev;
IntrusiveListNode *m_next;
public:
constexpr ALWAYS_INLINE IntrusiveListNode() : prev(this), next(this) { /* ... */ }
constexpr ALWAYS_INLINE IntrusiveListNode() : m_prev(this), m_next(this) { /* ... */ }
constexpr ALWAYS_INLINE bool IsLinked() const {
return this->next != this;
return m_next != this;
}
private:
ALWAYS_INLINE void LinkPrev(IntrusiveListNode *node) {
@ -53,11 +53,11 @@ namespace ams::util {
ALWAYS_INLINE void SplicePrev(IntrusiveListNode *first, IntrusiveListNode *last) {
/* Splice a range into the list. */
auto last_prev = last->prev;
first->prev = this->prev;
this->prev->next = first;
last_prev->next = this;
this->prev = last_prev;
auto last_prev = last->m_prev;
first->m_prev = m_prev;
last_prev->m_next = this;
m_prev->m_next = first;
m_prev = last_prev;
}
ALWAYS_INLINE void LinkNext(IntrusiveListNode *node) {
@ -68,40 +68,40 @@ namespace ams::util {
ALWAYS_INLINE void SpliceNext(IntrusiveListNode *first, IntrusiveListNode *last) {
/* Splice a range into the list. */
auto last_prev = last->prev;
first->prev = this;
last_prev->next = next;
this->next->prev = last_prev;
this->next = first;
auto last_prev = last->m_prev;
first->m_prev = this;
last_prev->m_next = m_next;
m_next->m_prev = last_prev;
m_next = first;
}
ALWAYS_INLINE void Unlink() {
this->Unlink(this->next);
this->Unlink(m_next);
}
ALWAYS_INLINE void Unlink(IntrusiveListNode *last) {
/* Unlink a node from a next node. */
auto last_prev = last->prev;
this->prev->next = last;
last->prev = this->prev;
last_prev->next = this;
this->prev = last_prev;
auto last_prev = last->m_prev;
m_prev->m_next = last;
last->m_prev = m_prev;
last_prev->m_next = this;
m_prev = last_prev;
}
ALWAYS_INLINE IntrusiveListNode *GetPrev() {
return this->prev;
return m_prev;
}
ALWAYS_INLINE const IntrusiveListNode *GetPrev() const {
return this->prev;
return m_prev;
}
ALWAYS_INLINE IntrusiveListNode *GetNext() {
return this->next;
return m_next;
}
ALWAYS_INLINE const IntrusiveListNode *GetNext() const {
return this->next;
return m_next;
}
};
/* DEPRECATED: static_assert(std::is_literal_type<IntrusiveListNode>::value); */
@ -111,7 +111,7 @@ namespace ams::util {
class IntrusiveListImpl {
NON_COPYABLE(IntrusiveListImpl);
private:
IntrusiveListNode root_node;
IntrusiveListNode m_root_node;
public:
template<bool Const>
class Iterator;
@ -137,12 +137,12 @@ namespace ams::util {
using pointer = typename std::conditional<Const, IntrusiveListImpl::const_pointer, IntrusiveListImpl::pointer>::type;
using reference = typename std::conditional<Const, IntrusiveListImpl::const_reference, IntrusiveListImpl::reference>::type;
private:
pointer node;
pointer m_node;
public:
ALWAYS_INLINE explicit Iterator(pointer n) : node(n) { /* ... */ }
ALWAYS_INLINE explicit Iterator(pointer n) : m_node(n) { /* ... */ }
ALWAYS_INLINE bool operator==(const Iterator &rhs) const {
return this->node == rhs.node;
return m_node == rhs.m_node;
}
ALWAYS_INLINE bool operator!=(const Iterator &rhs) const {
@ -150,20 +150,20 @@ namespace ams::util {
}
ALWAYS_INLINE pointer operator->() const {
return this->node;
return m_node;
}
ALWAYS_INLINE reference operator*() const {
return *this->node;
return *m_node;
}
ALWAYS_INLINE Iterator &operator++() {
this->node = this->node->next;
m_node = m_node->m_next;
return *this;
}
ALWAYS_INLINE Iterator &operator--() {
this->node = this->node->prev;
m_node = m_node->m_prev;
return *this;
}
@ -180,31 +180,31 @@ namespace ams::util {
}
ALWAYS_INLINE operator Iterator<true>() const {
return Iterator<true>(this->node);
return Iterator<true>(m_node);
}
ALWAYS_INLINE Iterator<false> GetNonConstIterator() const {
return Iterator<false>(const_cast<IntrusiveListImpl::pointer>(this->node));
return Iterator<false>(const_cast<IntrusiveListImpl::pointer>(m_node));
}
};
public:
constexpr ALWAYS_INLINE IntrusiveListImpl() : root_node() { /* ... */ }
constexpr ALWAYS_INLINE IntrusiveListImpl() : m_root_node() { /* ... */ }
/* Iterator accessors. */
ALWAYS_INLINE iterator begin() {
return iterator(this->root_node.GetNext());
return iterator(m_root_node.GetNext());
}
ALWAYS_INLINE const_iterator begin() const {
return const_iterator(this->root_node.GetNext());
return const_iterator(m_root_node.GetNext());
}
ALWAYS_INLINE iterator end() {
return iterator(std::addressof(this->root_node));
return iterator(std::addressof(m_root_node));
}
ALWAYS_INLINE const_iterator end() const {
return const_iterator(std::addressof(this->root_node));
return const_iterator(std::addressof(m_root_node));
}
ALWAYS_INLINE iterator iterator_to(reference v) {
@ -221,7 +221,7 @@ namespace ams::util {
/* Content management. */
ALWAYS_INLINE bool empty() const {
return !this->root_node.IsLinked();
return !m_root_node.IsLinked();
}
ALWAYS_INLINE size_type size() const {
@ -229,35 +229,35 @@ namespace ams::util {
}
ALWAYS_INLINE reference back() {
return *this->root_node.GetPrev();
return *m_root_node.GetPrev();
}
ALWAYS_INLINE const_reference back() const {
return *this->root_node.GetPrev();
return *m_root_node.GetPrev();
}
ALWAYS_INLINE reference front() {
return *this->root_node.GetNext();
return *m_root_node.GetNext();
}
ALWAYS_INLINE const_reference front() const {
return *this->root_node.GetNext();
return *m_root_node.GetNext();
}
ALWAYS_INLINE void push_back(reference node) {
this->root_node.LinkPrev(std::addressof(node));
m_root_node.LinkPrev(std::addressof(node));
}
ALWAYS_INLINE void push_front(reference node) {
this->root_node.LinkNext(std::addressof(node));
m_root_node.LinkNext(std::addressof(node));
}
ALWAYS_INLINE void pop_back() {
this->root_node.GetPrev()->Unlink();
m_root_node.GetPrev()->Unlink();
}
ALWAYS_INLINE void pop_front() {
this->root_node.GetNext()->Unlink();
m_root_node.GetNext()->Unlink();
}
ALWAYS_INLINE iterator insert(const_iterator pos, reference node) {
@ -315,7 +315,7 @@ namespace ams::util {
class IntrusiveList {
NON_COPYABLE(IntrusiveList);
private:
impl::IntrusiveListImpl impl;
impl::IntrusiveListImpl m_impl;
public:
template<bool Const>
class Iterator;
@ -345,16 +345,16 @@ namespace ams::util {
using pointer = typename std::conditional<Const, IntrusiveList::const_pointer, IntrusiveList::pointer>::type;
using reference = typename std::conditional<Const, IntrusiveList::const_reference, IntrusiveList::reference>::type;
private:
ImplIterator iterator;
ImplIterator m_iterator;
private:
explicit ALWAYS_INLINE Iterator(ImplIterator it) : iterator(it) { /* ... */ }
explicit ALWAYS_INLINE Iterator(ImplIterator it) : m_iterator(it) { /* ... */ }
ALWAYS_INLINE ImplIterator GetImplIterator() const {
return this->iterator;
return m_iterator;
}
public:
ALWAYS_INLINE bool operator==(const Iterator &rhs) const {
return this->iterator == rhs.iterator;
return m_iterator == rhs.m_iterator;
}
ALWAYS_INLINE bool operator!=(const Iterator &rhs) const {
@ -362,37 +362,37 @@ namespace ams::util {
}
ALWAYS_INLINE pointer operator->() const {
return std::addressof(Traits::GetParent(*this->iterator));
return std::addressof(Traits::GetParent(*m_iterator));
}
ALWAYS_INLINE reference operator*() const {
return Traits::GetParent(*this->iterator);
return Traits::GetParent(*m_iterator);
}
ALWAYS_INLINE Iterator &operator++() {
++this->iterator;
++m_iterator;
return *this;
}
ALWAYS_INLINE Iterator &operator--() {
--this->iterator;
--m_iterator;
return *this;
}
ALWAYS_INLINE Iterator operator++(int) {
const Iterator it{*this};
++this->iterator;
++m_iterator;
return it;
}
ALWAYS_INLINE Iterator operator--(int) {
const Iterator it{*this};
--this->iterator;
--m_iterator;
return it;
}
ALWAYS_INLINE operator Iterator<true>() const {
return Iterator<true>(this->iterator);
return Iterator<true>(m_iterator);
}
};
private:
@ -412,23 +412,23 @@ namespace ams::util {
return Traits::GetParent(node);
}
public:
constexpr ALWAYS_INLINE IntrusiveList() : impl() { /* ... */ }
constexpr ALWAYS_INLINE IntrusiveList() : m_impl() { /* ... */ }
/* Iterator accessors. */
ALWAYS_INLINE iterator begin() {
return iterator(this->impl.begin());
return iterator(m_impl.begin());
}
ALWAYS_INLINE const_iterator begin() const {
return const_iterator(this->impl.begin());
return const_iterator(m_impl.begin());
}
ALWAYS_INLINE iterator end() {
return iterator(this->impl.end());
return iterator(m_impl.end());
}
ALWAYS_INLINE const_iterator end() const {
return const_iterator(this->impl.end());
return const_iterator(m_impl.end());
}
ALWAYS_INLINE const_iterator cbegin() const {
@ -464,82 +464,82 @@ namespace ams::util {
}
ALWAYS_INLINE iterator iterator_to(reference v) {
return iterator(this->impl.iterator_to(GetNode(v)));
return iterator(m_impl.iterator_to(GetNode(v)));
}
ALWAYS_INLINE const_iterator iterator_to(const_reference v) const {
return const_iterator(this->impl.iterator_to(GetNode(v)));
return const_iterator(m_impl.iterator_to(GetNode(v)));
}
/* Content management. */
ALWAYS_INLINE bool empty() const {
return this->impl.empty();
return m_impl.empty();
}
ALWAYS_INLINE size_type size() const {
return this->impl.size();
return m_impl.size();
}
ALWAYS_INLINE reference back() {
AMS_ASSERT(!this->impl.empty());
return GetParent(this->impl.back());
AMS_ASSERT(!m_impl.empty());
return GetParent(m_impl.back());
}
ALWAYS_INLINE const_reference back() const {
AMS_ASSERT(!this->impl.empty());
return GetParent(this->impl.back());
AMS_ASSERT(!m_impl.empty());
return GetParent(m_impl.back());
}
ALWAYS_INLINE reference front() {
AMS_ASSERT(!this->impl.empty());
return GetParent(this->impl.front());
AMS_ASSERT(!m_impl.empty());
return GetParent(m_impl.front());
}
ALWAYS_INLINE const_reference front() const {
AMS_ASSERT(!this->impl.empty());
return GetParent(this->impl.front());
AMS_ASSERT(!m_impl.empty());
return GetParent(m_impl.front());
}
ALWAYS_INLINE void push_back(reference ref) {
this->impl.push_back(GetNode(ref));
m_impl.push_back(GetNode(ref));
}
ALWAYS_INLINE void push_front(reference ref) {
this->impl.push_front(GetNode(ref));
m_impl.push_front(GetNode(ref));
}
ALWAYS_INLINE void pop_back() {
AMS_ASSERT(!this->impl.empty());
this->impl.pop_back();
AMS_ASSERT(!m_impl.empty());
m_impl.pop_back();
}
ALWAYS_INLINE void pop_front() {
AMS_ASSERT(!this->impl.empty());
this->impl.pop_front();
AMS_ASSERT(!m_impl.empty());
m_impl.pop_front();
}
ALWAYS_INLINE iterator insert(const_iterator pos, reference ref) {
return iterator(this->impl.insert(pos.GetImplIterator(), GetNode(ref)));
return iterator(m_impl.insert(pos.GetImplIterator(), GetNode(ref)));
}
ALWAYS_INLINE void splice(const_iterator pos, IntrusiveList &o) {
this->impl.splice(pos.GetImplIterator(), o.impl);
m_impl.splice(pos.GetImplIterator(), o.m_impl);
}
ALWAYS_INLINE void splice(const_iterator pos, IntrusiveList &o, const_iterator first) {
this->impl.splice(pos.GetImplIterator(), o.impl, first.GetImplIterator());
m_impl.splice(pos.GetImplIterator(), o.m_impl, first.GetImplIterator());
}
ALWAYS_INLINE void splice(const_iterator pos, IntrusiveList &o, const_iterator first, const_iterator last) {
this->impl.splice(pos.GetImplIterator(), o.impl, first.GetImplIterator(), last.GetImplIterator());
m_impl.splice(pos.GetImplIterator(), o.m_impl, first.GetImplIterator(), last.GetImplIterator());
}
ALWAYS_INLINE iterator erase(const_iterator pos) {
return iterator(this->impl.erase(pos.GetImplIterator()));
return iterator(m_impl.erase(pos.GetImplIterator()));
}
ALWAYS_INLINE void clear() {
this->impl.clear();
m_impl.clear();
}
};

View file

@ -51,20 +51,20 @@ namespace ams::util {
return value ^ (value >> 30);
}
private:
State state;
State m_state;
private:
/* Internal API. */
void FinalizeInitialization() {
const u32 state0 = this->state.data[0] & TopBitmask;
const u32 state1 = this->state.data[1];
const u32 state2 = this->state.data[2];
const u32 state3 = this->state.data[3];
const u32 state0 = m_state.data[0] & TopBitmask;
const u32 state1 = m_state.data[1];
const u32 state2 = m_state.data[2];
const u32 state3 = m_state.data[3];
if (state0 == 0 && state1 == 0 && state2 == 0 && state3 == 0) {
this->state.data[0] = 'T';
this->state.data[1] = 'I';
this->state.data[2] = 'N';
this->state.data[3] = 'Y';
m_state.data[0] = 'T';
m_state.data[1] = 'I';
m_state.data[2] = 'N';
m_state.data[3] = 'Y';
}
for (int i = 0; i < NumDiscardedInitOutputs; i++) {
@ -102,42 +102,42 @@ namespace ams::util {
state2 ^= y;
}
public:
constexpr TinyMT() : state() { /* ... */ }
constexpr TinyMT() : m_state() { /* ... */ }
/* Public API. */
/* Initialization. */
void Initialize(u32 seed) {
this->state.data[0] = seed;
this->state.data[1] = ParamMat1;
this->state.data[2] = ParamMat2;
this->state.data[3] = ParamTmat;
m_state.data[0] = seed;
m_state.data[1] = ParamMat1;
m_state.data[2] = ParamMat2;
m_state.data[3] = ParamTmat;
for (int i = 1; i < MinimumInitIterations; i++) {
const u32 mixed = XorByShifted30(this->state.data[(i - 1) % NumStateWords]);
this->state.data[i % NumStateWords] ^= mixed * ParamMult + i;
const u32 mixed = XorByShifted30(m_state.data[(i - 1) % NumStateWords]);
m_state.data[i % NumStateWords] ^= mixed * ParamMult + i;
}
this->FinalizeInitialization();
}
void Initialize(const u32 *seed, int seed_count) {
this->state.data[0] = 0;
this->state.data[1] = ParamMat1;
this->state.data[2] = ParamMat2;
this->state.data[3] = ParamTmat;
m_state.data[0] = 0;
m_state.data[1] = ParamMat1;
m_state.data[2] = ParamMat2;
m_state.data[3] = ParamTmat;
{
const int num_init_iterations = std::max(seed_count + 1, MinimumInitIterations) - 1;
GenerateInitialValuePlus(std::addressof(this->state), 0, seed_count);
GenerateInitialValuePlus(std::addressof(m_state), 0, seed_count);
for (int i = 0; i < num_init_iterations; i++) {
GenerateInitialValuePlus(std::addressof(this->state), (i + 1) % NumStateWords, (i < seed_count) ? seed[i] : 0);
GenerateInitialValuePlus(std::addressof(m_state), (i + 1) % NumStateWords, (i < seed_count) ? seed[i] : 0);
}
for (int i = 0; i < static_cast<int>(NumStateWords); i++) {
GenerateInitialValueXor(std::addressof(this->state), (i + 1 + num_init_iterations) % NumStateWords);
GenerateInitialValueXor(std::addressof(m_state), (i + 1 + num_init_iterations) % NumStateWords);
}
}
@ -146,11 +146,11 @@ namespace ams::util {
/* State management. */
void GetState(TinyMT::State *out) const {
std::memcpy(out->data, this->state.data, sizeof(this->state));
std::memcpy(out->data, m_state.data, sizeof(m_state));
}
void SetState(const TinyMT::State *state) {
std::memcpy(this->state.data, state->data, sizeof(this->state));
std::memcpy(m_state.data, state->data, sizeof(m_state));
}
/* Random generation. */
@ -185,13 +185,13 @@ namespace ams::util {
NOINLINE u32 GenerateRandomU32() {
/* Advance state. */
const u32 x0 = (this->state.data[0] & TopBitmask) ^ this->state.data[1] ^ this->state.data[2];
const u32 y0 = this->state.data[3];
const u32 x0 = (m_state.data[0] & TopBitmask) ^ m_state.data[1] ^ m_state.data[2];
const u32 y0 = m_state.data[3];
const u32 x1 = x0 ^ (x0 << 1);
const u32 y1 = y0 ^ (y0 >> 1) ^ x1;
const u32 state0 = this->state.data[1];
u32 state1 = this->state.data[2];
const u32 state0 = m_state.data[1];
u32 state1 = m_state.data[2];
u32 state2 = x1 ^ (y1 << 10);
const u32 state3 = y1;
@ -200,10 +200,10 @@ namespace ams::util {
state2 ^= ParamMat2;
}
this->state.data[0] = state0;
this->state.data[1] = state1;
this->state.data[2] = state2;
this->state.data[3] = state3;
m_state.data[0] = state0;
m_state.data[1] = state1;
m_state.data[2] = state2;
m_state.data[3] = state3;
/* Temper. */
const u32 t1 = state0 + (state2 >> 8);