1 | // |
---|
2 | // SHA1Engine.h |
---|
3 | // |
---|
4 | // $Id: //poco/1.3/Foundation/include/Poco/SHA1Engine.h#2 $ |
---|
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 | // Permission is hereby granted, free of charge, to any person or organization |
---|
22 | // obtaining a copy of the software and accompanying documentation covered by |
---|
23 | // this license (the "Software") to use, reproduce, display, distribute, |
---|
24 | // execute, and transmit the Software, and to prepare derivative works of the |
---|
25 | // Software, and to permit third-parties to whom the Software is furnished to |
---|
26 | // do so, all subject to the following: |
---|
27 | // |
---|
28 | // The copyright notices in the Software and this entire statement, including |
---|
29 | // the above license grant, this restriction and the following disclaimer, |
---|
30 | // must be included in all copies of the Software, in whole or in part, and |
---|
31 | // all derivative works of the Software, unless such copies or derivative |
---|
32 | // works are solely in the form of machine-executable object code generated by |
---|
33 | // a source language processor. |
---|
34 | // |
---|
35 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
36 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
37 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT |
---|
38 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE |
---|
39 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, |
---|
40 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
41 | // DEALINGS IN THE SOFTWARE. |
---|
42 | // |
---|
43 | |
---|
44 | |
---|
45 | #ifndef Foundation_SHA1Engine_INCLUDED |
---|
46 | #define Foundation_SHA1Engine_INCLUDED |
---|
47 | |
---|
48 | |
---|
49 | #include "Poco/Foundation.h" |
---|
50 | #include "Poco/DigestEngine.h" |
---|
51 | |
---|
52 | |
---|
53 | namespace Poco { |
---|
54 | |
---|
55 | |
---|
56 | class Foundation_API SHA1Engine: public DigestEngine |
---|
57 | /// This class implementes the SHA-1 message digest algorithm. |
---|
58 | /// (FIPS 180-1, see http://www.itl.nist.gov/fipspubs/fip180-1.htm) |
---|
59 | { |
---|
60 | public: |
---|
61 | enum |
---|
62 | { |
---|
63 | BLOCK_SIZE = 64, |
---|
64 | DIGEST_SIZE = 20 |
---|
65 | }; |
---|
66 | |
---|
67 | SHA1Engine(); |
---|
68 | ~SHA1Engine(); |
---|
69 | |
---|
70 | unsigned digestLength() const; |
---|
71 | void reset(); |
---|
72 | const DigestEngine::Digest& digest(); |
---|
73 | |
---|
74 | protected: |
---|
75 | void updateImpl(const void* data, unsigned length); |
---|
76 | |
---|
77 | private: |
---|
78 | void transform(); |
---|
79 | static void byteReverse(UInt32* buffer, int byteCount); |
---|
80 | |
---|
81 | typedef UInt8 BYTE; |
---|
82 | |
---|
83 | struct Context |
---|
84 | { |
---|
85 | UInt32 digest[5]; // Message digest |
---|
86 | UInt32 countLo; // 64-bit bit count |
---|
87 | UInt32 countHi; |
---|
88 | UInt32 data[16]; // SHA data buffer |
---|
89 | UInt32 slop; // # of bytes saved in data[] |
---|
90 | }; |
---|
91 | |
---|
92 | Context _context; |
---|
93 | DigestEngine::Digest _digest; |
---|
94 | |
---|
95 | SHA1Engine(const SHA1Engine&); |
---|
96 | SHA1Engine& operator = (const SHA1Engine&); |
---|
97 | }; |
---|
98 | |
---|
99 | |
---|
100 | } // namespace Poco |
---|
101 | |
---|
102 | |
---|
103 | #endif // Foundation_SHA1Engine_INCLUDED |
---|