mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-31 14:58:22 -04:00
exo/vapours: refactor member variables to m_ over this->
This commit is contained in:
parent
5a38311ebf
commit
67a45c97ef
55 changed files with 846 additions and 847 deletions
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue