libxcks  0.1.0.1
md4.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_MD4_HPP_A048742F_00A1_4097_9B9A_B3FA4E9D013F
25 #define INC_MD4_HPP_A048742F_00A1_4097_9B9A_B3FA4E9D013F
26 
27 //---------------------------------------------------------------------------
28 #include "libgcrypthash.hpp"
29 //---------------------------------------------------------------------------
30 
31 
32 namespace libxcks
33 {
56 class MD4 final : public LibgcryptHash
57 {
58  protected:
59  // State of computation between the single steps.
60  uint32_t A;
61  uint32_t B;
62  uint32_t C;
63  uint32_t D;
64 
65  uint32_t nblocks;
66  int count;
67  uint8_t ibuffer[64];
68 
69  public:
73  MD4();
74 
78  void reset() override;
79 
88  uint8_t* getValue(uint8_t* buffer) const override;
89 
97  size_t getSize() const override { return 16; }
98 
105  void update(const uint8_t* buf, size_t len) override;
106 
107  protected:
112  void finish();
113 
121  void transform(uint8_t* data);
122 
123  public:
129  std::string getName() const override
130  {
131  return getHashName();
132  }
133 
143  ChecksumAlgoId getID() const override
144  {
145  return getIdentifier();
146  }
147 
153  static std::string getHashName()
154  {
155  return "MD4";
156  }
157 
167  static constexpr ChecksumAlgoId getIdentifier()
168  {
169  return ChecksumAlgoId::MD4;
170  }
171 
181  {
182  return new MD4();
183  }
184 };
185 //---------------------------------------------------------------------------
186 } // namespace libxcks
187 //---------------------------------------------------------------------------
188 
189 #endif // INC_MD4_HPP_A048742F_00A1_4097_9B9A_B3FA4E9D013F
Computes a checksum from a byte stream.
Definition: checksum.hpp:54
Computes a hash from a byte stream.
Computes the MD4 hash from a byte stream.
Definition: md4.hpp:57
uint32_t nblocks
Number of blocks.
Definition: md4.hpp:65
void finish()
Process the remaining bytes in the internal buffer and the usual prolog according to the standard.
Definition: md4.cpp:90
ChecksumAlgoId getID() const override
Returns an unique identifier for the checksum or the hash algorithm.
Definition: md4.hpp:143
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
Definition: md4.hpp:167
uint32_t A
First part of the state of computation.
Definition: md4.hpp:60
MD4()
Default constructor.
Definition: md4.cpp:64
uint32_t D
Fourth part of the state of computation.
Definition: md4.hpp:63
int count
Current size of the input buffer.
Definition: md4.hpp:66
std::string getName() const override
Returns the name of the checksum or the hash algorithm.
Definition: md4.hpp:129
uint8_t * getValue(uint8_t *buffer) const override
Returns the MD4 hash value in the first 16 bytes of the given address.
Definition: md4.cpp:302
size_t getSize() const override
Returns the minimal size to allocate in memory to store the hash with the getValue(buffer) method.
Definition: md4.hpp:97
static Checksum * getNewInstance()
Gets a new instance of this class.
Definition: md4.hpp:180
void update(const uint8_t *buf, size_t len) override
Updates the MD4 hash with specified array of bytes.
Definition: md4.cpp:156
uint32_t B
Second part of the state of computation.
Definition: md4.hpp:61
uint8_t ibuffer[64]
Input buffer.
Definition: md4.hpp:67
uint32_t C
Third part of the state of computation.
Definition: md4.hpp:62
void transform(uint8_t *data)
Transform the message X which consists of 16 32-bit-words.
Definition: md4.cpp:197
static std::string getHashName()
Returns the name of the hash algorithm.
Definition: md4.hpp:153
void reset() override
Resets the MD4 hash to initial state of computation.
Definition: md4.cpp:74
Interface for classes from the Libgcrypt that compute hashes.
ChecksumAlgoId
Ids of algorithms of checksums.
Definition: types.hpp:65