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 | |
39 | |
40 | #ifndef Foundation_MD5Engine_INCLUDED |
41 | #define Foundation_MD5Engine_INCLUDED |
42 | |
43 | |
44 | #include "Poco/Foundation.h" |
45 | #include "Poco/DigestEngine.h" |
46 | |
47 | |
48 | namespace Poco { |
49 | |
50 | |
51 | class Foundation_API MD5Engine: public DigestEngine |
52 | /// This class implements the MD5 message digest algorithm, |
53 | /// described in RFC 1321. |
54 | { |
55 | public: |
56 | enum |
57 | { |
58 | BLOCK_SIZE = 64, |
59 | DIGEST_SIZE = 16 |
60 | }; |
61 | |
62 | MD5Engine(); |
63 | ~MD5Engine(); |
64 | |
65 | std::size_t digestLength() const; |
66 | void reset(); |
67 | const DigestEngine::Digest& digest(); |
68 | |
69 | protected: |
70 | void updateImpl(const void* data, std::size_t length); |
71 | |
72 | private: |
73 | static void transform(UInt32 state[4], const unsigned char block[64]); |
74 | static void encode(unsigned char* output, const UInt32* input, std::size_t len); |
75 | static void decode(UInt32* output, const unsigned char* input, std::size_t len); |
76 | |
77 | struct Context |
78 | { |
79 | UInt32 state[4]; // state (ABCD) |
80 | UInt32 count[2]; // number of bits, modulo 2^64 (lsb first) |
81 | unsigned char buffer[64]; // input buffer |
82 | }; |
83 | |
84 | Context _context; |
85 | DigestEngine::Digest _digest; |
86 | |
87 | MD5Engine(const MD5Engine&); |
88 | MD5Engine& operator = (const MD5Engine&); |
89 | }; |
90 | |
91 | |
92 | } // namespace Poco |
93 | |
94 | |
95 | #endif // Foundation_MD5Engine_INCLUDED |
96 | |