sha256.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #pragma once
  2. #include <array>
  3. #include <cstddef>
  4. #include <span>
  5. namespace sunrise::middleware::crypto::sha256 {
  6. /** SHA-256 produces 32 bytes. */
  7. inline constexpr std::size_t kDigestSize = 32;
  8. /** One finished SHA-256 digest. */
  9. using Digest = std::array<std::byte, kDigestSize>;
  10. /**
  11. * Hashes one buffer.
  12. * @param input Bytes to hash.
  13. * @param output Receives the digest only on success.
  14. * @return True when Windows completed the hash.
  15. */
  16. [[nodiscard]] bool hash(std::span<const std::byte> input, Digest& output) noexcept;
  17. /**
  18. * Hashes two buffers as one concatenated message.
  19. * The SRP scrambling parameter is defined over a concatenation, so it needs no scratch copy.
  20. * @param first Leading bytes.
  21. * @param second Trailing bytes.
  22. * @param output Receives the digest only on success.
  23. * @return True when Windows completed the hash.
  24. */
  25. [[nodiscard]] bool hash_pair(std::span<const std::byte> first,
  26. std::span<const std::byte> second,
  27. Digest& output) noexcept;
  28. } // namespace sunrise::middleware::crypto::sha256