mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-12-01 02:37:27 +01:00
fs: add Sha256HashGenerator, LZ4 decompressor
This commit is contained in:
parent
a2aec363d7
commit
01f7f567b9
@ -48,4 +48,5 @@
|
|||||||
#include <stratosphere/fssystem/save/fssystem_buffered_storage.hpp>
|
#include <stratosphere/fssystem/save/fssystem_buffered_storage.hpp>
|
||||||
#include <stratosphere/fssystem/save/fssystem_hierarchical_integrity_verification_storage.hpp>
|
#include <stratosphere/fssystem/save/fssystem_hierarchical_integrity_verification_storage.hpp>
|
||||||
#include <stratosphere/fssystem/fssystem_integrity_romfs_storage.hpp>
|
#include <stratosphere/fssystem/fssystem_integrity_romfs_storage.hpp>
|
||||||
|
#include <stratosphere/fssystem/fssystem_sha256_hash_generator.hpp>
|
||||||
#include <stratosphere/fssystem/fssystem_file_system_proxy_api.hpp>
|
#include <stratosphere/fssystem/fssystem_file_system_proxy_api.hpp>
|
@ -66,6 +66,7 @@ namespace ams::fssystem {
|
|||||||
public:
|
public:
|
||||||
virtual Result QueryAppropriateOffset(s64 *out, s64 offset, s64 access_size, s64 alignment_size) override {
|
virtual Result QueryAppropriateOffset(s64 *out, s64 offset, s64 access_size, s64 alignment_size) override {
|
||||||
AMS_ABORT("TODO");
|
AMS_ABORT("TODO");
|
||||||
|
AMS_UNUSED(out, offset, access_size, alignment_size);
|
||||||
/* return m_core.QueryAppropriateOffsetForAsynchronousAccess(out, offset, access_size, alignment_size); */
|
/* return m_core.QueryAppropriateOffsetForAsynchronousAccess(out, offset, access_size, alignment_size); */
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
@ -74,6 +75,7 @@ namespace ams::fssystem {
|
|||||||
|
|
||||||
virtual Result GetSize(s64 *out) override {
|
virtual Result GetSize(s64 *out) override {
|
||||||
AMS_ABORT("TODO");
|
AMS_ABORT("TODO");
|
||||||
|
AMS_UNUSED(out);
|
||||||
/* return m_core.GetSize(out); */
|
/* return m_core.GetSize(out); */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ namespace ams::fssystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool IsRandomAccessible(CompressionType type) {
|
constexpr bool IsRandomAccessible(CompressionType type) {
|
||||||
return CompressionType_None;
|
return type == CompressionType_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool IsUnknownType(CompressionType type) {
|
constexpr bool IsUnknownType(CompressionType type) {
|
||||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include <vapours.hpp>
|
||||||
|
#include <stratosphere/fssystem/fssystem_i_hash_256_generator.hpp>
|
||||||
|
|
||||||
|
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<IHash256Generator> DoCreate() override {
|
||||||
|
return std::unique_ptr<IHash256Generator>(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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
@ -82,7 +82,7 @@ namespace ams::fssystem::save {
|
|||||||
void CalcBlockHash(BlockHash *out, const void *buffer, size_t block_size, std::unique_ptr<fssystem::IHash256Generator> &generator) const;
|
void CalcBlockHash(BlockHash *out, const void *buffer, size_t block_size, std::unique_ptr<fssystem::IHash256Generator> &generator) const;
|
||||||
|
|
||||||
void CalcBlockHash(BlockHash *out, const void *buffer, std::unique_ptr<fssystem::IHash256Generator> &generator) const {
|
void CalcBlockHash(BlockHash *out, const void *buffer, std::unique_ptr<fssystem::IHash256Generator> &generator) const {
|
||||||
return this->CalcBlockHash(out, buffer, static_cast<size_t>(m_verification_block_size));
|
return this->CalcBlockHash(out, buffer, static_cast<size_t>(m_verification_block_size), generator);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result IsCleared(bool *is_cleared, const BlockHash &hash);
|
Result IsCleared(bool *is_cleared, const BlockHash &hash);
|
||||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include <stratosphere.hpp>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include <stratosphere.hpp>
|
||||||
|
#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<int>(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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -39,7 +39,7 @@ namespace ams::crypto::impl {
|
|||||||
private:
|
private:
|
||||||
State m_state;
|
State m_state;
|
||||||
public:
|
public:
|
||||||
Sha1Impl() { /* ... */ }
|
Sha1Impl() { m_state.finalized = false; }
|
||||||
~Sha1Impl() {
|
~Sha1Impl() {
|
||||||
static_assert(std::is_trivially_destructible<State>::value);
|
static_assert(std::is_trivially_destructible<State>::value);
|
||||||
ClearMemory(std::addressof(m_state), sizeof(m_state));
|
ClearMemory(std::addressof(m_state), sizeof(m_state));
|
||||||
|
@ -44,7 +44,7 @@ namespace ams::crypto::impl {
|
|||||||
private:
|
private:
|
||||||
State m_state;
|
State m_state;
|
||||||
public:
|
public:
|
||||||
Sha256Impl() { /* ... */ }
|
Sha256Impl() { m_state.finalized = false; }
|
||||||
~Sha256Impl() {
|
~Sha256Impl() {
|
||||||
static_assert(std::is_trivially_destructible<State>::value);
|
static_assert(std::is_trivially_destructible<State>::value);
|
||||||
ClearMemory(std::addressof(m_state), sizeof(m_state));
|
ClearMemory(std::addressof(m_state), sizeof(m_state));
|
||||||
|
@ -287,6 +287,9 @@ namespace ams::fs {
|
|||||||
R_DEFINE_ERROR_RESULT(UnexpectedInAesCtrStorageA, 5315);
|
R_DEFINE_ERROR_RESULT(UnexpectedInAesCtrStorageA, 5315);
|
||||||
R_DEFINE_ERROR_RESULT(UnexpectedInAesXtsStorageA, 5316);
|
R_DEFINE_ERROR_RESULT(UnexpectedInAesXtsStorageA, 5316);
|
||||||
R_DEFINE_ERROR_RESULT(UnexpectedInFindFileSystemA, 5319);
|
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(PreconditionViolation, 6000, 6499);
|
||||||
R_DEFINE_ERROR_RANGE(InvalidArgument, 6001, 6199);
|
R_DEFINE_ERROR_RANGE(InvalidArgument, 6001, 6199);
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
|
|
||||||
namespace ams::crypto::impl {
|
namespace ams::crypto::impl {
|
||||||
|
|
||||||
|
|
||||||
/* Variable management macros. */
|
/* Variable management macros. */
|
||||||
#define DECLARE_ROUND_KEY_VAR(n) \
|
#define DECLARE_ROUND_KEY_VAR(n) \
|
||||||
const uint8x16_t round_key_##n = vld1q_u8(keys + (BlockSize * n))
|
const uint8x16_t round_key_##n = vld1q_u8(keys + (BlockSize * n))
|
||||||
|
Loading…
Reference in New Issue
Block a user