mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-06-02 07:39:49 -04:00
fs: utilities for hac2l to print gc headers
This commit is contained in:
parent
2d984822c6
commit
c35114bacc
15 changed files with 893 additions and 3 deletions
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <vapours.hpp>
|
||||
#include "crypto_update_impl.hpp"
|
||||
|
||||
namespace ams::crypto::impl {
|
||||
|
||||
void CbcMacImpl::UpdateGeneric(const void *data, size_t size) {
|
||||
/* Check pre-conditions. */
|
||||
AMS_ASSERT(m_state == State_Initialized);
|
||||
|
||||
/* Update. */
|
||||
UpdateImpl<void>(this, data, size);
|
||||
}
|
||||
|
||||
void CbcMacImpl::ProcessBlocksGeneric(const void *data, size_t num_blocks) {
|
||||
/* If we have a block remaining, process it. */
|
||||
if (m_buffered_bytes == BlockSize) {
|
||||
this->ProcessBlock(m_buffer);
|
||||
m_buffered_bytes = 0;
|
||||
}
|
||||
|
||||
/* Process blocks. */
|
||||
const u8 *data8 = static_cast<const u8 *>(data);
|
||||
|
||||
u8 block[BlockSize];
|
||||
while ((--num_blocks) > 0) {
|
||||
for (size_t i = 0; i < BlockSize; ++i) {
|
||||
block[i] = data8[i] ^ m_mac[i];
|
||||
}
|
||||
|
||||
m_cipher_function(m_mac, block, m_cipher_context);
|
||||
|
||||
data8 += BlockSize;
|
||||
}
|
||||
|
||||
/* Process the last block. */
|
||||
std::memcpy(m_buffer, data8, BlockSize);
|
||||
m_buffered_bytes = BlockSize;
|
||||
}
|
||||
|
||||
template<>
|
||||
void CbcMacImpl::Update<AesEncryptor128>(const void *data, size_t size) {
|
||||
this->UpdateGeneric(data, size);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (c) Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <vapours.hpp>
|
||||
|
||||
namespace ams::crypto::impl {
|
||||
|
||||
void CbcMacImpl::ProcessBlock(const void *data) {
|
||||
/* Procses the block. */
|
||||
const u8 *data8 = static_cast<const u8 *>(data);
|
||||
|
||||
u8 block[BlockSize];
|
||||
for (size_t i = 0; i < BlockSize; ++i) {
|
||||
block[i] = data8[i] ^ m_mac[i];
|
||||
}
|
||||
|
||||
m_cipher_function(m_mac, block, m_cipher_context);
|
||||
}
|
||||
|
||||
void CbcMacImpl::ProcessPartialData(const void *data, size_t size) {
|
||||
/* Copy in the data. */
|
||||
std::memcpy(m_buffer + m_buffered_bytes, data, size);
|
||||
m_buffered_bytes += size;
|
||||
}
|
||||
|
||||
void CbcMacImpl::ProcessRemainingData(const void *data, size_t size) {
|
||||
/* If we have a block remaining, process it. */
|
||||
if (m_buffered_bytes == BlockSize) {
|
||||
this->ProcessBlock(m_buffer);
|
||||
m_buffered_bytes = 0;
|
||||
}
|
||||
|
||||
/* Copy the remaining data. */
|
||||
std::memcpy(m_buffer, data, size);
|
||||
m_buffered_bytes = size;
|
||||
}
|
||||
|
||||
void CbcMacImpl::GetMac(void *mac, size_t mac_size) {
|
||||
/* Check pre-conditions. */
|
||||
AMS_ASSERT(m_state == State_Initialized || m_state == State_Done);
|
||||
AMS_ASSERT(mac_size >= BlockSize);
|
||||
|
||||
/* Ensure we're done. */
|
||||
if (m_state == State_Initialized) {
|
||||
if (m_buffered_bytes == BlockSize) {
|
||||
this->ProcessBlock(m_buffer);
|
||||
m_buffered_bytes = 0;
|
||||
}
|
||||
m_state = State_Done;
|
||||
}
|
||||
|
||||
/* Copy out the mac. */
|
||||
std::memcpy(mac, m_mac, sizeof(m_mac));
|
||||
}
|
||||
|
||||
void CbcMacImpl::MaskBufferedData(const void *data, size_t size) {
|
||||
/* Check pre-conditions. */
|
||||
AMS_ASSERT(m_buffered_bytes == BlockSize);
|
||||
AMS_ASSERT(size == BlockSize);
|
||||
AMS_UNUSED(size);
|
||||
|
||||
/* Mask the data. */
|
||||
for (size_t i = 0; i < BlockSize; ++i) {
|
||||
m_buffer[i] ^= static_cast<const u8 *>(data)[i];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue