50 lines
1.3 KiB
C++
50 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <Void/Crypto/Crypto.hpp>
|
|
#include <Void/Crypto/Types.hpp>
|
|
|
|
#include <cstddef>
|
|
#include <span>
|
|
|
|
namespace Void::Crypto::Detail
|
|
{
|
|
void builtin_secure_wipe(std::span<std::byte> buffer) noexcept;
|
|
|
|
[[nodiscard]] bool
|
|
builtin_constant_time_equal(std::span<const std::byte> lhs,
|
|
std::span<const std::byte> rhs) noexcept;
|
|
|
|
class BuiltinHasher
|
|
{
|
|
public:
|
|
|
|
BuiltinHasher() noexcept = default;
|
|
~BuiltinHasher() noexcept;
|
|
|
|
BuiltinHasher(BuiltinHasher&& other) noexcept;
|
|
BuiltinHasher& operator=(BuiltinHasher&& other) noexcept;
|
|
BuiltinHasher(const BuiltinHasher&) = delete;
|
|
BuiltinHasher& operator=(const BuiltinHasher&) = delete;
|
|
|
|
[[nodiscard]] bool init(HashAlgorithm algorithm) noexcept;
|
|
void update(std::span<const std::byte> data) noexcept;
|
|
[[nodiscard]] Digest finalize();
|
|
|
|
private:
|
|
|
|
struct State;
|
|
State* m_state{nullptr};
|
|
void destroy() noexcept;
|
|
};
|
|
|
|
void builtin_hmac_sha256(std::span<const std::byte> secret_key,
|
|
std::span<const std::byte> message,
|
|
std::span<std::byte> output_32) noexcept;
|
|
|
|
void builtin_hkdf_sha256(std::span<const std::byte> secret_input,
|
|
std::span<const std::byte> salt,
|
|
std::span<const std::byte> context,
|
|
std::span<std::byte> secret_output) noexcept;
|
|
|
|
} // namespace Void::Crypto::Detail
|