crypto: add ability to hash data at compile time, for future diag use

This commit is contained in:
Michael Scire
2022-03-10 01:49:05 -08:00
committed by SciresM
parent 646f84bad1
commit 79b1835a2b
2 changed files with 296 additions and 0 deletions

View File

@@ -19,6 +19,7 @@
#include <vapours/assert.hpp>
#include <vapours/util.hpp>
#include <vapours/crypto/impl/crypto_sha256_impl.hpp>
#include <vapours/crypto/impl/crypto_sha256_impl_constexpr.hpp>
namespace ams::crypto {
@@ -85,4 +86,16 @@ namespace ams::crypto {
return GenerateSha256(dst, dst_size, src, src_size);
}
template<typename T, typename = typename std::enable_if<std::same_as<T, u8> || std::same_as<T, s8> || std::same_as<T, char> || std::same_as<T, unsigned char>>::type>
constexpr ALWAYS_INLINE void GenerateSha256(u8 *dst, size_t dst_size, const T *src, size_t src_size) {
if (std::is_constant_evaluated()) {
impl::Sha256CompileTimeImpl sha;
sha.Initialize();
sha.Update(src, src_size);
sha.GetHash(dst, dst_size);
} else {
return GenerateSha256(static_cast<void *>(dst), dst_size, static_cast<const void *>(src), src_size);
}
}
}