1 //
2 // SHA2Engine.h
3 //
4 // Library: Foundation
5 // Package: Crypt
6 // Module:  SHA2Engine
7 //
8 // Definition of class SHA2Engine.
9 //
10 // Secure Hash Standard SHA-2 algorithm
11 // (FIPS 180-4, see http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf)
12 //
13 // Based on the implementation of mbed TLS (Apache 2.0)
14 // http://www.apache.org/licenses/LICENSE-2.0
15 //
16 // Copyright (c) 2017, Applied Informatics Software Engineering GmbH
17 // and Contributors.
18 //
19 // SPDX-License-Identifier:	BSL-1.0
20 //
21 
22 
23 #ifndef Foundation_SHA2Engine_INCLUDED
24 #define Foundation_SHA2Engine_INCLUDED
25 
26 
27 #include "Poco/Foundation.h"
28 #include "Poco/DigestEngine.h"
29 
30 
31 namespace Poco {
32 
33 
34 class Foundation_API SHA2Engine: public DigestEngine
35 	/// This class implements the SHA-2 message digest algorithm.
36 	/// (FIPS 180-4, see http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf)
37 {
38 public:
39 	enum ALGORITHM
40 	{
41 		SHA_224 = 224,
42 		SHA_256 = 256,
43 		SHA_384 = 384,
44 		SHA_512 = 512
45 	};
46 
47 	SHA2Engine(ALGORITHM algorithm = SHA_256);
48 	~SHA2Engine();
49 
50 	std::size_t digestLength() const;
51 	void reset();
52 	const DigestEngine::Digest& digest();
53 
54 protected:
55 	void updateImpl(const void* data, std::size_t length);
56 
57 private:
58 	void transform();
59 
60 	void* _context;
61 	ALGORITHM _algorithm;
62 	DigestEngine::Digest _digest;
63 
64 	SHA2Engine(const SHA2Engine&);
65 	SHA2Engine& operator = (const SHA2Engine&);
66 };
67 
68 
69 } // namespace Poco
70 
71 
72 #endif // Foundation_SHA2Engine_INCLUDED
73