sha1.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/beast
  8. //
  9. #ifndef BOOST_BEAST_DETAIL_SHA1_HPP
  10. #define BOOST_BEAST_DETAIL_SHA1_HPP
  11. #include <boost/beast/core/detail/config.hpp>
  12. #include <cstdint>
  13. #include <cstddef>
  14. // Based on https://github.com/vog/sha1
  15. /*
  16. Original authors:
  17. Steve Reid (Original C Code)
  18. Bruce Guenter (Small changes to fit into bglibs)
  19. Volker Grabsch (Translation to simpler C++ Code)
  20. Eugene Hopkinson (Safety improvements)
  21. Vincent Falco (beast adaptation)
  22. */
  23. namespace boost {
  24. namespace beast {
  25. namespace detail {
  26. namespace sha1 {
  27. static std::size_t constexpr BLOCK_INTS = 16;
  28. static std::size_t constexpr BLOCK_BYTES = 64;
  29. static std::size_t constexpr DIGEST_BYTES = 20;
  30. } // sha1
  31. struct sha1_context
  32. {
  33. static unsigned int constexpr block_size = sha1::BLOCK_BYTES;
  34. static unsigned int constexpr digest_size = 20;
  35. std::size_t buflen;
  36. std::size_t blocks;
  37. std::uint32_t digest[5];
  38. std::uint8_t buf[block_size];
  39. };
  40. BOOST_BEAST_DECL
  41. void
  42. init(sha1_context& ctx) noexcept;
  43. BOOST_BEAST_DECL
  44. void
  45. update(
  46. sha1_context& ctx,
  47. void const* message,
  48. std::size_t size) noexcept;
  49. BOOST_BEAST_DECL
  50. void
  51. finish(
  52. sha1_context& ctx,
  53. void* digest) noexcept;
  54. } // detail
  55. } // beast
  56. } // boost
  57. #ifdef BOOST_BEAST_HEADER_ONLY
  58. #include <boost/beast/core/detail/sha1.ipp>
  59. #endif
  60. #endif