MD5Engine.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // MD5Engine.h
  3. //
  4. // Library: Foundation
  5. // Package: Crypt
  6. // Module: MD5Engine
  7. //
  8. // Definition of class MD5Engine.
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. //
  16. // MD5 (RFC 1321) algorithm:
  17. // Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
  18. // rights reserved.
  19. //
  20. // License to copy and use this software is granted provided that it
  21. // is identified as the "RSA Data Security, Inc. MD5 Message-Digest
  22. // Algorithm" in all material mentioning or referencing this software
  23. // or this function.
  24. //
  25. // License is also granted to make and use derivative works provided
  26. // that such works are identified as "derived from the RSA Data
  27. // Security, Inc. MD5 Message-Digest Algorithm" in all material
  28. // mentioning or referencing the derived work.
  29. //
  30. // RSA Data Security, Inc. makes no representations concerning either
  31. // the merchantability of this software or the suitability of this
  32. // software for any particular purpose. It is provided "as is"
  33. // without express or implied warranty of any kind.
  34. //
  35. // These notices must be retained in any copies of any part of this
  36. // documentation and/or software.
  37. //
  38. #ifndef Foundation_MD5Engine_INCLUDED
  39. #define Foundation_MD5Engine_INCLUDED
  40. #include "Poco/Foundation.h"
  41. #include "Poco/DigestEngine.h"
  42. namespace Poco {
  43. class Foundation_API MD5Engine: public DigestEngine
  44. /// This class implementes the MD5 message digest algorithm,
  45. /// described in RFC 1321.
  46. {
  47. public:
  48. enum
  49. {
  50. BLOCK_SIZE = 64,
  51. DIGEST_SIZE = 16
  52. };
  53. MD5Engine();
  54. ~MD5Engine();
  55. std::size_t digestLength() const;
  56. void reset();
  57. const DigestEngine::Digest& digest();
  58. protected:
  59. void updateImpl(const void* data, std::size_t length);
  60. private:
  61. static void transform(UInt32 state[4], const unsigned char block[64]);
  62. static void encode(unsigned char* output, const UInt32* input, std::size_t len);
  63. static void decode(UInt32* output, const unsigned char* input, std::size_t len);
  64. struct Context
  65. {
  66. UInt32 state[4]; // state (ABCD)
  67. UInt32 count[2]; // number of bits, modulo 2^64 (lsb first)
  68. unsigned char buffer[64]; // input buffer
  69. };
  70. Context _context;
  71. DigestEngine::Digest _digest;
  72. MD5Engine(const MD5Engine&);
  73. MD5Engine& operator = (const MD5Engine&);
  74. };
  75. } // namespace Poco
  76. #endif // Foundation_MD5Engine_INCLUDED