SPB Git

spb/wp40_uqo

Public MIT
910 B · 30 lines cpp
1// SHA-256 (FIPS 180-4), dependency-free, for provenance hashes of inputs/artifacts.2#pragma once3#include <string>4#include <string_view>5#include <span>6#include <array>7#include <cstdint>89namespace raid {1011class Sha256 {12 public:13  Sha256();14  void update(const void* data, std::size_t len);15  void update(std::string_view s) { update(s.data(), s.size()); }16  std::array<std::uint8_t, 32> digest();17  std::string hex();18  static std::string of(std::string_view s) { Sha256 h; h.update(s); return h.hex(); }19  static std::string of_file(const std::string& path);20  template <class T> static std::string of_span(std::span<const T> x) { Sha256 h; h.update(x.data(), x.size_bytes()); return h.hex(); }21 private:22  void transform(const std::uint8_t* chunk);23  std::array<std::uint32_t, 8> h_;24  std::array<std::uint8_t, 64> buf_{};25  std::size_t buf_len_{0};26  std::uint64_t total_{0};27};2829}  // namespace raid30
Files · a9731b7fb3254b6175c7c579307f61336c22d6c8
Menu

Theme