2023-02-08 11:04:11 +00:00
|
|
|
//
|
|
|
|
// SHA1Engine.h
|
|
|
|
//
|
|
|
|
// Library: Foundation
|
|
|
|
// Package: Crypt
|
|
|
|
// Module: SHA1Engine
|
|
|
|
//
|
|
|
|
// Definition of class SHA1Engine.
|
|
|
|
//
|
|
|
|
// Secure Hash Standard SHA-1 algorithm
|
|
|
|
// (FIPS 180-1, see http://www.itl.nist.gov/fipspubs/fip180-1.htm)
|
|
|
|
//
|
|
|
|
// Based on the public domain implementation by Peter C. Gutmann
|
|
|
|
// on 2 Sep 1992, modified by Carl Ellison to be SHA-1.
|
|
|
|
//
|
|
|
|
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
|
|
|
// and Contributors.
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef Foundation_SHA1Engine_INCLUDED
|
|
|
|
#define Foundation_SHA1Engine_INCLUDED
|
|
|
|
|
|
|
|
|
|
|
|
#include "Poco/DigestEngine.h"
|
2023-02-13 09:22:33 +00:00
|
|
|
#include "Poco/Foundation.h"
|
2023-02-08 11:04:11 +00:00
|
|
|
|
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
namespace Poco
|
|
|
|
{
|
2023-02-08 11:04:11 +00:00
|
|
|
|
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
class Foundation_API SHA1Engine : public DigestEngine
|
|
|
|
/// This class implements the SHA-1 message digest algorithm.
|
|
|
|
/// (FIPS 180-1, see http://www.itl.nist.gov/fipspubs/fip180-1.htm)
|
2023-02-08 11:04:11 +00:00
|
|
|
{
|
|
|
|
public:
|
2023-02-13 09:22:33 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
BLOCK_SIZE = 64,
|
|
|
|
DIGEST_SIZE = 20
|
|
|
|
};
|
|
|
|
|
|
|
|
SHA1Engine();
|
|
|
|
~SHA1Engine();
|
|
|
|
|
|
|
|
std::size_t digestLength() const;
|
|
|
|
void reset();
|
|
|
|
const DigestEngine::Digest & digest();
|
2023-02-08 11:04:11 +00:00
|
|
|
|
|
|
|
protected:
|
2023-02-13 09:22:33 +00:00
|
|
|
void updateImpl(const void * data, std::size_t length);
|
2023-02-08 11:04:11 +00:00
|
|
|
|
|
|
|
private:
|
2023-02-13 09:22:33 +00:00
|
|
|
void transform();
|
|
|
|
static void byteReverse(UInt32 * buffer, int byteCount);
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
typedef UInt8 BYTE;
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
struct Context
|
|
|
|
{
|
|
|
|
UInt32 digest[5]; // Message digest
|
|
|
|
UInt32 countLo; // 64-bit bit count
|
|
|
|
UInt32 countHi;
|
|
|
|
UInt32 data[16]; // SHA data buffer
|
|
|
|
UInt32 slop; // # of bytes saved in data[]
|
|
|
|
};
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
Context _context;
|
|
|
|
DigestEngine::Digest _digest;
|
2023-02-08 11:04:11 +00:00
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
SHA1Engine(const SHA1Engine &);
|
|
|
|
SHA1Engine & operator=(const SHA1Engine &);
|
2023-02-08 11:04:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace Poco
|
|
|
|
|
|
|
|
|
|
|
|
#endif // Foundation_SHA1Engine_INCLUDED
|