libxcks  0.1.0.1
crc64.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_CRC64_HPP_D457DF18_2251_4074_831B_AE0C18F981FC
25 #define INC_CRC64_HPP_D457DF18_2251_4074_831B_AE0C18F981FC
26 
27 //---------------------------------------------------------------------------
28 #include "checksumex.hpp"
29 //---------------------------------------------------------------------------
30 
31 
32 namespace libxcks
33 {
51 class CRC64 final : public ChecksumEx
52 {
53  protected:
55  static const uint64_t crc_table[256];
56 
58  uint64_t crc64;
59 
60  public:
64  CRC64();
65 
69  void reset() override;
70 
76  uint64_t getUint64Value() const;
77 
85  std::string toString(const bool hexInUpperCase = false) const override;
86 
95  uint8_t* getValue(uint8_t* buffer) const override;
96 
104  size_t getSize() const override { return 8; }
105 
112  void update(const uint8_t* buf, size_t len) override;
113 
119  std::string getName() const override
120  {
121  return getChecksumName();
122  }
123 
129  ArrayString getAltNames() const override
130  {
131  return getAlternativeNames();
132  }
133 
143  ChecksumAlgoId getID() const override
144  {
145  return getIdentifier();
146  }
147 
153  static std::string getChecksumName()
154  {
155  return "CRC64";
156  }
157 
168  static constexpr ChecksumAlgoId getIdentifier()
169  {
170  return ChecksumAlgoId::CRC64;
171  }
172 
179 
189  {
190  return new CRC64();
191  }
192 };
193 //---------------------------------------------------------------------------
194 } // namespace libxcks
195 //---------------------------------------------------------------------------
196 
197 #endif // INC_CRC64_HPP_D457DF18_2251_4074_831B_AE0C18F981FC
Add some utilities to Checksum class.
Computes the CRC-64 (ECMA 182 standard) from a byte stream.
Definition: crc64.hpp:52
void reset() override
Resets the CRC64 to initial value.
Definition: crc64.cpp:88
ArrayString getAltNames() const override
Returns the alternative names of the CRC64 checksum algorithm.
Definition: crc64.hpp:129
static std::string getChecksumName()
Returns the name of the checksum algorithm.
Definition: crc64.hpp:153
uint8_t * getValue(uint8_t *buffer) const override
Returns the CRC64 value in the first 8 bytes of the given address.
Definition: crc64.cpp:108
CRC64()
Default constructor.
Definition: crc64.cpp:78
ChecksumAlgoId getID() const override
Returns an unique identifier for the checksum or the hash algorithm.
Definition: crc64.hpp:143
std::string toString(const bool hexInUpperCase=false) const override
Returns the CRC64 value in a string.
Definition: crc64.cpp:123
static Checksum * getNewInstance()
Gets a new instance of this class.
Definition: crc64.hpp:188
uint64_t getUint64Value() const
Returns the CRC64 value.
Definition: crc64.cpp:98
std::string getName() const override
Returns the name of the checksum or the hash algorithm.
Definition: crc64.hpp:119
void update(const uint8_t *buf, size_t len) override
Updates the CRC64 with specified array of bytes.
Definition: crc64.cpp:142
static ArrayString getAlternativeNames()
Returns the alternative names of the CRC64 checksum algorithm.
Definition: crc64.cpp:155
uint64_t crc64
The current CRC64 value.
Definition: crc64.hpp:58
static constexpr ChecksumAlgoId getIdentifier()
Returns an unique identifier for the checksum algorithm.
Definition: crc64.hpp:168
size_t getSize() const override
Returns the minimal size to allocate in memory to store the checksum with the getValue(buffer) metho...
Definition: crc64.hpp:104
static const uint64_t crc_table[256]
Table used to compute the CRC64 value.
Definition: crc64.hpp:55
Computes a hash from a byte stream.
Definition: checksumex.hpp:72
Computes a checksum from a byte stream.
Definition: checksum.hpp:54
ChecksumAlgoId
Ids of algorithms of checksums.
Definition: types.hpp:65
std::vector< std::string > ArrayString
Array of strings.
Definition: types.hpp:44