SHA1Engine.h 1.6 KB

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