sha1.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. // Based on https://github.com/vog/sha1
  14. /*
  15. Original authors:
  16. Steve Reid (Original C Code)
  17. Bruce Guenter (Small changes to fit into bglibs)
  18. Volker Grabsch (Translation to simpler C++ Code)
  19. Eugene Hopkinson (Safety improvements)
  20. Vincent Falco (beast adaptation)
  21. */
  22. namespace boost {
  23. namespace beast {
  24. namespace detail {
  25. namespace sha1 {
  26. static std::size_t constexpr BLOCK_INTS = 16;
  27. static std::size_t constexpr BLOCK_BYTES = 64;
  28. static std::size_t constexpr DIGEST_BYTES = 20;
  29. } // sha1
  30. struct sha1_context
  31. {
  32. static unsigned int constexpr block_size = sha1::BLOCK_BYTES;
  33. static unsigned int constexpr digest_size = 20;
  34. std::size_t buflen;
  35. std::size_t blocks;
  36. std::uint32_t digest[5];
  37. std::uint8_t buf[block_size];
  38. };
  39. BOOST_BEAST_DECL
  40. void
  41. init(sha1_context& ctx) noexcept;
  42. BOOST_BEAST_DECL
  43. void
  44. update(
  45. sha1_context& ctx,
  46. void const* message,
  47. std::size_t size) noexcept;
  48. BOOST_BEAST_DECL
  49. void
  50. finish(
  51. sha1_context& ctx,
  52. void* digest) noexcept;
  53. } // detail
  54. } // beast
  55. } // boost
  56. #ifdef BOOST_BEAST_HEADER_ONLY
  57. #include <boost/beast/core/detail/sha1.ipp>
  58. #endif
  59. #endif