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 | |
22 | |
23 | #ifndef Foundation_SHA1Engine_INCLUDED |
24 | #define Foundation_SHA1Engine_INCLUDED |
25 | |
26 | |
27 | #include "Poco/Foundation.h" |
28 | #include "Poco/DigestEngine.h" |
29 | |
30 | |
31 | namespace Poco { |
32 | |
33 | |
34 | class Foundation_API SHA1Engine: public DigestEngine |
35 | /// This class implements the SHA-1 message digest algorithm. |
36 | /// (FIPS 180-1, see http://www.itl.nist.gov/fipspubs/fip180-1.htm) |
37 | { |
38 | public: |
39 | enum |
40 | { |
41 | BLOCK_SIZE = 64, |
42 | DIGEST_SIZE = 20 |
43 | }; |
44 | |
45 | SHA1Engine(); |
46 | ~SHA1Engine(); |
47 | |
48 | std::size_t digestLength() const; |
49 | void reset(); |
50 | const DigestEngine::Digest& digest(); |
51 | |
52 | protected: |
53 | void updateImpl(const void* data, std::size_t length); |
54 | |
55 | private: |
56 | void transform(); |
57 | static void byteReverse(UInt32* buffer, int byteCount); |
58 | |
59 | typedef UInt8 BYTE; |
60 | |
61 | struct Context |
62 | { |
63 | UInt32 digest[5]; // Message digest |
64 | UInt32 countLo; // 64-bit bit count |
65 | UInt32 countHi; |
66 | UInt32 data[16]; // SHA data buffer |
67 | UInt32 slop; // # of bytes saved in data[] |
68 | }; |
69 | |
70 | Context _context; |
71 | DigestEngine::Digest _digest; |
72 | |
73 | SHA1Engine(const SHA1Engine&); |
74 | SHA1Engine& operator = (const SHA1Engine&); |
75 | }; |
76 | |
77 | |
78 | } // namespace Poco |
79 | |
80 | |
81 | #endif // Foundation_SHA1Engine_INCLUDED |
82 | |