| 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 | #ifndef Foundation_SHA2Engine_INCLUDED |
| 23 | #define Foundation_SHA2Engine_INCLUDED |
| 24 | |
| 25 | #include "Poco/Foundation.h" |
| 26 | #include "Poco/DigestEngine.h" |
| 27 | |
| 28 | namespace Poco { |
| 29 | |
| 30 | |
| 31 | class Foundation_API SHA2Engine: public DigestEngine |
| 32 | /// This class implements the SHA-2 message digest algorithm. |
| 33 | /// (FIPS 180-4, see http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf) |
| 34 | { |
| 35 | public: |
| 36 | enum ALGORITHM |
| 37 | { |
| 38 | SHA_224 = 224, |
| 39 | SHA_256 = 256, |
| 40 | SHA_384 = 384, |
| 41 | SHA_512 = 512 |
| 42 | }; |
| 43 | |
| 44 | SHA2Engine(ALGORITHM algorithm = SHA_512); |
| 45 | ~SHA2Engine(); |
| 46 | |
| 47 | std::size_t digestLength() const; |
| 48 | void reset(); |
| 49 | const DigestEngine::Digest& digest(); |
| 50 | |
| 51 | protected: |
| 52 | void updateImpl(const void* data, std::size_t length); |
| 53 | |
| 54 | private: |
| 55 | void transform(); |
| 56 | |
| 57 | void* _context; |
| 58 | ALGORITHM _algorithm; |
| 59 | DigestEngine::Digest _digest; |
| 60 | |
| 61 | SHA2Engine(const SHA2Engine&); |
| 62 | SHA2Engine& operator = (const SHA2Engine&); |
| 63 | }; |
| 64 | |
| 65 | |
| 66 | } // namespace Poco |
| 67 | |
| 68 | |
| 69 | #endif // Foundation_SHA2Engine_INCLUDED |
| 70 |