libxcks  0.1.0.1
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
tiger.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_TIGER_HPP_25AA767E_5CF0_45CD_860E_2B02008338DA
25 #define INC_TIGER_HPP_25AA767E_5CF0_45CD_860E_2B02008338DA
26 
27 //---------------------------------------------------------------------------
28 #include "libgcrypthash.hpp"
29 //---------------------------------------------------------------------------
30 
31 
32 namespace libxcks
33 {
56 class Tiger final : public LibgcryptHash
57 {
58  protected:
59  // State of computation between the single steps.
60  uint64_t a;
61  uint64_t b;
62  uint64_t c;
63 
64  uint32_t nblocks;
65  int count;
66  uint8_t ibuffer[64];
67 
68  // Static arrays
69  static const uint64_t sbox1[256];
70  static const uint64_t sbox2[256];
71  static const uint64_t sbox3[256];
72  static const uint64_t sbox4[256];
73 
74  public:
78  Tiger();
79 
83  void reset() override;
84 
93  uint8_t* getValue(uint8_t* buffer) const override;
94 
102  size_t getSize() const override { return 24; }
103 
110  void update(const uint8_t* buf, size_t len) override;
111 
112  protected:
117  void finish();
118 
126  void transform(uint8_t* data);
127 
139  void round(uint64_t& a, uint64_t& b, uint64_t& c, uint64_t x, int mul);
140 
152  void pass(uint64_t& a, uint64_t& b, uint64_t& c, uint64_t* x, int mul);
153 
154 
162  void key_schedule(uint64_t* x);
163 
164  public:
170  std::string getName() const override
171  {
172  return getHashName();
173  }
174 
184  ChecksumAlgoId getID() const override
185  {
186  return getIdentifier();
187  }
188 
194  static std::string getHashName()
195  {
196  return "Tiger";
197  }
198 
208  static constexpr ChecksumAlgoId getIdentifier()
209  {
210  return ChecksumAlgoId::Tiger;
211  }
212 
222  {
223  return new Tiger();
224  }
225 };
226 //---------------------------------------------------------------------------
227 } // namespace libxcks
228 //---------------------------------------------------------------------------
229 
230 #endif // INC_TIGER_HPP_25AA767E_5CF0_45CD_860E_2B02008338DA
Computes a checksum from a byte stream.
Definition: checksum.hpp:54
Computes a hash from a byte stream.
Computes the Tiger hash from a byte stream.
Definition: tiger.hpp:57
void update(const uint8_t *buf, size_t len) override
Updates the Tiger hash with specified array of bytes.
Definition: tiger.cpp:671
void transform(uint8_t *data)
Transform the message X which consists of 8 64-bit-words.
Definition: tiger.cpp:712
size_t getSize() const override
Returns the minimal size to allocate in memory to store the hash with the getValue(buffer) method.
Definition: tiger.hpp:102
ChecksumAlgoId getID() const override
Returns an unique identifier for the checksum or the hash algorithm.
Definition: tiger.hpp:184
void pass(uint64_t &a, uint64_t &b, uint64_t &c, uint64_t *x, int mul)
Helper function for Tiger's computing.
Definition: tiger.cpp:782
static Checksum * getNewInstance()
Gets a new instance of this class.
Definition: tiger.hpp:221
static std::string getHashName()
Returns the name of the hash algorithm.
Definition: tiger.hpp:194
uint8_t ibuffer[64]
Input buffer.
Definition: tiger.hpp:66
static const uint64_t sbox3[256]
Table used to compute the Tiger hash.
Definition: tiger.hpp:71
void round(uint64_t &a, uint64_t &b, uint64_t &c, uint64_t x, int mul)
Helper function for Tiger's computing.
Definition: tiger.cpp:763
Tiger()
Default constructor.
Definition: tiger.cpp:579
static const uint64_t sbox1[256]
Table used to compute the Tiger hash.
Definition: tiger.hpp:69
static const uint64_t sbox4[256]
Table used to compute the Tiger hash.
Definition: tiger.hpp:72
void key_schedule(uint64_t *x)
Helper function for Tiger's computing.
Definition: tiger.cpp:799
void finish()
Process the remaining bytes in the internal buffer and the usual prolog according to the standard.
Definition: tiger.cpp:604
uint64_t b
Second part of the state of computation.
Definition: tiger.hpp:61
uint32_t nblocks
Number of blocks.
Definition: tiger.hpp:64
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the hash algorithm.
Definition: tiger.hpp:208
int count
Current size of the input buffer.
Definition: tiger.hpp:65
static const uint64_t sbox2[256]
Table used to compute the Tiger hash.
Definition: tiger.hpp:70
uint64_t a
First part of the state of computation.
Definition: tiger.hpp:60
std::string getName() const override
Returns the name of the checksum or the hash algorithm.
Definition: tiger.hpp:170
uint64_t c
Third part of the state of computation.
Definition: tiger.hpp:62
uint8_t * getValue(uint8_t *buffer) const override
Returns the Tiger hash value in the first 24 bytes of the given address.
Definition: tiger.cpp:824
void reset() override
Resets the Tiger hash to initial state of computation.
Definition: tiger.cpp:589
Interface for classes from the Libgcrypt that compute hashes.
ChecksumAlgoId
Ids of algorithms of checksums.
Definition: types.hpp:65