mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-29 14:05:17 -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
|
@ -40,16 +40,16 @@ namespace ams::crypto::impl {
|
|||
|
||||
if constexpr (KeySize == 16) {
|
||||
/* Aes 128. */
|
||||
static_assert(sizeof(this->round_keys) == sizeof(::Aes128Context));
|
||||
aes128ContextCreate(reinterpret_cast<Aes128Context *>(this->round_keys), key, is_encrypt);
|
||||
static_assert(sizeof(m_round_keys) == sizeof(::Aes128Context));
|
||||
aes128ContextCreate(reinterpret_cast<Aes128Context *>(m_round_keys), key, is_encrypt);
|
||||
} else if constexpr (KeySize == 24) {
|
||||
/* Aes 192. */
|
||||
static_assert(sizeof(this->round_keys) == sizeof(::Aes192Context));
|
||||
aes192ContextCreate(reinterpret_cast<Aes192Context *>(this->round_keys), key, is_encrypt);
|
||||
static_assert(sizeof(m_round_keys) == sizeof(::Aes192Context));
|
||||
aes192ContextCreate(reinterpret_cast<Aes192Context *>(m_round_keys), key, is_encrypt);
|
||||
} else if constexpr (KeySize == 32) {
|
||||
/* Aes 256. */
|
||||
static_assert(sizeof(this->round_keys) == sizeof(::Aes256Context));
|
||||
aes256ContextCreate(reinterpret_cast<Aes256Context *>(this->round_keys), key, is_encrypt);
|
||||
static_assert(sizeof(m_round_keys) == sizeof(::Aes256Context));
|
||||
aes256ContextCreate(reinterpret_cast<Aes256Context *>(m_round_keys), key, is_encrypt);
|
||||
} else {
|
||||
/* Invalid key size. */
|
||||
static_assert(!std::is_same<AesImpl<KeySize>, AesImpl<KeySize>>::value);
|
||||
|
@ -65,16 +65,16 @@ namespace ams::crypto::impl {
|
|||
|
||||
if constexpr (KeySize == 16) {
|
||||
/* Aes 128. */
|
||||
static_assert(sizeof(this->round_keys) == sizeof(::Aes128Context));
|
||||
aes128EncryptBlock(reinterpret_cast<const Aes128Context *>(this->round_keys), dst, src);
|
||||
static_assert(sizeof(m_round_keys) == sizeof(::Aes128Context));
|
||||
aes128EncryptBlock(reinterpret_cast<const Aes128Context *>(m_round_keys), dst, src);
|
||||
} else if constexpr (KeySize == 24) {
|
||||
/* Aes 192. */
|
||||
static_assert(sizeof(this->round_keys) == sizeof(::Aes192Context));
|
||||
aes192EncryptBlock(reinterpret_cast<const Aes192Context *>(this->round_keys), dst, src);
|
||||
static_assert(sizeof(m_round_keys) == sizeof(::Aes192Context));
|
||||
aes192EncryptBlock(reinterpret_cast<const Aes192Context *>(m_round_keys), dst, src);
|
||||
} else if constexpr (KeySize == 32) {
|
||||
/* Aes 256. */
|
||||
static_assert(sizeof(this->round_keys) == sizeof(::Aes256Context));
|
||||
aes256EncryptBlock(reinterpret_cast<const Aes256Context *>(this->round_keys), dst, src);
|
||||
static_assert(sizeof(m_round_keys) == sizeof(::Aes256Context));
|
||||
aes256EncryptBlock(reinterpret_cast<const Aes256Context *>(m_round_keys), dst, src);
|
||||
} else {
|
||||
/* Invalid key size. */
|
||||
static_assert(!std::is_same<AesImpl<KeySize>, AesImpl<KeySize>>::value);
|
||||
|
@ -90,16 +90,16 @@ namespace ams::crypto::impl {
|
|||
|
||||
if constexpr (KeySize == 16) {
|
||||
/* Aes 128. */
|
||||
static_assert(sizeof(this->round_keys) == sizeof(::Aes128Context));
|
||||
aes128DecryptBlock(reinterpret_cast<const Aes128Context *>(this->round_keys), dst, src);
|
||||
static_assert(sizeof(m_round_keys) == sizeof(::Aes128Context));
|
||||
aes128DecryptBlock(reinterpret_cast<const Aes128Context *>(m_round_keys), dst, src);
|
||||
} else if constexpr (KeySize == 24) {
|
||||
/* Aes 192. */
|
||||
static_assert(sizeof(this->round_keys) == sizeof(::Aes192Context));
|
||||
aes192DecryptBlock(reinterpret_cast<const Aes192Context *>(this->round_keys), dst, src);
|
||||
static_assert(sizeof(m_round_keys) == sizeof(::Aes192Context));
|
||||
aes192DecryptBlock(reinterpret_cast<const Aes192Context *>(m_round_keys), dst, src);
|
||||
} else if constexpr (KeySize == 32) {
|
||||
/* Aes 256. */
|
||||
static_assert(sizeof(this->round_keys) == sizeof(::Aes256Context));
|
||||
aes256DecryptBlock(reinterpret_cast<const Aes256Context *>(this->round_keys), dst, src);
|
||||
static_assert(sizeof(m_round_keys) == sizeof(::Aes256Context));
|
||||
aes256DecryptBlock(reinterpret_cast<const Aes256Context *>(m_round_keys), dst, src);
|
||||
} else {
|
||||
/* Invalid key size. */
|
||||
static_assert(!std::is_same<AesImpl<KeySize>, AesImpl<KeySize>>::value);
|
||||
|
|
|
@ -54,13 +54,13 @@ namespace ams::crypto::impl {
|
|||
}
|
||||
|
||||
size_t BigNum::GetSize() const {
|
||||
if (this->num_words == 0) {
|
||||
if (m_num_words == 0) {
|
||||
return 0;
|
||||
}
|
||||
static_assert(sizeof(Word) == 4);
|
||||
|
||||
size_t size = this->num_words * sizeof(Word);
|
||||
const Word last = this->words[this->num_words - 1];
|
||||
size_t size = m_num_words * sizeof(Word);
|
||||
const Word last = m_words[m_num_words - 1];
|
||||
AMS_ASSERT(last != 0);
|
||||
if (last >= 0x01000000u) {
|
||||
return size - 0;
|
||||
|
@ -84,21 +84,21 @@ namespace ams::crypto::impl {
|
|||
}
|
||||
|
||||
/* Ensure we have space for the number. */
|
||||
AMS_ASSERT(src_size <= this->max_words * sizeof(Word));
|
||||
if (AMS_UNLIKELY(!(src_size <= this->max_words * sizeof(Word)))) {
|
||||
AMS_ASSERT(src_size <= m_max_words * sizeof(Word));
|
||||
if (AMS_UNLIKELY(!(src_size <= m_max_words * sizeof(Word)))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Import. */
|
||||
this->num_words = util::AlignUp(src_size, sizeof(Word)) / sizeof(Word);
|
||||
m_num_words = util::AlignUp(src_size, sizeof(Word)) / sizeof(Word);
|
||||
|
||||
ImportImpl(this->words, this->max_words, data, src_size);
|
||||
ImportImpl(m_words, m_max_words, data, src_size);
|
||||
return true;
|
||||
}
|
||||
|
||||
void BigNum::Export(void *dst, size_t dst_size) {
|
||||
AMS_ASSERT(dst_size >= this->GetSize());
|
||||
ExportImpl(static_cast<u8 *>(dst), dst_size, this->words, this->num_words);
|
||||
ExportImpl(static_cast<u8 *>(dst), dst_size, m_words, m_num_words);
|
||||
}
|
||||
|
||||
bool BigNum::ExpMod(void *dst, const void *src, size_t size, const BigNum &exp, u32 *work_buf, size_t work_buf_size) const {
|
||||
|
@ -126,7 +126,7 @@ namespace ams::crypto::impl {
|
|||
}
|
||||
|
||||
/* Perform the exponentiation. */
|
||||
if (!ExpMod(signature.words, signature.words, exp.words, exp.num_words, this->words, this->num_words, std::addressof(allocator))) {
|
||||
if (!ExpMod(signature.m_words, signature.m_words, exp.m_words, exp.m_num_words, m_words, m_num_words, std::addressof(allocator))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -138,11 +138,11 @@ namespace ams::crypto::impl {
|
|||
}
|
||||
|
||||
void BigNum::ClearToZero() {
|
||||
std::memset(this->words, 0, this->num_words * sizeof(Word));
|
||||
std::memset(m_words, 0, m_num_words * sizeof(Word));
|
||||
}
|
||||
|
||||
void BigNum::UpdateCount() {
|
||||
this->num_words = CountWords(this->words, this->max_words);
|
||||
m_num_words = CountWords(m_words, m_max_words);
|
||||
}
|
||||
|
||||
}
|
|
@ -89,7 +89,7 @@ namespace ams::crypto::impl {
|
|||
template<>
|
||||
void CtrModeImpl<AesEncryptor128>::ProcessBlocks(u8 *dst, const u8 *src, size_t num_blocks) {
|
||||
/* Preload all round keys + iv into neon registers. */
|
||||
const u8 *keys = this->block_cipher->GetRoundKey();
|
||||
const u8 *keys = m_block_cipher->GetRoundKey();
|
||||
DECLARE_ROUND_KEY_VAR(0);
|
||||
DECLARE_ROUND_KEY_VAR(1);
|
||||
DECLARE_ROUND_KEY_VAR(2);
|
||||
|
@ -101,7 +101,7 @@ namespace ams::crypto::impl {
|
|||
DECLARE_ROUND_KEY_VAR(8);
|
||||
DECLARE_ROUND_KEY_VAR(9);
|
||||
DECLARE_ROUND_KEY_VAR(10);
|
||||
uint8x16_t ctr0 = vld1q_u8(this->counter);
|
||||
uint8x16_t ctr0 = vld1q_u8(m_counter);
|
||||
uint64_t high, low;
|
||||
|
||||
/* Process three blocks at a time, when possible. */
|
||||
|
@ -237,13 +237,13 @@ namespace ams::crypto::impl {
|
|||
num_blocks--;
|
||||
}
|
||||
|
||||
vst1q_u8(this->counter, ctr0);
|
||||
vst1q_u8(m_counter, ctr0);
|
||||
}
|
||||
|
||||
template<>
|
||||
void CtrModeImpl<AesEncryptor192>::ProcessBlocks(u8 *dst, const u8 *src, size_t num_blocks) {
|
||||
/* Preload all round keys + iv into neon registers. */
|
||||
const u8 *keys = this->block_cipher->GetRoundKey();
|
||||
const u8 *keys = m_block_cipher->GetRoundKey();
|
||||
DECLARE_ROUND_KEY_VAR(0);
|
||||
DECLARE_ROUND_KEY_VAR(1);
|
||||
DECLARE_ROUND_KEY_VAR(2);
|
||||
|
@ -257,7 +257,7 @@ namespace ams::crypto::impl {
|
|||
DECLARE_ROUND_KEY_VAR(10);
|
||||
DECLARE_ROUND_KEY_VAR(11);
|
||||
DECLARE_ROUND_KEY_VAR(12);
|
||||
uint8x16_t ctr0 = vld1q_u8(this->counter);
|
||||
uint8x16_t ctr0 = vld1q_u8(m_counter);
|
||||
uint64_t high, low;
|
||||
|
||||
/* Process three blocks at a time, when possible. */
|
||||
|
@ -401,13 +401,13 @@ namespace ams::crypto::impl {
|
|||
num_blocks--;
|
||||
}
|
||||
|
||||
vst1q_u8(this->counter, ctr0);
|
||||
vst1q_u8(m_counter, ctr0);
|
||||
}
|
||||
|
||||
template<>
|
||||
void CtrModeImpl<AesEncryptor256>::ProcessBlocks(u8 *dst, const u8 *src, size_t num_blocks) {
|
||||
/* Preload all round keys + iv into neon registers. */
|
||||
const u8 *keys = this->block_cipher->GetRoundKey();
|
||||
const u8 *keys = m_block_cipher->GetRoundKey();
|
||||
DECLARE_ROUND_KEY_VAR(0);
|
||||
DECLARE_ROUND_KEY_VAR(1);
|
||||
DECLARE_ROUND_KEY_VAR(2);
|
||||
|
@ -423,7 +423,7 @@ namespace ams::crypto::impl {
|
|||
DECLARE_ROUND_KEY_VAR(12);
|
||||
DECLARE_ROUND_KEY_VAR(13);
|
||||
DECLARE_ROUND_KEY_VAR(14);
|
||||
uint8x16_t ctr0 = vld1q_u8(this->counter);
|
||||
uint8x16_t ctr0 = vld1q_u8(m_counter);
|
||||
uint64_t high, low;
|
||||
|
||||
/* Process three blocks at a time, when possible. */
|
||||
|
@ -576,7 +576,7 @@ namespace ams::crypto::impl {
|
|||
num_blocks--;
|
||||
}
|
||||
|
||||
vst1q_u8(this->counter, ctr0);
|
||||
vst1q_u8(m_counter, ctr0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -108,96 +108,96 @@ namespace ams::crypto::impl {
|
|||
template<class BlockCipher>
|
||||
void GcmModeImpl<BlockCipher>::Initialize(const BlockCipher *block_cipher) {
|
||||
/* Set member variables. */
|
||||
this->block_cipher = block_cipher;
|
||||
this->cipher_func = std::addressof(GcmModeImpl<BlockCipher>::ProcessBlock);
|
||||
m_block_cipher = block_cipher;
|
||||
m_cipher_func = std::addressof(GcmModeImpl<BlockCipher>::ProcessBlock);
|
||||
|
||||
/* Pre-calculate values to speed up galois field multiplications later. */
|
||||
this->InitializeHashKey();
|
||||
|
||||
/* Note that we're initialized. */
|
||||
this->state = State_Initialized;
|
||||
m_state = State_Initialized;
|
||||
}
|
||||
|
||||
template<class BlockCipher>
|
||||
void GcmModeImpl<BlockCipher>::Reset(const void *iv, size_t iv_size) {
|
||||
/* Validate pre-conditions. */
|
||||
AMS_ASSERT(this->state >= State_Initialized);
|
||||
AMS_ASSERT(m_state >= State_Initialized);
|
||||
|
||||
/* Reset blocks. */
|
||||
this->block_x.block_128.Clear();
|
||||
this->block_tmp.block_128.Clear();
|
||||
m_block_x.block_128.Clear();
|
||||
m_block_tmp.block_128.Clear();
|
||||
|
||||
/* Clear sizes. */
|
||||
this->aad_size = 0;
|
||||
this->msg_size = 0;
|
||||
this->aad_remaining = 0;
|
||||
this->msg_remaining = 0;
|
||||
m_aad_size = 0;
|
||||
m_msg_size = 0;
|
||||
m_aad_remaining = 0;
|
||||
m_msg_remaining = 0;
|
||||
|
||||
/* Update our state. */
|
||||
this->state = State_ProcessingAad;
|
||||
m_state = State_ProcessingAad;
|
||||
|
||||
/* Set our iv. */
|
||||
if (iv_size == 12) {
|
||||
/* If our iv is the correct size, simply copy in the iv, and set the magic bit. */
|
||||
std::memcpy(std::addressof(this->block_ek0), iv, iv_size);
|
||||
util::StoreBigEndian(this->block_ek0.block_32 + 3, static_cast<u32>(1));
|
||||
std::memcpy(std::addressof(m_block_ek0), iv, iv_size);
|
||||
util::StoreBigEndian(m_block_ek0.block_32 + 3, static_cast<u32>(1));
|
||||
} else {
|
||||
/* Clear our ek0 block. */
|
||||
this->block_ek0.block_128.Clear();
|
||||
m_block_ek0.block_128.Clear();
|
||||
|
||||
/* Update using the iv as aad. */
|
||||
this->UpdateAad(iv, iv_size);
|
||||
|
||||
/* Treat the iv as fake msg for the mac that will become our iv. */
|
||||
this->msg_size = this->aad_size;
|
||||
this->aad_size = 0;
|
||||
m_msg_size = m_aad_size;
|
||||
m_aad_size = 0;
|
||||
|
||||
/* Compute a non-final mac. */
|
||||
this->ComputeMac(false);
|
||||
|
||||
/* Set our ek0 block to our calculated mac block. */
|
||||
this->block_ek0 = this->block_x;
|
||||
m_block_ek0 = m_block_x;
|
||||
|
||||
/* Clear our calculated mac block. */
|
||||
this->block_x.block_128.Clear();
|
||||
m_block_x.block_128.Clear();
|
||||
|
||||
/* Reset our state. */
|
||||
this->msg_size = 0;
|
||||
this->aad_size = 0;
|
||||
this->msg_remaining = 0;
|
||||
this->aad_remaining = 0;
|
||||
m_msg_size = 0;
|
||||
m_aad_size = 0;
|
||||
m_msg_remaining = 0;
|
||||
m_aad_remaining = 0;
|
||||
}
|
||||
|
||||
/* Set the working block to the iv. */
|
||||
this->block_ek = this->block_ek0;
|
||||
m_block_ek = m_block_ek0;
|
||||
}
|
||||
|
||||
template<class BlockCipher>
|
||||
void GcmModeImpl<BlockCipher>::UpdateAad(const void *aad, size_t aad_size) {
|
||||
/* Validate pre-conditions. */
|
||||
AMS_ASSERT(this->state == State_ProcessingAad);
|
||||
AMS_ASSERT(this->msg_size == 0);
|
||||
AMS_ASSERT(m_state == State_ProcessingAad);
|
||||
AMS_ASSERT(m_msg_size == 0);
|
||||
|
||||
/* Update our aad size. */
|
||||
this->aad_size += aad_size;
|
||||
m_aad_size += aad_size;
|
||||
|
||||
/* Define a working tracker variable. */
|
||||
const u8 *cur_aad = static_cast<const u8 *>(aad);
|
||||
|
||||
/* Process any leftover aad data from a previous invocation. */
|
||||
if (this->aad_remaining > 0) {
|
||||
if (m_aad_remaining > 0) {
|
||||
while (aad_size > 0) {
|
||||
/* Copy in a byte of the aad to our partial block. */
|
||||
this->block_x.block_8[this->aad_remaining] ^= *(cur_aad++);
|
||||
m_block_x.block_8[m_aad_remaining] ^= *(cur_aad++);
|
||||
|
||||
/* Note that we consumed a byte. */
|
||||
--aad_size;
|
||||
|
||||
/* Increment our partial block size. */
|
||||
this->aad_remaining = (this->aad_remaining + 1) % BlockSize;
|
||||
m_aad_remaining = (m_aad_remaining + 1) % BlockSize;
|
||||
|
||||
/* If we have a complete block, process it and move onward. */
|
||||
GaloisFieldMult(std::addressof(this->block_x), std::addressof(this->block_x), std::addressof(this->h_mult_blocks[0]));
|
||||
GaloisFieldMult(std::addressof(m_block_x), std::addressof(m_block_x), std::addressof(m_h_mult_blocks[0]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -205,11 +205,11 @@ namespace ams::crypto::impl {
|
|||
while (aad_size >= BlockSize) {
|
||||
/* Xor the current aad into our work block. */
|
||||
for (size_t i = 0; i < BlockSize; ++i) {
|
||||
this->block_x.block_8[i] ^= *(cur_aad++);
|
||||
m_block_x.block_8[i] ^= *(cur_aad++);
|
||||
}
|
||||
|
||||
/* Multiply the blocks in our galois field. */
|
||||
GaloisFieldMult(std::addressof(this->block_x), std::addressof(this->block_x), std::addressof(this->h_mult_blocks[0]));
|
||||
GaloisFieldMult(std::addressof(m_block_x), std::addressof(m_block_x), std::addressof(m_h_mult_blocks[0]));
|
||||
|
||||
/* Note that we've processed a block. */
|
||||
aad_size -= BlockSize;
|
||||
|
@ -218,11 +218,11 @@ namespace ams::crypto::impl {
|
|||
/* Update our state with whatever aad is left over. */
|
||||
if (aad_size > 0) {
|
||||
/* Note how much left over data we have. */
|
||||
this->aad_remaining = static_cast<u32>(aad_size);
|
||||
m_aad_remaining = static_cast<u32>(aad_size);
|
||||
|
||||
/* Xor the data in. */
|
||||
for (size_t i = 0; i < aad_size; ++i) {
|
||||
this->block_x.block_8[i] ^= *(cur_aad++);
|
||||
m_block_x.block_8[i] ^= *(cur_aad++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -234,21 +234,21 @@ namespace ams::crypto::impl {
|
|||
template<class BlockCipher>
|
||||
void GcmModeImpl<BlockCipher>::GetMac(void *dst, size_t dst_size) {
|
||||
/* Validate pre-conditions. */
|
||||
AMS_ASSERT(State_ProcessingAad <= this->state && this->state <= State_Done);
|
||||
AMS_ASSERT(State_ProcessingAad <= m_state && m_state <= State_Done);
|
||||
AMS_ASSERT(dst != nullptr);
|
||||
AMS_ASSERT(dst_size >= MacSize);
|
||||
AMS_ASSERT(this->aad_remaining == 0);
|
||||
AMS_ASSERT(this->msg_remaining == 0);
|
||||
AMS_ASSERT(m_aad_remaining == 0);
|
||||
AMS_ASSERT(m_msg_remaining == 0);
|
||||
AMS_UNUSED(dst_size);
|
||||
|
||||
/* If we haven't already done so, compute the final mac. */
|
||||
if (this->state != State_Done) {
|
||||
if (m_state != State_Done) {
|
||||
this->ComputeMac(true);
|
||||
this->state = State_Done;
|
||||
m_state = State_Done;
|
||||
}
|
||||
|
||||
static_assert(sizeof(this->block_x) == MacSize);
|
||||
std::memcpy(dst, std::addressof(this->block_x), MacSize);
|
||||
static_assert(sizeof(m_block_x) == MacSize);
|
||||
std::memcpy(dst, std::addressof(m_block_x), MacSize);
|
||||
}
|
||||
|
||||
template<class BlockCipher>
|
||||
|
@ -258,18 +258,18 @@ namespace ams::crypto::impl {
|
|||
/* to speed up galois field arithmetic. */
|
||||
constexpr const Block EmptyBlock = {};
|
||||
|
||||
this->ProcessBlock(std::addressof(this->h_mult_blocks[0]), std::addressof(EmptyBlock), this->block_cipher);
|
||||
this->ProcessBlock(std::addressof(m_h_mult_blocks[0]), std::addressof(EmptyBlock), m_block_cipher);
|
||||
}
|
||||
|
||||
template<class BlockCipher>
|
||||
void GcmModeImpl<BlockCipher>::ComputeMac(bool encrypt) {
|
||||
/* If we have leftover data, process it. */
|
||||
if (this->aad_remaining > 0 || this->msg_remaining > 0) {
|
||||
GaloisFieldMult(std::addressof(this->block_x), std::addressof(this->block_x), std::addressof(this->h_mult_blocks[0]));
|
||||
if (m_aad_remaining > 0 || m_msg_remaining > 0) {
|
||||
GaloisFieldMult(std::addressof(m_block_x), std::addressof(m_block_x), std::addressof(m_h_mult_blocks[0]));
|
||||
}
|
||||
|
||||
/* Setup the last block. */
|
||||
Block last_block = Block{ .block_128 = { this->msg_size, this->aad_size } };
|
||||
Block last_block = Block{ .block_128 = { m_msg_size, m_aad_size } };
|
||||
|
||||
/* Multiply the last block by 8 to account for bit vs byte sizes. */
|
||||
static_assert(offsetof(Block128, hi) == 0);
|
||||
|
@ -279,21 +279,21 @@ namespace ams::crypto::impl {
|
|||
|
||||
/* Xor the data in. */
|
||||
for (size_t i = 0; i < BlockSize; ++i) {
|
||||
this->block_x.block_8[BlockSize - 1 - i] ^= last_block.block_8[i];
|
||||
m_block_x.block_8[BlockSize - 1 - i] ^= last_block.block_8[i];
|
||||
}
|
||||
|
||||
/* Perform the final multiplication. */
|
||||
GaloisFieldMult(std::addressof(this->block_x), std::addressof(this->block_x), std::addressof(this->h_mult_blocks[0]));
|
||||
GaloisFieldMult(std::addressof(m_block_x), std::addressof(m_block_x), std::addressof(m_h_mult_blocks[0]));
|
||||
|
||||
/* If we need to do an encryption, do so. */
|
||||
if (encrypt) {
|
||||
/* Encrypt the iv. */
|
||||
u8 enc_result[BlockSize];
|
||||
this->ProcessBlock(enc_result, std::addressof(this->block_ek0), this->block_cipher);
|
||||
this->ProcessBlock(enc_result, std::addressof(m_block_ek0), m_block_cipher);
|
||||
|
||||
/* Xor the iv in. */
|
||||
for (size_t i = 0; i < BlockSize; ++i) {
|
||||
this->block_x.block_8[i] ^= enc_result[i];
|
||||
m_block_x.block_8[i] ^= enc_result[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,20 +20,20 @@ namespace ams::crypto::impl {
|
|||
#ifdef ATMOSPHERE_IS_STRATOSPHERE
|
||||
|
||||
void Sha1Impl::Initialize() {
|
||||
static_assert(sizeof(this->state) == sizeof(::Sha1Context));
|
||||
::sha1ContextCreate(reinterpret_cast<::Sha1Context *>(std::addressof(this->state)));
|
||||
static_assert(sizeof(m_state) == sizeof(::Sha1Context));
|
||||
::sha1ContextCreate(reinterpret_cast<::Sha1Context *>(std::addressof(m_state)));
|
||||
}
|
||||
|
||||
void Sha1Impl::Update(const void *data, size_t size) {
|
||||
static_assert(sizeof(this->state) == sizeof(::Sha1Context));
|
||||
::sha1ContextUpdate(reinterpret_cast<::Sha1Context *>(std::addressof(this->state)), data, size);
|
||||
static_assert(sizeof(m_state) == sizeof(::Sha1Context));
|
||||
::sha1ContextUpdate(reinterpret_cast<::Sha1Context *>(std::addressof(m_state)), data, size);
|
||||
}
|
||||
|
||||
void Sha1Impl::GetHash(void *dst, size_t size) {
|
||||
static_assert(sizeof(this->state) == sizeof(::Sha1Context));
|
||||
static_assert(sizeof(m_state) == sizeof(::Sha1Context));
|
||||
AMS_ASSERT(size >= HashSize);
|
||||
AMS_UNUSED(size);
|
||||
::sha1ContextGetHash(reinterpret_cast<::Sha1Context *>(std::addressof(this->state)), dst);
|
||||
::sha1ContextGetHash(reinterpret_cast<::Sha1Context *>(std::addressof(m_state)), dst);
|
||||
}
|
||||
|
||||
#else
|
||||
|
|
|
@ -20,42 +20,42 @@ namespace ams::crypto::impl {
|
|||
#ifdef ATMOSPHERE_IS_STRATOSPHERE
|
||||
|
||||
void Sha256Impl::Initialize() {
|
||||
static_assert(sizeof(this->state) == sizeof(::Sha256Context));
|
||||
::sha256ContextCreate(reinterpret_cast<::Sha256Context *>(std::addressof(this->state)));
|
||||
static_assert(sizeof(m_state) == sizeof(::Sha256Context));
|
||||
::sha256ContextCreate(reinterpret_cast<::Sha256Context *>(std::addressof(m_state)));
|
||||
}
|
||||
|
||||
void Sha256Impl::Update(const void *data, size_t size) {
|
||||
static_assert(sizeof(this->state) == sizeof(::Sha256Context));
|
||||
::sha256ContextUpdate(reinterpret_cast<::Sha256Context *>(std::addressof(this->state)), data, size);
|
||||
static_assert(sizeof(m_state) == sizeof(::Sha256Context));
|
||||
::sha256ContextUpdate(reinterpret_cast<::Sha256Context *>(std::addressof(m_state)), data, size);
|
||||
}
|
||||
|
||||
void Sha256Impl::GetHash(void *dst, size_t size) {
|
||||
static_assert(sizeof(this->state) == sizeof(::Sha256Context));
|
||||
static_assert(sizeof(m_state) == sizeof(::Sha256Context));
|
||||
AMS_ASSERT(size >= HashSize);
|
||||
AMS_UNUSED(size);
|
||||
|
||||
::sha256ContextGetHash(reinterpret_cast<::Sha256Context *>(std::addressof(this->state)), dst);
|
||||
::sha256ContextGetHash(reinterpret_cast<::Sha256Context *>(std::addressof(m_state)), dst);
|
||||
}
|
||||
|
||||
void Sha256Impl::InitializeWithContext(const Sha256Context *context) {
|
||||
static_assert(sizeof(this->state) == sizeof(::Sha256Context));
|
||||
static_assert(sizeof(m_state) == sizeof(::Sha256Context));
|
||||
|
||||
/* Copy state in from the context. */
|
||||
std::memcpy(this->state.intermediate_hash, context->intermediate_hash, sizeof(this->state.intermediate_hash));
|
||||
this->state.bits_consumed = context->bits_consumed;
|
||||
std::memcpy(m_state.intermediate_hash, context->intermediate_hash, sizeof(m_state.intermediate_hash));
|
||||
m_state.bits_consumed = context->bits_consumed;
|
||||
|
||||
/* Clear the rest of state. */
|
||||
std::memset(this->state.buffer, 0, sizeof(this->state.buffer));
|
||||
this->state.num_buffered = 0;
|
||||
this->state.finalized = false;
|
||||
std::memset(m_state.buffer, 0, sizeof(m_state.buffer));
|
||||
m_state.num_buffered = 0;
|
||||
m_state.finalized = false;
|
||||
}
|
||||
|
||||
size_t Sha256Impl::GetContext(Sha256Context *context) const {
|
||||
static_assert(sizeof(this->state) == sizeof(::Sha256Context));
|
||||
std::memcpy(context->intermediate_hash, this->state.intermediate_hash, sizeof(context->intermediate_hash));
|
||||
context->bits_consumed = this->state.bits_consumed;
|
||||
static_assert(sizeof(m_state) == sizeof(::Sha256Context));
|
||||
std::memcpy(context->intermediate_hash, m_state.intermediate_hash, sizeof(context->intermediate_hash));
|
||||
context->bits_consumed = m_state.bits_consumed;
|
||||
|
||||
return this->state.num_buffered;
|
||||
return m_state.num_buffered;
|
||||
}
|
||||
|
||||
#else
|
||||
|
|
|
@ -110,7 +110,7 @@ namespace ams::crypto::impl {
|
|||
}
|
||||
|
||||
size_t XtsModeImpl::UpdateGeneric(void *dst, size_t dst_size, const void *src, size_t src_size) {
|
||||
AMS_ASSERT(this->state == State_Initialized || this->state == State_Processing);
|
||||
AMS_ASSERT(m_state == State_Initialized || m_state == State_Processing);
|
||||
|
||||
return UpdateImpl<void>(this, dst, dst_size, src, src_size);
|
||||
}
|
||||
|
@ -118,13 +118,13 @@ namespace ams::crypto::impl {
|
|||
size_t XtsModeImpl::ProcessBlocksGeneric(u8 *dst, const u8 *src, size_t num_blocks) {
|
||||
size_t processed = BlockSize * (num_blocks - 1);
|
||||
|
||||
if (this->state == State_Processing) {
|
||||
this->ProcessBlock(dst, this->last_block);
|
||||
if (m_state == State_Processing) {
|
||||
this->ProcessBlock(dst, m_last_block);
|
||||
dst += BlockSize;
|
||||
processed += BlockSize;
|
||||
}
|
||||
|
||||
uint8x16_t tweak = vld1q_u8(this->tweak);
|
||||
uint8x16_t tweak = vld1q_u8(m_tweak);
|
||||
|
||||
while ((--num_blocks) > 0) {
|
||||
/* Xor */
|
||||
|
@ -134,7 +134,7 @@ namespace ams::crypto::impl {
|
|||
|
||||
/* Encrypt */
|
||||
vst1q_u8(dst, block);
|
||||
this->cipher_func(dst, dst, this->cipher_ctx);
|
||||
m_cipher_func(dst, dst, m_cipher_ctx);
|
||||
block = vld1q_u8(dst);
|
||||
|
||||
/* Xor */
|
||||
|
@ -146,11 +146,11 @@ namespace ams::crypto::impl {
|
|||
tweak = MultiplyTweak(tweak);
|
||||
}
|
||||
|
||||
vst1q_u8(this->tweak, tweak);
|
||||
vst1q_u8(m_tweak, tweak);
|
||||
|
||||
std::memcpy(this->last_block, src, BlockSize);
|
||||
std::memcpy(m_last_block, src, BlockSize);
|
||||
|
||||
this->state = State_Processing;
|
||||
m_state = State_Processing;
|
||||
|
||||
return processed;
|
||||
}
|
||||
|
@ -168,14 +168,14 @@ namespace ams::crypto::impl {
|
|||
/* Handle last buffered block. */
|
||||
size_t processed = (num_blocks - 1) * BlockSize;
|
||||
|
||||
if (this->state == State_Processing) {
|
||||
this->ProcessBlock(dst, this->last_block);
|
||||
if (m_state == State_Processing) {
|
||||
this->ProcessBlock(dst, m_last_block);
|
||||
dst += BlockSize;
|
||||
processed += BlockSize;
|
||||
}
|
||||
|
||||
/* Preload all round keys + iv into neon registers. */
|
||||
const u8 *keys = static_cast<const AesEncryptor128 *>(this->cipher_ctx)->GetRoundKey();
|
||||
const u8 *keys = static_cast<const AesEncryptor128 *>(m_cipher_ctx)->GetRoundKey();
|
||||
DECLARE_ROUND_KEY_VAR(0);
|
||||
DECLARE_ROUND_KEY_VAR(1);
|
||||
DECLARE_ROUND_KEY_VAR(2);
|
||||
|
@ -187,7 +187,7 @@ namespace ams::crypto::impl {
|
|||
DECLARE_ROUND_KEY_VAR(8);
|
||||
DECLARE_ROUND_KEY_VAR(9);
|
||||
DECLARE_ROUND_KEY_VAR(10);
|
||||
uint8x16_t tweak0 = vld1q_u8(this->tweak);
|
||||
uint8x16_t tweak0 = vld1q_u8(m_tweak);
|
||||
constexpr uint64_t xorv = 0x87ul;
|
||||
uint64_t high, low, mask;
|
||||
|
||||
|
@ -314,10 +314,10 @@ namespace ams::crypto::impl {
|
|||
dst += BlockSize;
|
||||
}
|
||||
|
||||
vst1q_u8(this->tweak, tweak0);
|
||||
vst1q_u8(m_tweak, tweak0);
|
||||
|
||||
std::memcpy(this->last_block, src, BlockSize);
|
||||
this->state = State_Processing;
|
||||
std::memcpy(m_last_block, src, BlockSize);
|
||||
m_state = State_Processing;
|
||||
|
||||
return processed;
|
||||
}
|
||||
|
@ -327,14 +327,14 @@ namespace ams::crypto::impl {
|
|||
/* Handle last buffered block. */
|
||||
size_t processed = (num_blocks - 1) * BlockSize;
|
||||
|
||||
if (this->state == State_Processing) {
|
||||
this->ProcessBlock(dst, this->last_block);
|
||||
if (m_state == State_Processing) {
|
||||
this->ProcessBlock(dst, m_last_block);
|
||||
dst += BlockSize;
|
||||
processed += BlockSize;
|
||||
}
|
||||
|
||||
/* Preload all round keys + iv into neon registers. */
|
||||
const u8 *keys = static_cast<const AesEncryptor192 *>(this->cipher_ctx)->GetRoundKey();
|
||||
const u8 *keys = static_cast<const AesEncryptor192 *>(m_cipher_ctx)->GetRoundKey();
|
||||
DECLARE_ROUND_KEY_VAR(0);
|
||||
DECLARE_ROUND_KEY_VAR(1);
|
||||
DECLARE_ROUND_KEY_VAR(2);
|
||||
|
@ -348,7 +348,7 @@ namespace ams::crypto::impl {
|
|||
DECLARE_ROUND_KEY_VAR(10);
|
||||
DECLARE_ROUND_KEY_VAR(11);
|
||||
DECLARE_ROUND_KEY_VAR(12);
|
||||
uint8x16_t tweak0 = vld1q_u8(this->tweak);
|
||||
uint8x16_t tweak0 = vld1q_u8(m_tweak);
|
||||
constexpr uint64_t xorv = 0x87ul;
|
||||
uint64_t high, low, mask;
|
||||
|
||||
|
@ -483,10 +483,10 @@ namespace ams::crypto::impl {
|
|||
dst += BlockSize;
|
||||
}
|
||||
|
||||
vst1q_u8(this->tweak, tweak0);
|
||||
vst1q_u8(m_tweak, tweak0);
|
||||
|
||||
std::memcpy(this->last_block, src, BlockSize);
|
||||
this->state = State_Processing;
|
||||
std::memcpy(m_last_block, src, BlockSize);
|
||||
m_state = State_Processing;
|
||||
|
||||
return processed;
|
||||
}
|
||||
|
@ -496,14 +496,14 @@ namespace ams::crypto::impl {
|
|||
/* Handle last buffered block. */
|
||||
size_t processed = (num_blocks - 1) * BlockSize;
|
||||
|
||||
if (this->state == State_Processing) {
|
||||
this->ProcessBlock(dst, this->last_block);
|
||||
if (m_state == State_Processing) {
|
||||
this->ProcessBlock(dst, m_last_block);
|
||||
dst += BlockSize;
|
||||
processed += BlockSize;
|
||||
}
|
||||
|
||||
/* Preload all round keys + iv into neon registers. */
|
||||
const u8 *keys = static_cast<const AesEncryptor256 *>(this->cipher_ctx)->GetRoundKey();
|
||||
const u8 *keys = static_cast<const AesEncryptor256 *>(m_cipher_ctx)->GetRoundKey();
|
||||
DECLARE_ROUND_KEY_VAR(0);
|
||||
DECLARE_ROUND_KEY_VAR(1);
|
||||
DECLARE_ROUND_KEY_VAR(2);
|
||||
|
@ -519,7 +519,7 @@ namespace ams::crypto::impl {
|
|||
DECLARE_ROUND_KEY_VAR(12);
|
||||
DECLARE_ROUND_KEY_VAR(13);
|
||||
DECLARE_ROUND_KEY_VAR(14);
|
||||
uint8x16_t tweak0 = vld1q_u8(this->tweak);
|
||||
uint8x16_t tweak0 = vld1q_u8(m_tweak);
|
||||
constexpr uint64_t xorv = 0x87ul;
|
||||
uint64_t high, low, mask;
|
||||
|
||||
|
@ -663,10 +663,10 @@ namespace ams::crypto::impl {
|
|||
dst += BlockSize;
|
||||
}
|
||||
|
||||
vst1q_u8(this->tweak, tweak0);
|
||||
vst1q_u8(m_tweak, tweak0);
|
||||
|
||||
std::memcpy(this->last_block, src, BlockSize);
|
||||
this->state = State_Processing;
|
||||
std::memcpy(m_last_block, src, BlockSize);
|
||||
m_state = State_Processing;
|
||||
|
||||
return processed;
|
||||
}
|
||||
|
@ -676,14 +676,14 @@ namespace ams::crypto::impl {
|
|||
/* Handle last buffered block. */
|
||||
size_t processed = (num_blocks - 1) * BlockSize;
|
||||
|
||||
if (this->state == State_Processing) {
|
||||
this->ProcessBlock(dst, this->last_block);
|
||||
if (m_state == State_Processing) {
|
||||
this->ProcessBlock(dst, m_last_block);
|
||||
dst += BlockSize;
|
||||
processed += BlockSize;
|
||||
}
|
||||
|
||||
/* Preload all round keys + iv into neon registers. */
|
||||
const u8 *keys = static_cast<const AesDecryptor128 *>(this->cipher_ctx)->GetRoundKey();
|
||||
const u8 *keys = static_cast<const AesDecryptor128 *>(m_cipher_ctx)->GetRoundKey();
|
||||
DECLARE_ROUND_KEY_VAR(0);
|
||||
DECLARE_ROUND_KEY_VAR(1);
|
||||
DECLARE_ROUND_KEY_VAR(2);
|
||||
|
@ -695,7 +695,7 @@ namespace ams::crypto::impl {
|
|||
DECLARE_ROUND_KEY_VAR(8);
|
||||
DECLARE_ROUND_KEY_VAR(9);
|
||||
DECLARE_ROUND_KEY_VAR(10);
|
||||
uint8x16_t tweak0 = vld1q_u8(this->tweak);
|
||||
uint8x16_t tweak0 = vld1q_u8(m_tweak);
|
||||
constexpr uint64_t xorv = 0x87ul;
|
||||
uint64_t high, low, mask;
|
||||
|
||||
|
@ -822,10 +822,10 @@ namespace ams::crypto::impl {
|
|||
dst += BlockSize;
|
||||
}
|
||||
|
||||
vst1q_u8(this->tweak, tweak0);
|
||||
vst1q_u8(m_tweak, tweak0);
|
||||
|
||||
std::memcpy(this->last_block, src, BlockSize);
|
||||
this->state = State_Processing;
|
||||
std::memcpy(m_last_block, src, BlockSize);
|
||||
m_state = State_Processing;
|
||||
|
||||
return processed;
|
||||
}
|
||||
|
@ -835,14 +835,14 @@ namespace ams::crypto::impl {
|
|||
/* Handle last buffered block. */
|
||||
size_t processed = (num_blocks - 1) * BlockSize;
|
||||
|
||||
if (this->state == State_Processing) {
|
||||
this->ProcessBlock(dst, this->last_block);
|
||||
if (m_state == State_Processing) {
|
||||
this->ProcessBlock(dst, m_last_block);
|
||||
dst += BlockSize;
|
||||
processed += BlockSize;
|
||||
}
|
||||
|
||||
/* Preload all round keys + iv into neon registers. */
|
||||
const u8 *keys = static_cast<const AesDecryptor192 *>(this->cipher_ctx)->GetRoundKey();
|
||||
const u8 *keys = static_cast<const AesDecryptor192 *>(m_cipher_ctx)->GetRoundKey();
|
||||
DECLARE_ROUND_KEY_VAR(0);
|
||||
DECLARE_ROUND_KEY_VAR(1);
|
||||
DECLARE_ROUND_KEY_VAR(2);
|
||||
|
@ -856,7 +856,7 @@ namespace ams::crypto::impl {
|
|||
DECLARE_ROUND_KEY_VAR(10);
|
||||
DECLARE_ROUND_KEY_VAR(11);
|
||||
DECLARE_ROUND_KEY_VAR(12);
|
||||
uint8x16_t tweak0 = vld1q_u8(this->tweak);
|
||||
uint8x16_t tweak0 = vld1q_u8(m_tweak);
|
||||
constexpr uint64_t xorv = 0x87ul;
|
||||
uint64_t high, low, mask;
|
||||
|
||||
|
@ -991,10 +991,10 @@ namespace ams::crypto::impl {
|
|||
dst += BlockSize;
|
||||
}
|
||||
|
||||
vst1q_u8(this->tweak, tweak0);
|
||||
vst1q_u8(m_tweak, tweak0);
|
||||
|
||||
std::memcpy(this->last_block, src, BlockSize);
|
||||
this->state = State_Processing;
|
||||
std::memcpy(m_last_block, src, BlockSize);
|
||||
m_state = State_Processing;
|
||||
|
||||
return processed;
|
||||
}
|
||||
|
@ -1004,14 +1004,14 @@ namespace ams::crypto::impl {
|
|||
/* Handle last buffered block. */
|
||||
size_t processed = (num_blocks - 1) * BlockSize;
|
||||
|
||||
if (this->state == State_Processing) {
|
||||
this->ProcessBlock(dst, this->last_block);
|
||||
if (m_state == State_Processing) {
|
||||
this->ProcessBlock(dst, m_last_block);
|
||||
dst += BlockSize;
|
||||
processed += BlockSize;
|
||||
}
|
||||
|
||||
/* Preload all round keys + iv into neon registers. */
|
||||
const u8 *keys = static_cast<const AesDecryptor256 *>(this->cipher_ctx)->GetRoundKey();
|
||||
const u8 *keys = static_cast<const AesDecryptor256 *>(m_cipher_ctx)->GetRoundKey();
|
||||
DECLARE_ROUND_KEY_VAR(0);
|
||||
DECLARE_ROUND_KEY_VAR(1);
|
||||
DECLARE_ROUND_KEY_VAR(2);
|
||||
|
@ -1027,7 +1027,7 @@ namespace ams::crypto::impl {
|
|||
DECLARE_ROUND_KEY_VAR(12);
|
||||
DECLARE_ROUND_KEY_VAR(13);
|
||||
DECLARE_ROUND_KEY_VAR(14);
|
||||
uint8x16_t tweak0 = vld1q_u8(this->tweak);
|
||||
uint8x16_t tweak0 = vld1q_u8(m_tweak);
|
||||
constexpr uint64_t xorv = 0x87ul;
|
||||
uint64_t high, low, mask;
|
||||
|
||||
|
@ -1171,10 +1171,10 @@ namespace ams::crypto::impl {
|
|||
dst += BlockSize;
|
||||
}
|
||||
|
||||
vst1q_u8(this->tweak, tweak0);
|
||||
vst1q_u8(m_tweak, tweak0);
|
||||
|
||||
std::memcpy(this->last_block, src, BlockSize);
|
||||
this->state = State_Processing;
|
||||
std::memcpy(m_last_block, src, BlockSize);
|
||||
m_state = State_Processing;
|
||||
|
||||
return processed;
|
||||
}
|
||||
|
|
|
@ -39,94 +39,94 @@ namespace ams::crypto::impl {
|
|||
|
||||
/* Xor. */
|
||||
for (size_t i = 0; i < BlockSize; i++) {
|
||||
tmp[i] = this->tweak[i] ^ src[i];
|
||||
tmp[i] = m_tweak[i] ^ src[i];
|
||||
}
|
||||
|
||||
/* Crypt */
|
||||
this->cipher_func(tmp, tmp, this->cipher_ctx);
|
||||
m_cipher_func(tmp, tmp, m_cipher_ctx);
|
||||
|
||||
/* Xor. */
|
||||
for (size_t i = 0; i < BlockSize; i++) {
|
||||
dst[i] = this->tweak[i] ^ tmp[i];
|
||||
dst[i] = m_tweak[i] ^ tmp[i];
|
||||
}
|
||||
|
||||
MultiplyTweakGeneric(reinterpret_cast<u64 *>(this->tweak));
|
||||
MultiplyTweakGeneric(reinterpret_cast<u64 *>(m_tweak));
|
||||
}
|
||||
|
||||
size_t XtsModeImpl::FinalizeEncryption(void *dst, size_t dst_size) {
|
||||
AMS_ASSERT(this->state == State_Processing);
|
||||
AMS_ASSERT(m_state == State_Processing);
|
||||
AMS_UNUSED(dst_size);
|
||||
|
||||
u8 *dst_u8 = static_cast<u8 *>(dst);
|
||||
size_t processed = 0;
|
||||
|
||||
if (this->num_buffered == 0) {
|
||||
this->ProcessBlock(dst_u8, this->last_block);
|
||||
if (m_num_buffered == 0) {
|
||||
this->ProcessBlock(dst_u8, m_last_block);
|
||||
processed = BlockSize;
|
||||
} else {
|
||||
this->ProcessBlock(this->last_block, this->last_block);
|
||||
this->ProcessBlock(m_last_block, m_last_block);
|
||||
|
||||
std::memcpy(this->buffer + this->num_buffered, this->last_block + this->num_buffered, BlockSize - this->num_buffered);
|
||||
std::memcpy(m_buffer + m_num_buffered, m_last_block + m_num_buffered, BlockSize - m_num_buffered);
|
||||
|
||||
this->ProcessBlock(dst_u8, this->buffer);
|
||||
this->ProcessBlock(dst_u8, m_buffer);
|
||||
|
||||
std::memcpy(dst_u8 + BlockSize, this->last_block, this->num_buffered);
|
||||
std::memcpy(dst_u8 + BlockSize, m_last_block, m_num_buffered);
|
||||
|
||||
processed = BlockSize + this->num_buffered;
|
||||
processed = BlockSize + m_num_buffered;
|
||||
}
|
||||
|
||||
this->state = State_Done;
|
||||
m_state = State_Done;
|
||||
return processed;
|
||||
}
|
||||
|
||||
size_t XtsModeImpl::FinalizeDecryption(void *dst, size_t dst_size) {
|
||||
AMS_ASSERT(this->state == State_Processing);
|
||||
AMS_ASSERT(m_state == State_Processing);
|
||||
AMS_UNUSED(dst_size);
|
||||
|
||||
u8 *dst_u8 = static_cast<u8 *>(dst);
|
||||
size_t processed = 0;
|
||||
|
||||
if (this->num_buffered == 0) {
|
||||
this->ProcessBlock(dst_u8, this->last_block);
|
||||
if (m_num_buffered == 0) {
|
||||
this->ProcessBlock(dst_u8, m_last_block);
|
||||
processed = BlockSize;
|
||||
} else {
|
||||
u8 tmp_tweak[BlockSize];
|
||||
std::memcpy(tmp_tweak, this->tweak, BlockSize);
|
||||
MultiplyTweakGeneric(reinterpret_cast<u64 *>(this->tweak));
|
||||
std::memcpy(tmp_tweak, m_tweak, BlockSize);
|
||||
MultiplyTweakGeneric(reinterpret_cast<u64 *>(m_tweak));
|
||||
|
||||
this->ProcessBlock(this->last_block, this->last_block);
|
||||
this->ProcessBlock(m_last_block, m_last_block);
|
||||
|
||||
std::memcpy(this->buffer + this->num_buffered, this->last_block + this->num_buffered, BlockSize - this->num_buffered);
|
||||
std::memcpy(m_buffer + m_num_buffered, m_last_block + m_num_buffered, BlockSize - m_num_buffered);
|
||||
|
||||
std::memcpy(this->tweak, tmp_tweak, BlockSize);
|
||||
std::memcpy(m_tweak, tmp_tweak, BlockSize);
|
||||
|
||||
this->ProcessBlock(dst_u8, this->buffer);
|
||||
this->ProcessBlock(dst_u8, m_buffer);
|
||||
|
||||
std::memcpy(dst_u8 + BlockSize, this->last_block, this->num_buffered);
|
||||
std::memcpy(dst_u8 + BlockSize, m_last_block, m_num_buffered);
|
||||
|
||||
processed = BlockSize + this->num_buffered;
|
||||
processed = BlockSize + m_num_buffered;
|
||||
}
|
||||
|
||||
this->state = State_Done;
|
||||
m_state = State_Done;
|
||||
return processed;
|
||||
}
|
||||
|
||||
size_t XtsModeImpl::ProcessPartialData(u8 *dst, const u8 *src, size_t size) {
|
||||
size_t processed = 0;
|
||||
|
||||
std::memcpy(this->buffer + this->num_buffered, src, size);
|
||||
this->num_buffered += size;
|
||||
std::memcpy(m_buffer + m_num_buffered, src, size);
|
||||
m_num_buffered += size;
|
||||
|
||||
if (this->num_buffered == BlockSize) {
|
||||
if (this->state == State_Processing) {
|
||||
this->ProcessBlock(dst, this->last_block);
|
||||
if (m_num_buffered == BlockSize) {
|
||||
if (m_state == State_Processing) {
|
||||
this->ProcessBlock(dst, m_last_block);
|
||||
processed += BlockSize;
|
||||
}
|
||||
|
||||
std::memcpy(this->last_block, this->buffer, BlockSize);
|
||||
this->num_buffered = 0;
|
||||
std::memcpy(m_last_block, m_buffer, BlockSize);
|
||||
m_num_buffered = 0;
|
||||
|
||||
this->state = State_Processing;
|
||||
m_state = State_Processing;
|
||||
}
|
||||
|
||||
return processed;
|
||||
|
@ -135,8 +135,8 @@ namespace ams::crypto::impl {
|
|||
size_t XtsModeImpl::ProcessRemainingData(u8 *dst, const u8 *src, size_t size) {
|
||||
AMS_UNUSED(dst);
|
||||
|
||||
std::memcpy(this->buffer, src, size);
|
||||
this->num_buffered = size;
|
||||
std::memcpy(m_buffer, src, size);
|
||||
m_num_buffered = size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue