libxcks  0.1.0.1
md2.hpp
Go to the documentation of this file.
1 /*
2  * libxcks
3  * Copyright (C) 2022 Julien Couot
4  *
5  * This program is free software: you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13  * License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
24 #ifndef INC_MD2_HPP_6054FE3E_36EE_452D_AD68_111840350FB4
25 #define INC_MD2_HPP_6054FE3E_36EE_452D_AD68_111840350FB4
26 
27 //---------------------------------------------------------------------------
28 #include "checksumex.hpp"
29 //---------------------------------------------------------------------------
30 
31 
32 namespace libxcks
33 {
56 class MD2 final : public ChecksumEx
57 {
58  protected:
59  // State of computation between the single steps.
60  uint8_t C[16];
61  uint8_t X[48];
62 
63  int count;
64  uint8_t ibuffer[16];
65 
66  public:
70  MD2();
71 
75  void reset() override;
76 
85  uint8_t* getValue(uint8_t* buffer) const override;
86 
94  size_t getSize() const override { return 16; }
95 
102  void update(const uint8_t* buf, size_t len) override;
103 
104  protected:
109  void finish();
110 
111  public:
117  std::string getName() const override
118  {
119  return getHashName();
120  }
121 
131  ChecksumAlgoId getID() const override
132  {
133  return getIdentifier();
134  }
135 
141  static std::string getHashName()
142  {
143  return "MD2";
144  }
145 
155  static constexpr ChecksumAlgoId getIdentifier()
156  {
157  return ChecksumAlgoId::MD2;
158  }
159 
169  {
170  return new MD2();
171  }
172 };
173 //---------------------------------------------------------------------------
174 } // namespace libxcks
175 //---------------------------------------------------------------------------
176 
177 #endif // INC_MD2_HPP_6054FE3E_36EE_452D_AD68_111840350FB4
Add some utilities to Checksum class.
Computes a hash from a byte stream.
Definition: checksumex.hpp:72
Computes a checksum from a byte stream.
Definition: checksum.hpp:54
Computes the MD2 hash from a byte stream.
Definition: md2.hpp:57
MD2()
Default constructor.
Definition: md2.cpp:40
static std::string getHashName()
Returns the name of the hash algorithm.
Definition: md2.hpp:141
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
Definition: md2.hpp:155
uint8_t * getValue(uint8_t *buffer) const override
Returns the MD2 hash value in the first 20 bytes of the given address.
Definition: md2.cpp:143
uint8_t X[48]
Buffer used for computing md2 hash.
Definition: md2.hpp:61
uint8_t ibuffer[16]
Input buffer.
Definition: md2.hpp:64
void update(const uint8_t *buf, size_t len) override
Updates the MD2 hash with specified array of bytes.
Definition: md2.cpp:81
ChecksumAlgoId getID() const override
Returns an unique identifier for the checksum or the hash algorithm.
Definition: md2.hpp:131
static Checksum * getNewInstance()
Gets a new instance of this class.
Definition: md2.hpp:168
void finish()
Process the remaining bytes in the internal buffer and the usual prolog according to the standard.
Definition: md2.cpp:63
uint8_t C[16]
Buffer used for computing md2 hash.
Definition: md2.hpp:60
int count
Current size of the input buffer.
Definition: md2.hpp:63
std::string getName() const override
Returns the name of the checksum or the hash algorithm.
Definition: md2.hpp:117
void reset() override
Resets the MD2 hash to initial state of computation.
Definition: md2.cpp:50
size_t getSize() const override
Returns the minimal size to allocate in memory to store the hash with the getValue(buffer) method.
Definition: md2.hpp:94
ChecksumAlgoId
Ids of algorithms of checksums.
Definition: types.hpp:65