libxcks  0.1.0.1
rmd160.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_RMD160_HPP_9F51C127_E1C2_4C40_8C5F_8C610DB13EC0
25 #define INC_RMD160_HPP_9F51C127_E1C2_4C40_8C5F_8C610DB13EC0
26 
27 //---------------------------------------------------------------------------
28 #include "libgcrypthash.hpp"
29 //---------------------------------------------------------------------------
30 
31 
32 namespace libxcks
33 {
56 class RIPEMD160 final : public LibgcryptHash
57 {
58  protected:
59  // State of computation between the single steps.
60  uint32_t h0;
61  uint32_t h1;
62  uint32_t h2;
63  uint32_t h3;
64  uint32_t h4;
65 
66  uint32_t nblocks;
67  int count;
68  uint8_t ibuffer[64];
69 
70  public:
74  RIPEMD160();
75 
79  void reset() override;
80 
89  uint8_t* getValue(uint8_t* buffer) const override;
90 
98  size_t getSize() const override { return 20; }
99 
106  void update(const uint8_t* buf, size_t len) override;
107 
108  protected:
113  void finish();
114 
122  void transform(uint8_t* data);
123 
124  public:
130  std::string getName() const override
131  {
132  return getHashName();
133  }
134 
144  ChecksumAlgoId getID() const override
145  {
146  return getIdentifier();
147  }
148 
154  static std::string getHashName()
155  {
156  return "RIPE-MD160";
157  }
158 
165  {
166  return getAlternativeNames();
167  }
168 
178  static constexpr ChecksumAlgoId getIdentifier()
179  {
180  return ChecksumAlgoId::RIPEMD_160;
181  }
182 
189 
199  {
200  return new RIPEMD160();
201  }
202 };
203 //---------------------------------------------------------------------------
204 } // namespace libxcks
205 //---------------------------------------------------------------------------
206 
207 #endif // INC_RMD160_HPP_9F51C127_E1C2_4C40_8C5F_8C610DB13EC0
Computes a checksum from a byte stream.
Definition: checksum.hpp:54
Computes a hash from a byte stream.
Computes the RIPE-MD160 hash from a byte stream.
Definition: rmd160.hpp:57
void transform(uint8_t *data)
Transform the message X which consists of 16 32-bit-words.
Definition: rmd160.cpp:247
uint32_t h3
Fourth part of the state of computation.
Definition: rmd160.hpp:63
uint32_t h2
Third part of the state of computation.
Definition: rmd160.hpp:62
ChecksumAlgoId getID() const override
Returns an unique identifier for the checksum or the hash algorithm.
Definition: rmd160.hpp:144
std::string getName() const override
Returns the name of the checksum or the hash algorithm.
Definition: rmd160.hpp:130
uint32_t h1
Second part of the state of computation.
Definition: rmd160.hpp:61
size_t getSize() const override
Returns the minimal size to allocate in memory to store the hash with the getValue(buffer) method.
Definition: rmd160.hpp:98
uint8_t ibuffer[64]
Input buffer.
Definition: rmd160.hpp:68
static ArrayString getAlternativeNames()
Returns the alternative names of the RIPE-MD160 hash algorithm.
Definition: rmd160.cpp:501
ArrayString getAltNames() const
Returns the alternative names of the RIPE-MD160 hash algorithm.
Definition: rmd160.hpp:164
uint8_t * getValue(uint8_t *buffer) const override
Returns the RIPE-MD160 hash value in the first 20 bytes of the given address.
Definition: rmd160.cpp:486
uint32_t h0
First part of the state of computation.
Definition: rmd160.hpp:60
void update(const uint8_t *buf, size_t len) override
Updates the RIPE-MD160 hash with specified array of bytes.
Definition: rmd160.cpp:206
static std::string getHashName()
Returns the name of the hash algorithm.
Definition: rmd160.hpp:154
RIPEMD160()
Default constructor.
Definition: rmd160.cpp:112
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
Definition: rmd160.hpp:178
void reset() override
Resets the RIPE-MD160 hash to initial state of computation.
Definition: rmd160.cpp:122
uint32_t h4
Fifth part of the state of computation.
Definition: rmd160.hpp:64
uint32_t nblocks
Number of blocks.
Definition: rmd160.hpp:66
int count
Current size of the input buffer.
Definition: rmd160.hpp:67
static Checksum * getNewInstance()
Gets a new instance of this class.
Definition: rmd160.hpp:198
void finish()
Process the remaining bytes in the internal buffer and the usual prolog according to the standard.
Definition: rmd160.cpp:139
Interface for classes from the Libgcrypt that compute hashes.
ChecksumAlgoId
Ids of algorithms of checksums.
Definition: types.hpp:65
std::vector< std::string > ArrayString
Array of strings.
Definition: types.hpp:44