SHA1Engine.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // SHA1Engine.h
  3. //
  4. // Library: Foundation
  5. // Package: Crypt
  6. // Module: SHA1Engine
  7. //
  8. // Definition of class SHA1Engine.
  9. //
  10. // Secure Hash Standard SHA-1 algorithm
  11. // (FIPS 180-1, see http://www.itl.nist.gov/fipspubs/fip180-1.htm)
  12. //
  13. // Based on the public domain implementation by Peter C. Gutmann
  14. // on 2 Sep 1992, modified by Carl Ellison to be SHA-1.
  15. //
  16. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  17. // and Contributors.
  18. //
  19. // SPDX-License-Identifier: BSL-1.0
  20. //
  21. #ifndef Foundation_SHA1Engine_INCLUDED
  22. #define Foundation_SHA1Engine_INCLUDED
  23. #include "Poco/Foundation.h"
  24. #include "Poco/DigestEngine.h"
  25. namespace Poco {
  26. class Foundation_API SHA1Engine: public DigestEngine
  27. /// This class implementes the SHA-1 message digest algorithm.
  28. /// (FIPS 180-1, see http://www.itl.nist.gov/fipspubs/fip180-1.htm)
  29. {
  30. public:
  31. enum
  32. {
  33. BLOCK_SIZE = 64,
  34. DIGEST_SIZE = 20
  35. };
  36. SHA1Engine();
  37. ~SHA1Engine();
  38. std::size_t digestLength() const;
  39. void reset();
  40. const DigestEngine::Digest& digest();
  41. protected:
  42. void updateImpl(const void* data, std::size_t length);
  43. private:
  44. void transform();
  45. static void byteReverse(UInt32* buffer, int byteCount);
  46. typedef UInt8 BYTE;
  47. struct Context
  48. {
  49. UInt32 digest[5]; // Message digest
  50. UInt32 countLo; // 64-bit bit count
  51. UInt32 countHi;
  52. UInt32 data[16]; // SHA data buffer
  53. UInt32 slop; // # of bytes saved in data[]
  54. };
  55. Context _context;
  56. DigestEngine::Digest _digest;
  57. SHA1Engine(const SHA1Engine&);
  58. SHA1Engine& operator = (const SHA1Engine&);
  59. };
  60. } // namespace Poco
  61. #endif // Foundation_SHA1Engine_INCLUDED