Coverage Report

Created: 2026-08-11 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/poco/Foundation/include/Poco/SHA2Engine.h
Line
Count
Source
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 = 1,
42
    SHA_256,
43
    SHA_384,
44
    SHA_512,
45
    SHA_512_224,
46
    SHA_512_256
47
  };
48
49
  SHA2Engine(ALGORITHM algorithm = SHA_256);
50
  ~SHA2Engine() override;
51
52
  std::size_t digestLength() const override;
53
  void reset() override;
54
  const DigestEngine::Digest& digest() override;
55
56
protected:
57
  void updateImpl(const void *data, std::size_t length) override;
58
59
private:
60
  void transform();
61
62
  void* _context;
63
  ALGORITHM _algorithm;
64
  DigestEngine::Digest _digest;
65
66
  SHA2Engine(const SHA2Engine&);
67
  SHA2Engine& operator = (const SHA2Engine&);
68
};
69
70
71
class Foundation_API SHA2Engine224 : public SHA2Engine
72
{
73
public:
74
  enum
75
  {
76
    BLOCK_SIZE = 64,
77
    DIGEST_SIZE = 28
78
  };
79
80
  SHA2Engine224(): Poco::SHA2Engine(Poco::SHA2Engine::ALGORITHM::SHA_224)
81
0
  {
82
0
  }
83
84
  ~SHA2Engine224() override = default;
85
};
86
87
88
class Foundation_API SHA2Engine256 : public SHA2Engine
89
{
90
public:
91
  enum
92
  {
93
    BLOCK_SIZE = 64,
94
    DIGEST_SIZE = 32
95
  };
96
97
  SHA2Engine256(): Poco::SHA2Engine(Poco::SHA2Engine::ALGORITHM::SHA_256)
98
0
  {
99
0
  }
100
101
  ~SHA2Engine256() override = default;
102
};
103
104
105
class Foundation_API SHA2Engine384 : public SHA2Engine
106
{
107
public:
108
  enum
109
  {
110
    BLOCK_SIZE = 128,
111
    DIGEST_SIZE = 48
112
  };
113
114
  SHA2Engine384(): Poco::SHA2Engine(Poco::SHA2Engine::ALGORITHM::SHA_384)
115
0
  {
116
0
  }
117
118
  ~SHA2Engine384() override = default;
119
};
120
121
122
class Foundation_API SHA2Engine512 : public SHA2Engine
123
{
124
public:
125
  enum
126
  {
127
    BLOCK_SIZE = 128,
128
    DIGEST_SIZE = 64
129
  };
130
131
  SHA2Engine512(): Poco::SHA2Engine(Poco::SHA2Engine::ALGORITHM::SHA_512)
132
0
  {
133
0
  }
134
135
  ~SHA2Engine512() override = default;
136
};
137
138
139
} // namespace Poco
140
141
142
#endif // Foundation_SHA2Engine_INCLUDED