forked from Atmosphere-NX/Atmosphere
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: update HashGeneratorFactorySelector to reflect 14.0.0
- Loading branch information
Showing
8 changed files
with
140 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 0 additions & 73 deletions
73
libraries/libstratosphere/include/stratosphere/fssystem/fssystem_sha256_hash_generator.hpp
This file was deleted.
Oops, something went wrong.
107 changes: 107 additions & 0 deletions
107
libraries/libstratosphere/include/stratosphere/fssystem/fssystem_sha_hash_generator.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* 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 { | ||
|
||
/* ACCURATE_TO_VERSION: 14.3.0.0 */ | ||
|
||
namespace impl { | ||
|
||
template<typename Traits> | ||
class ShaHashGenerator final : public ::ams::fssystem::IHash256Generator, public ::ams::fs::impl::Newable { | ||
static_assert(Traits::Generator::HashSize == IHash256Generator::HashSize); | ||
NON_COPYABLE(ShaHashGenerator); | ||
NON_MOVEABLE(ShaHashGenerator); | ||
private: | ||
Traits::Generator m_generator; | ||
public: | ||
ShaHashGenerator() = 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); | ||
} | ||
}; | ||
|
||
template<typename Traits> | ||
class ShaHashGeneratorFactory final : public IHash256GeneratorFactory, public ::ams::fs::impl::Newable { | ||
static_assert(Traits::Generator::HashSize == IHash256Generator::HashSize); | ||
NON_COPYABLE(ShaHashGeneratorFactory); | ||
NON_MOVEABLE(ShaHashGeneratorFactory); | ||
public: | ||
constexpr ShaHashGeneratorFactory() = default; | ||
protected: | ||
virtual std::unique_ptr<IHash256Generator> DoCreate() override { | ||
return std::unique_ptr<IHash256Generator>(new ShaHashGenerator<Traits>()); | ||
} | ||
|
||
virtual void DoGenerateHash(void *dst, size_t dst_size, const void *src, size_t src_size) override { | ||
Traits::Generate(dst, dst_size, src, src_size); | ||
} | ||
}; | ||
|
||
struct Sha256Traits { | ||
using Generator = crypto::Sha256Generator; | ||
|
||
static ALWAYS_INLINE void Generate(void *dst, size_t dst_size, const void *src, size_t src_size) { | ||
return crypto::GenerateSha256(dst, dst_size, src, src_size); | ||
} | ||
}; | ||
|
||
struct Sha3256Traits { | ||
using Generator = crypto::Sha3256Generator; | ||
|
||
static ALWAYS_INLINE void Generate(void *dst, size_t dst_size, const void *src, size_t src_size) { | ||
return crypto::GenerateSha3256(dst, dst_size, src, src_size); | ||
} | ||
}; | ||
} | ||
|
||
using Sha256HashGenerator = impl::ShaHashGenerator<impl::Sha256Traits>; | ||
using Sha256HashGeneratorFactory = impl::ShaHashGeneratorFactory<impl::Sha256Traits>; | ||
|
||
using Sha3256HashGenerator = impl::ShaHashGenerator<impl::Sha3256Traits>; | ||
using Sha3256HashGeneratorFactory = impl::ShaHashGeneratorFactory<impl::Sha3256Traits>; | ||
|
||
class ShaHashGeneratorFactorySelector final : public IHash256GeneratorFactorySelector, public ::ams::fs::impl::Newable { | ||
NON_COPYABLE(ShaHashGeneratorFactorySelector); | ||
NON_MOVEABLE(ShaHashGeneratorFactorySelector); | ||
private: | ||
Sha256HashGeneratorFactory m_sha256_factory; | ||
Sha3256HashGeneratorFactory m_sha3_256_factory; | ||
public: | ||
constexpr ShaHashGeneratorFactorySelector() = default; | ||
protected: | ||
virtual IHash256GeneratorFactory *DoGetFactory(HashAlgorithmType alg) override { | ||
switch (alg) { | ||
case HashAlgorithmType_Sha2: return std::addressof(m_sha256_factory); | ||
case HashAlgorithmType_Sha3: return std::addressof(m_sha3_256_factory); | ||
AMS_UNREACHABLE_DEFAULT_CASE(); | ||
} | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters