mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-06-05 17:14:22 -04:00
ams: fs accuracy fixes, bump to 1.3.2
This commit is contained in:
parent
d85875b910
commit
3545c0aac2
10 changed files with 57 additions and 31 deletions
|
@ -87,7 +87,11 @@ namespace ams::fssystem {
|
|||
AMS_ASSERT(decryptor != nullptr);
|
||||
|
||||
/* Initialize the bucket tree table. */
|
||||
R_TRY(m_table.Initialize(allocator, node_storage, entry_storage, NodeSize, sizeof(Entry), entry_count));
|
||||
if (entry_count > 0) {
|
||||
R_TRY(m_table.Initialize(allocator, node_storage, entry_storage, NodeSize, sizeof(Entry), entry_count));
|
||||
} else {
|
||||
m_table.Initialize(NodeSize, 0);
|
||||
}
|
||||
|
||||
/* Set members. */
|
||||
m_data_storage = data_storage;
|
||||
|
@ -174,15 +178,18 @@ namespace ams::fssystem {
|
|||
const auto cur_size = static_cast<size_t>(std::min(remaining_size, data_size));
|
||||
AMS_ASSERT(cur_size <= size);
|
||||
|
||||
/* Make the CTR for the data we're decrypting. */
|
||||
const auto counter_offset = m_counter_offset + cur_entry_offset + data_offset;
|
||||
NcaAesCtrUpperIv upper_iv = { .part = { .generation = static_cast<u32>(cur_entry.generation), .secure_value = m_secure_value } };
|
||||
/* If necessary, perform decryption. */
|
||||
if (cur_entry.encryption_value == Entry::Encryption::Encrypted) {
|
||||
/* Make the CTR for the data we're decrypting. */
|
||||
const auto counter_offset = m_counter_offset + cur_entry_offset + data_offset;
|
||||
NcaAesCtrUpperIv upper_iv = { .part = { .generation = static_cast<u32>(cur_entry.generation), .secure_value = m_secure_value } };
|
||||
|
||||
u8 iv[IvSize];
|
||||
AesCtrStorageByPointer::MakeIv(iv, IvSize, upper_iv.value, counter_offset);
|
||||
u8 iv[IvSize];
|
||||
AesCtrStorageByPointer::MakeIv(iv, IvSize, upper_iv.value, counter_offset);
|
||||
|
||||
/* Decrypt. */
|
||||
m_decryptor->Decrypt(cur_data, cur_size, m_key, KeySize, iv, IvSize);
|
||||
/* Decrypt. */
|
||||
m_decryptor->Decrypt(cur_data, cur_size, m_key, KeySize, iv, IvSize);
|
||||
}
|
||||
|
||||
/* Advance. */
|
||||
cur_data += cur_size;
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
namespace ams::fssystem {
|
||||
|
||||
Result IntegrityVerificationStorage::Initialize(fs::SubStorage hs, fs::SubStorage ds, s64 verif_block_size, s64 upper_layer_verif_block_size, fs::IBufferManager *bm, fssystem::IHash256GeneratorFactory *hgf, const util::optional<fs::HashSalt> &salt, bool is_real_data, bool is_writable, bool allow_cleared_blocks) {
|
||||
void IntegrityVerificationStorage::Initialize(fs::SubStorage hs, fs::SubStorage ds, s64 verif_block_size, s64 upper_layer_verif_block_size, fs::IBufferManager *bm, fssystem::IHash256GeneratorFactory *hgf, const util::optional<fs::HashSalt> &salt, bool is_real_data, bool is_writable, bool allow_cleared_blocks) {
|
||||
/* Validate preconditions. */
|
||||
AMS_ASSERT(verif_block_size >= HashSize);
|
||||
AMS_ASSERT(bm != nullptr);
|
||||
|
@ -61,7 +61,6 @@ namespace ams::fssystem {
|
|||
m_is_real_data = is_real_data;
|
||||
m_is_writable = is_writable;
|
||||
m_allow_cleared_blocks = allow_cleared_blocks;
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void IntegrityVerificationStorage::Finalize() {
|
||||
|
@ -120,7 +119,8 @@ namespace ams::fssystem {
|
|||
Result verify_hash_result = ResultSuccess();
|
||||
|
||||
/* Create hash generator. */
|
||||
auto generator = m_hash_generator_factory->Create();
|
||||
std::unique_ptr<IHash256Generator> generator = nullptr;
|
||||
R_TRY(m_hash_generator_factory->Create(std::addressof(generator)));
|
||||
|
||||
/* Prepare to validate the signatures. */
|
||||
const auto signature_count = size >> m_verification_block_order;
|
||||
|
@ -221,7 +221,9 @@ namespace ams::fssystem {
|
|||
PooledBuffer signature_buffer(signature_count * sizeof(BlockHash), sizeof(BlockHash));
|
||||
const auto buffer_count = std::min(signature_count, signature_buffer.GetSize() / sizeof(BlockHash));
|
||||
|
||||
auto generator = m_hash_generator_factory->Create();
|
||||
/* Create hash generator. */
|
||||
std::unique_ptr<IHash256Generator> generator = nullptr;
|
||||
R_TRY(m_hash_generator_factory->Create(std::addressof(generator)));
|
||||
|
||||
while (updated_count < signature_count) {
|
||||
const auto cur_count = std::min(buffer_count, signature_count - updated_count);
|
||||
|
@ -326,7 +328,7 @@ namespace ams::fssystem {
|
|||
R_TRY(m_hash_storage.Read(sign_offset, buf.get(), sign_size));
|
||||
|
||||
/* Clear the signature. */
|
||||
/* This sets all bytes to FF, with the verification bit cleared. */
|
||||
/* This flips all bits other than the verification bit. */
|
||||
for (auto i = 0; i < sign_size; ++i) {
|
||||
buf[i] ^= ((i + 1) % HashSize == 0 ? 0x7F : 0xFF);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue