diff --git a/libraries/libstratosphere/include/stratosphere/fssystem.hpp b/libraries/libstratosphere/include/stratosphere/fssystem.hpp index 926a38b7f..3e79e01b1 100644 --- a/libraries/libstratosphere/include/stratosphere/fssystem.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssystem.hpp @@ -48,4 +48,5 @@ #include #include #include +#include #include \ No newline at end of file diff --git a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_compressed_storage.hpp b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_compressed_storage.hpp index 76010163a..327087959 100644 --- a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_compressed_storage.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_compressed_storage.hpp @@ -66,6 +66,7 @@ namespace ams::fssystem { public: virtual Result QueryAppropriateOffset(s64 *out, s64 offset, s64 access_size, s64 alignment_size) override { AMS_ABORT("TODO"); + AMS_UNUSED(out, offset, access_size, alignment_size); /* return m_core.QueryAppropriateOffsetForAsynchronousAccess(out, offset, access_size, alignment_size); */ } public: @@ -74,6 +75,7 @@ namespace ams::fssystem { virtual Result GetSize(s64 *out) override { AMS_ABORT("TODO"); + AMS_UNUSED(out); /* return m_core.GetSize(out); */ } diff --git a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_compression_common.hpp b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_compression_common.hpp index 97d5fca89..b7d875a0a 100644 --- a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_compression_common.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_compression_common.hpp @@ -40,7 +40,7 @@ namespace ams::fssystem { } constexpr bool IsRandomAccessible(CompressionType type) { - return CompressionType_None; + return type == CompressionType_None; } constexpr bool IsUnknownType(CompressionType type) { diff --git a/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_sha256_hash_generator.hpp b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_sha256_hash_generator.hpp new file mode 100644 index 000000000..4d168995f --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/fssystem/fssystem_sha256_hash_generator.hpp @@ -0,0 +1,71 @@ +/* + * 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 . + */ +#pragma once +#include +#include + +namespace ams::fssystem { + + class Sha256HashGenerator final : public ::ams::fssystem::IHash256Generator, public ::ams::fs::impl::Newable { + NON_COPYABLE(Sha256HashGenerator); + NON_MOVEABLE(Sha256HashGenerator); + private: + crypto::Sha256Generator m_generator; + public: + Sha256HashGenerator() = default; + protected: + virtual void DoInitialize() override { + m_generator.Initialize(); + } + + virtual void DoUpdate(const void *data, size_t size) override { + m_generator.Update(data, size); + } + + virtual void DoGetHash(void *dst, size_t dst_size) override { + m_generator.GetHash(dst, dst_size); + } + }; + + class Sha256HashGeneratorFactory final : public IHash256GeneratorFactory, public ::ams::fs::impl::Newable { + NON_COPYABLE(Sha256HashGeneratorFactory); + NON_MOVEABLE(Sha256HashGeneratorFactory); + public: + Sha256HashGeneratorFactory() = default; + protected: + virtual std::unique_ptr DoCreate() override { + return std::unique_ptr(new Sha256HashGenerator()); + } + + virtual void DoGenerateHash(void *dst, size_t dst_size, const void *src, size_t src_size) override { + crypto::GenerateSha256Hash(dst, dst_size, src, src_size); + } + }; + + class Sha256HashGeneratorFactorySelector final : public IHash256GeneratorFactorySelector, public ::ams::fs::impl::Newable { + NON_COPYABLE(Sha256HashGeneratorFactorySelector); + NON_MOVEABLE(Sha256HashGeneratorFactorySelector); + private: + Sha256HashGeneratorFactory m_factory; + public: + Sha256HashGeneratorFactorySelector() = default; + protected: + virtual IHash256GeneratorFactory *DoGetFactory() override { + return std::addressof(m_factory); + } + }; + +} diff --git a/libraries/libstratosphere/include/stratosphere/fssystem/save/fssystem_integrity_verification_storage.hpp b/libraries/libstratosphere/include/stratosphere/fssystem/save/fssystem_integrity_verification_storage.hpp index 758e6ef8d..e7b7ced05 100644 --- a/libraries/libstratosphere/include/stratosphere/fssystem/save/fssystem_integrity_verification_storage.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssystem/save/fssystem_integrity_verification_storage.hpp @@ -82,7 +82,7 @@ namespace ams::fssystem::save { void CalcBlockHash(BlockHash *out, const void *buffer, size_t block_size, std::unique_ptr &generator) const; void CalcBlockHash(BlockHash *out, const void *buffer, std::unique_ptr &generator) const { - return this->CalcBlockHash(out, buffer, static_cast(m_verification_block_size)); + return this->CalcBlockHash(out, buffer, static_cast(m_verification_block_size), generator); } Result IsCleared(bool *is_cleared, const BlockHash &hash); diff --git a/libraries/libstratosphere/source/fs/impl/fs_hash_generator_factory_selector.cpp b/libraries/libstratosphere/source/fs/impl/fs_hash_generator_factory_selector.cpp new file mode 100644 index 000000000..3a2876212 --- /dev/null +++ b/libraries/libstratosphere/source/fs/impl/fs_hash_generator_factory_selector.cpp @@ -0,0 +1,34 @@ +/* + * 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 . + */ +#include + +namespace ams::fs::impl { + + namespace { + + constinit fssystem::Sha256HashGeneratorFactorySelector g_sha256_hash_generator_factory_selector; + + } + + fssystem::IHash256GeneratorFactorySelector *GetNcaHashGeneratorFactorySelector() { + return std::addressof(g_sha256_hash_generator_factory_selector); + } + + fssystem::IHash256GeneratorFactorySelector *GetSaveDataHashGeneratorFactorySelector() { + return std::addressof(g_sha256_hash_generator_factory_selector); + } + +} diff --git a/libraries/libstratosphere/source/fssystem/fssystem_compression_configuration.cpp b/libraries/libstratosphere/source/fssystem/fssystem_compression_configuration.cpp new file mode 100644 index 000000000..e6bbfb67e --- /dev/null +++ b/libraries/libstratosphere/source/fssystem/fssystem_compression_configuration.cpp @@ -0,0 +1,47 @@ +/* + * 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 . + */ +#include +#include "fssystem_key_slot_cache.hpp" + +namespace ams::fssystem { + + namespace { + + Result DecompressLz4(void *dst, size_t dst_size, const void *src, size_t src_size) { + R_UNLESS(util::DecompressLZ4(dst, dst_size, src, src_size) == static_cast(dst_size), fs::ResultUnexpectedInCompressedStorageC()); + return ResultSuccess(); + } + + constexpr DecompressorFunction GetNcaDecompressorFunction(CompressionType type) { + switch (type) { + case CompressionType_Lz4: + return DecompressLz4; + default: + return nullptr; + } + } + + constexpr NcaCompressionConfiguration g_nca_compression_configuration { + .get_decompressor = GetNcaDecompressorFunction, + }; + + } + + const ::ams::fssystem::NcaCompressionConfiguration *GetNcaCompressionConfiguration() { + return std::addressof(g_nca_compression_configuration); + } + +} diff --git a/libraries/libvapours/include/vapours/crypto/impl/crypto_sha1_impl.hpp b/libraries/libvapours/include/vapours/crypto/impl/crypto_sha1_impl.hpp index 1b15171ae..2bcaa4434 100644 --- a/libraries/libvapours/include/vapours/crypto/impl/crypto_sha1_impl.hpp +++ b/libraries/libvapours/include/vapours/crypto/impl/crypto_sha1_impl.hpp @@ -39,7 +39,7 @@ namespace ams::crypto::impl { private: State m_state; public: - Sha1Impl() { /* ... */ } + Sha1Impl() { m_state.finalized = false; } ~Sha1Impl() { static_assert(std::is_trivially_destructible::value); ClearMemory(std::addressof(m_state), sizeof(m_state)); diff --git a/libraries/libvapours/include/vapours/crypto/impl/crypto_sha256_impl.hpp b/libraries/libvapours/include/vapours/crypto/impl/crypto_sha256_impl.hpp index adcdf623f..4621c2d3a 100644 --- a/libraries/libvapours/include/vapours/crypto/impl/crypto_sha256_impl.hpp +++ b/libraries/libvapours/include/vapours/crypto/impl/crypto_sha256_impl.hpp @@ -44,7 +44,7 @@ namespace ams::crypto::impl { private: State m_state; public: - Sha256Impl() { /* ... */ } + Sha256Impl() { m_state.finalized = false; } ~Sha256Impl() { static_assert(std::is_trivially_destructible::value); ClearMemory(std::addressof(m_state), sizeof(m_state)); diff --git a/libraries/libvapours/include/vapours/results/fs_results.hpp b/libraries/libvapours/include/vapours/results/fs_results.hpp index 613c96327..0f30b2efa 100644 --- a/libraries/libvapours/include/vapours/results/fs_results.hpp +++ b/libraries/libvapours/include/vapours/results/fs_results.hpp @@ -284,9 +284,12 @@ namespace ams::fs { R_DEFINE_ERROR_RESULT(GameCardLogoDataCorrupted, 4781); R_DEFINE_ERROR_RANGE(Unexpected, 5000, 5999); - R_DEFINE_ERROR_RESULT(UnexpectedInAesCtrStorageA, 5315); - R_DEFINE_ERROR_RESULT(UnexpectedInAesXtsStorageA, 5316); - R_DEFINE_ERROR_RESULT(UnexpectedInFindFileSystemA, 5319); + R_DEFINE_ERROR_RESULT(UnexpectedInAesCtrStorageA, 5315); + R_DEFINE_ERROR_RESULT(UnexpectedInAesXtsStorageA, 5316); + R_DEFINE_ERROR_RESULT(UnexpectedInFindFileSystemA, 5319); + R_DEFINE_ERROR_RESULT(UnexpectedInCompressedStorageA, 5324); + R_DEFINE_ERROR_RESULT(UnexpectedInCompressedStorageB, 5325); + R_DEFINE_ERROR_RESULT(UnexpectedInCompressedStorageC, 5326); R_DEFINE_ERROR_RANGE(PreconditionViolation, 6000, 6499); R_DEFINE_ERROR_RANGE(InvalidArgument, 6001, 6199); diff --git a/libraries/libvapours/source/crypto/impl/crypto_xts_mode_impl.arch.arm64.cpp b/libraries/libvapours/source/crypto/impl/crypto_xts_mode_impl.arch.arm64.cpp index bb2306de5..165c522e4 100644 --- a/libraries/libvapours/source/crypto/impl/crypto_xts_mode_impl.arch.arm64.cpp +++ b/libraries/libvapours/source/crypto/impl/crypto_xts_mode_impl.arch.arm64.cpp @@ -21,7 +21,6 @@ namespace ams::crypto::impl { - /* Variable management macros. */ #define DECLARE_ROUND_KEY_VAR(n) \ const uint8x16_t round_key_##n = vld1q_u8(keys + (BlockSize * n))