Fabcoin Core  0.16.2
P2P Digital Currency
FixedHash.h
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
24 #pragma once
25 
26 #include <array>
27 #include <cstdint>
28 #include <algorithm>
29 #include <boost/random/random_device.hpp>
30 #include <boost/random/uniform_int_distribution.hpp>
31 #include <boost/functional/hash.hpp>
32 #include "CommonData.h"
33 
34 namespace dev
35 {
36 
38 template <unsigned N> struct StaticLog2 { enum { result = 1 + StaticLog2<N/2>::result }; };
39 template <> struct StaticLog2<1> { enum { result = 0 }; };
40 
41 extern boost::random_device s_fixedHashEngine;
42 
46 template <unsigned N>
47 class FixedHash
48 {
49 public:
51  using Arith = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<N * 8, N * 8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>;
52 
54  enum { size = N };
55 
57  enum ConstructFromPointerType { ConstructFromPointer };
58 
60  enum ConstructFromStringType { FromHex, FromBinary };
61 
63  enum ConstructFromHashType { AlignLeft, AlignRight, FailIfDifferent };
64 
66  FixedHash() { m_data.fill(0); }
67 
69  template <unsigned M> explicit FixedHash(FixedHash<M> const& _h, ConstructFromHashType _t = AlignLeft) { m_data.fill(0); unsigned c = std::min(M, N); for (unsigned i = 0; i < c; ++i) m_data[_t == AlignRight ? N - 1 - i : i] = _h[_t == AlignRight ? M - 1 - i : i]; }
70 
72  FixedHash(Arith const& _arith) { toBigEndian(_arith, m_data); }
73 
75  explicit FixedHash(unsigned _u) { toBigEndian(_u, m_data); }
76 
78  explicit FixedHash(bytes const& _b, ConstructFromHashType _t = FailIfDifferent) { if (_b.size() == N) memcpy(m_data.data(), _b.data(), std::min<unsigned>(_b.size(), N)); else { m_data.fill(0); if (_t != FailIfDifferent) { auto c = std::min<unsigned>(_b.size(), N); for (unsigned i = 0; i < c; ++i) m_data[_t == AlignRight ? N - 1 - i : i] = _b[_t == AlignRight ? _b.size() - 1 - i : i]; } } }
79 
81  explicit FixedHash(bytesConstRef _b, ConstructFromHashType _t = FailIfDifferent) { if (_b.size() == N) memcpy(m_data.data(), _b.data(), std::min<unsigned>(_b.size(), N)); else { m_data.fill(0); if (_t != FailIfDifferent) { auto c = std::min<unsigned>(_b.size(), N); for (unsigned i = 0; i < c; ++i) m_data[_t == AlignRight ? N - 1 - i : i] = _b[_t == AlignRight ? _b.size() - 1 - i : i]; } } }
82 
84  explicit FixedHash(byte const* _bs, ConstructFromPointerType) { memcpy(m_data.data(), _bs, N); }
85 
87  explicit FixedHash(std::string const& _s, ConstructFromStringType _t = FromHex, ConstructFromHashType _ht = FailIfDifferent): FixedHash(_t == FromHex ? fromHex(_s, WhenError::Throw) : dev::asBytes(_s), _ht) {}
88 
90  operator Arith() const { return fromBigEndian<Arith>(m_data); }
91 
93  explicit operator bool() const { return std::any_of(m_data.begin(), m_data.end(), [](byte _b) { return _b != 0; }); }
94 
95  // The obvious comparison operators.
96  bool operator==(FixedHash const& _c) const { return m_data == _c.m_data; }
97  bool operator!=(FixedHash const& _c) const { return m_data != _c.m_data; }
98  bool operator<(FixedHash const& _c) const { for (unsigned i = 0; i < N; ++i) if (m_data[i] < _c.m_data[i]) return true; else if (m_data[i] > _c.m_data[i]) return false; return false; }
99  bool operator>=(FixedHash const& _c) const { return !operator<(_c); }
100  bool operator<=(FixedHash const& _c) const { return operator==(_c) || operator<(_c); }
101  bool operator>(FixedHash const& _c) const { return !operator<=(_c); }
102 
103  // The obvious binary operators.
104  FixedHash& operator^=(FixedHash const& _c) { for (unsigned i = 0; i < N; ++i) m_data[i] ^= _c.m_data[i]; return *this; }
105  FixedHash operator^(FixedHash const& _c) const { return FixedHash(*this) ^= _c; }
106  FixedHash& operator|=(FixedHash const& _c) { for (unsigned i = 0; i < N; ++i) m_data[i] |= _c.m_data[i]; return *this; }
107  FixedHash operator|(FixedHash const& _c) const { return FixedHash(*this) |= _c; }
108  FixedHash& operator&=(FixedHash const& _c) { for (unsigned i = 0; i < N; ++i) m_data[i] &= _c.m_data[i]; return *this; }
109  FixedHash operator&(FixedHash const& _c) const { return FixedHash(*this) &= _c; }
110  FixedHash operator~() const { FixedHash ret; for (unsigned i = 0; i < N; ++i) ret[i] = ~m_data[i]; return ret; }
111 
112  // Big-endian increment.
113  FixedHash& operator++() { for (unsigned i = size; i > 0 && !++m_data[--i]; ) {} return *this; }
114 
116  bool contains(FixedHash const& _c) const { return (*this & _c) == _c; }
117 
119  byte& operator[](unsigned _i) { return m_data[_i]; }
121  byte operator[](unsigned _i) const { return m_data[_i]; }
122 
124  std::string abridged() const { return toHex(ref().cropped(0, 4)) + "\342\200\246"; }
125 
127  std::string abridgedMiddle() const { return toHex(ref().cropped(0, 4)) + "\342\200\246" + toHex(ref().cropped(N - 4)); }
128 
130  std::string hex() const { return toHex(ref()); }
131 
133  bytesRef ref() { return bytesRef(m_data.data(), N); }
134 
136  bytesConstRef ref() const { return bytesConstRef(m_data.data(), N); }
137 
139  byte* data() { return m_data.data(); }
140 
142  byte const* data() const { return m_data.data(); }
143 
145  bytes asBytes() const { return bytes(data(), data() + N); }
146 
148  std::array<byte, N>& asArray() { return m_data; }
149 
151  std::array<byte, N> const& asArray() const { return m_data; }
152 
154  template <class Engine>
155  void randomize(Engine& _eng)
156  {
157  for (auto& i: m_data)
158  i = (uint8_t)boost::random::uniform_int_distribution<uint16_t>(0, 255)(_eng);
159  }
160 
162  static FixedHash random() { FixedHash ret; ret.randomize(s_fixedHashEngine); return ret; }
163 
164  struct hash
165  {
167  size_t operator()(FixedHash const& _value) const { return boost::hash_range(_value.m_data.cbegin(), _value.m_data.cend()); }
168  };
169 
170  template <unsigned P, unsigned M> inline FixedHash& shiftBloom(FixedHash<M> const& _h)
171  {
172  return (*this |= _h.template bloomPart<P, N>());
173  }
174 
175  template <unsigned P, unsigned M> inline bool containsBloom(FixedHash<M> const& _h)
176  {
177  return contains(_h.template bloomPart<P, N>());
178  }
179 
180  template <unsigned P, unsigned M> inline FixedHash<M> bloomPart() const
181  {
182  unsigned const c_bloomBits = M * 8;
183  unsigned const c_mask = c_bloomBits - 1;
184  unsigned const c_bloomBytes = (StaticLog2<c_bloomBits>::result + 7) / 8;
185 
186  static_assert((M & (M - 1)) == 0, "M must be power-of-two");
187  static_assert(P * c_bloomBytes <= N, "out of range");
188 
189  FixedHash<M> ret;
190  byte const* p = data();
191  for (unsigned i = 0; i < P; ++i)
192  {
193  unsigned index = 0;
194  for (unsigned j = 0; j < c_bloomBytes; ++j, ++p)
195  index = (index << 8) | *p;
196  index &= c_mask;
197  ret[M - 1 - index / 8] |= (1 << (index % 8));
198  }
199  return ret;
200  }
201 
203  inline unsigned firstBitSet() const
204  {
205  unsigned ret = 0;
206  for (auto d: m_data)
207  if (d)
208  for (;; ++ret, d <<= 1)
209  if (d & 0x80)
210  return ret;
211  else {}
212  else
213  ret += 8;
214  return ret;
215  }
216 
217  void clear() { m_data.fill(0); }
218 
219 private:
220  std::array<byte, N> m_data;
221 };
222 
223 template <unsigned T>
224 class SecureFixedHash: private FixedHash<T>
225 {
226 public:
230  SecureFixedHash() = default;
234  template <unsigned M> explicit SecureFixedHash(FixedHash<M> const& _h, ConstructFromHashType _t = FixedHash<T>::AlignLeft): FixedHash<T>(_h, _t) {}
235  template <unsigned M> explicit SecureFixedHash(SecureFixedHash<M> const& _h, ConstructFromHashType _t = FixedHash<T>::AlignLeft): FixedHash<T>(_h.makeInsecure(), _t) {}
237  explicit SecureFixedHash(bytes const* _d, ConstructFromPointerType _t): FixedHash<T>(_d, _t) {}
238  ~SecureFixedHash() { ref().cleanse(); }
239 
241  {
242  if (&_c == this)
243  return *this;
244  ref().cleanse();
245  FixedHash<T>::operator=(static_cast<FixedHash<T> const&>(_c));
246  return *this;
247  }
248 
249  using FixedHash<T>::size;
250 
251  bytesSec asBytesSec() const { return bytesSec(ref()); }
252 
253  FixedHash<T> const& makeInsecure() const { return static_cast<FixedHash<T> const&>(*this); }
254  FixedHash<T>& writable() { clear(); return static_cast<FixedHash<T>&>(*this); }
255 
256  using FixedHash<T>::operator bool;
257 
258  // The obvious comparison operators.
259  bool operator==(SecureFixedHash const& _c) const { return static_cast<FixedHash<T> const&>(*this).operator==(static_cast<FixedHash<T> const&>(_c)); }
260  bool operator!=(SecureFixedHash const& _c) const { return static_cast<FixedHash<T> const&>(*this).operator!=(static_cast<FixedHash<T> const&>(_c)); }
261  bool operator<(SecureFixedHash const& _c) const { return static_cast<FixedHash<T> const&>(*this).operator<(static_cast<FixedHash<T> const&>(_c)); }
262  bool operator>=(SecureFixedHash const& _c) const { return static_cast<FixedHash<T> const&>(*this).operator>=(static_cast<FixedHash<T> const&>(_c)); }
263  bool operator<=(SecureFixedHash const& _c) const { return static_cast<FixedHash<T> const&>(*this).operator<=(static_cast<FixedHash<T> const&>(_c)); }
264  bool operator>(SecureFixedHash const& _c) const { return static_cast<FixedHash<T> const&>(*this).operator>(static_cast<FixedHash<T> const&>(_c)); }
265 
266  using FixedHash<T>::operator==;
267  using FixedHash<T>::operator!=;
268  using FixedHash<T>::operator<;
269  using FixedHash<T>::operator>=;
270  using FixedHash<T>::operator<=;
271  using FixedHash<T>::operator>;
272 
273  // The obvious binary operators.
274  SecureFixedHash& operator^=(FixedHash<T> const& _c) { static_cast<FixedHash<T>&>(*this).operator^=(_c); return *this; }
275  SecureFixedHash operator^(FixedHash<T> const& _c) const { return SecureFixedHash(*this) ^= _c; }
276  SecureFixedHash& operator|=(FixedHash<T> const& _c) { static_cast<FixedHash<T>&>(*this).operator^=(_c); return *this; }
277  SecureFixedHash operator|(FixedHash<T> const& _c) const { return SecureFixedHash(*this) |= _c; }
278  SecureFixedHash& operator&=(FixedHash<T> const& _c) { static_cast<FixedHash<T>&>(*this).operator^=(_c); return *this; }
279  SecureFixedHash operator&(FixedHash<T> const& _c) const { return SecureFixedHash(*this) &= _c; }
280 
281  SecureFixedHash& operator^=(SecureFixedHash const& _c) { static_cast<FixedHash<T>&>(*this).operator^=(static_cast<FixedHash<T> const&>(_c)); return *this; }
282  SecureFixedHash operator^(SecureFixedHash const& _c) const { return SecureFixedHash(*this) ^= _c; }
283  SecureFixedHash& operator|=(SecureFixedHash const& _c) { static_cast<FixedHash<T>&>(*this).operator^=(static_cast<FixedHash<T> const&>(_c)); return *this; }
284  SecureFixedHash operator|(SecureFixedHash const& _c) const { return SecureFixedHash(*this) |= _c; }
285  SecureFixedHash& operator&=(SecureFixedHash const& _c) { static_cast<FixedHash<T>&>(*this).operator^=(static_cast<FixedHash<T> const&>(_c)); return *this; }
286  SecureFixedHash operator&(SecureFixedHash const& _c) const { return SecureFixedHash(*this) &= _c; }
287  SecureFixedHash operator~() const { auto r = ~static_cast<FixedHash<T> const&>(*this); return static_cast<SecureFixedHash const&>(r); }
288 
291 
292  bytesConstRef ref() const { return FixedHash<T>::ref(); }
293  byte const* data() const { return FixedHash<T>::data(); }
294 
295  static SecureFixedHash<T> random() { SecureFixedHash<T> ret; ret.randomize(s_fixedHashEngine); return ret; }
297 
298  void clear() { ref().cleanse(); }
299 };
300 
302 template<> inline bool FixedHash<32>::operator==(FixedHash<32> const& _other) const
303 {
304  const uint64_t* hash1 = (const uint64_t*)data();
305  const uint64_t* hash2 = (const uint64_t*)_other.data();
306  return (hash1[0] == hash2[0]) && (hash1[1] == hash2[1]) && (hash1[2] == hash2[2]) && (hash1[3] == hash2[3]);
307 }
308 
310 template<> inline size_t FixedHash<32>::hash::operator()(FixedHash<32> const& value) const
311 {
312  uint64_t const* data = reinterpret_cast<uint64_t const*>(value.data());
313  return boost::hash_range(data, data + 4);
314 }
315 
317 template <unsigned N>
318 inline std::ostream& operator<<(std::ostream& _out, FixedHash<N> const& _h)
319 {
320  _out << std::noshowbase << std::hex << std::setfill('0');
321  for (unsigned i = 0; i < N; ++i)
322  _out << std::setw(2) << (int)_h[i];
323  _out << std::dec;
324  return _out;
325 }
326 
328 template <unsigned N>
329 inline std::ostream& operator<<(std::ostream& _out, SecureFixedHash<N> const& _h)
330 {
331  _out << "SecureFixedHash#" << std::hex << typename FixedHash<N>::hash()(_h.makeInsecure()) << std::dec;
332  return _out;
333 }
334 
335 // Common types of FixedHash.
344 using h512s = std::vector<h512>;
345 using h256s = std::vector<h256>;
346 using h160s = std::vector<h160>;
347 using h256Set = std::set<h256>;
348 using h160Set = std::set<h160>;
349 using h256Hash = std::unordered_set<h256>;
350 using h160Hash = std::unordered_set<h160>;
351 
353 inline h160 right160(h256 const& _t)
354 {
355  h160 ret;
356  memcpy(ret.data(), _t.data() + 12, 20);
357  return ret;
358 }
359 
361 inline h160 left160(h256 const& _t)
362 {
363  h160 ret;
364  memcpy(&ret[0], _t.data(), 20);
365  return ret;
366 }
367 
368 h128 fromUUID(std::string const& _uuid);
369 
370 std::string toUUID(h128 const& _uuid);
371 
372 inline std::string toString(h256s const& _bs)
373 {
374  std::ostringstream out;
375  out << "[ ";
376  for (auto i: _bs)
377  out << i.abridged() << ", ";
378  out << "]";
379  return out.str();
380 }
381 
382 }
383 
384 namespace std
385 {
387  template<> struct hash<dev::h64>: dev::h64::hash {};
388  template<> struct hash<dev::h128>: dev::h128::hash {};
389  template<> struct hash<dev::h160>: dev::h160::hash {};
390  template<> struct hash<dev::h256>: dev::h256::hash {};
391  template<> struct hash<dev::h512>: dev::h512::hash {};
392 }
FixedHash operator^(FixedHash const &_c) const
Definition: FixedHash.h:105
h128 fromUUID(std::string const &_uuid)
Definition: FixedHash.cpp:31
bool operator>(SecureFixedHash const &_c) const
Definition: FixedHash.h:264
bool operator<(SecureFixedHash const &_c) const
Definition: FixedHash.h:261
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
std::set< h160 > h160Set
Definition: FixedHash.h:348
bool operator<=(SecureFixedHash const &_c) const
Definition: FixedHash.h:263
std::string toHex(T const &_data, int _w=2, HexPrefix _prefix=HexPrefix::DontAdd)
Definition: CommonData.h:54
bool operator<=(FixedHash const &_c) const
Definition: FixedHash.h:100
uint8_t byte
Definition: Common.h:57
vector_ref< _T const > ref(_T const &_t)
Definition: vector_ref.h:115
bool operator==(SecureFixedHash const &_c) const
Definition: FixedHash.h:259
SecureFixedHash operator^(SecureFixedHash const &_c) const
Definition: FixedHash.h:282
byte * data()
Definition: FixedHash.h:139
FixedHash & operator|=(FixedHash const &_c)
Definition: FixedHash.h:106
FixedHash & operator++()
Definition: FixedHash.h:113
byte const * data() const
Definition: FixedHash.h:293
void toBigEndian(T _val, Out &o_out)
Converts a templated integer value to the big-endian byte-stream represented on a templated collectio...
Definition: CommonData.h:110
h160 right160(h256 const &_t)
Convert the given value into h160 (160-bit unsigned integer) using the right 20 bytes.
Definition: FixedHash.h:353
SecureFixedHash & operator&=(FixedHash< T > const &_c)
Definition: FixedHash.h:278
bool contains(FixedHash const &_c) const
Definition: FixedHash.h:116
#define T(i, x)
FixedHash operator&(FixedHash const &_c) const
Definition: FixedHash.h:109
FixedHash operator~() const
Definition: FixedHash.h:110
std::set< h256 > h256Set
Definition: FixedHash.h:347
FixedHash< M > bloomPart() const
Definition: FixedHash.h:180
FixedHash(FixedHash< M > const &_h, ConstructFromHashType _t=AlignLeft)
Construct from another hash, filling with zeroes or cropping as necessary.
Definition: FixedHash.h:69
secure_vector< byte > bytesSec
Definition: Common.h:118
FixedHash(unsigned _u)
Convert from unsigned.
Definition: FixedHash.h:75
SecureFixedHash & operator|=(FixedHash< T > const &_c)
Definition: FixedHash.h:276
#define c(i)
FixedHash< 8 > h64
Definition: FixedHash.h:343
std::hash for asio::adress
Definition: Common.h:323
FixedHash operator|(FixedHash const &_c) const
Definition: FixedHash.h:107
byte & operator[](unsigned _i)
Definition: FixedHash.h:119
std::string toString(string32 const &_s)
Make normal string from fixed-length string.
Definition: CommonData.cpp:141
WhenError
Definition: CommonData.h:39
std::array< byte, N > const & asArray() const
Definition: FixedHash.h:151
Compile-time calculation of Log2 of constant values.
Definition: FixedHash.h:38
ExecStats::duration min
Definition: ExecStats.cpp:35
FixedHash & shiftBloom(FixedHash< M > const &_h)
Definition: FixedHash.h:170
FixedHash< 64 > h512
Definition: FixedHash.h:339
FixedHash()
Construct an empty hash.
Definition: FixedHash.h:66
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< N *8, N *8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> Arith
The corresponding arithmetic type.
Definition: FixedHash.h:51
std::vector< h512 > h512s
Definition: FixedHash.h:344
bool operator!=(FixedHash const &_c) const
Definition: FixedHash.h:97
SecureFixedHash(bytesSec const &_b, ConstructFromHashType _t=FixedHash< T >::FailIfDifferent)
Definition: FixedHash.h:233
SecureFixedHash(std::string const &_s, ConstructFromStringType _t=FixedHash< T >::FromHex, ConstructFromHashType _ht=FixedHash< T >::FailIfDifferent)
Definition: FixedHash.h:236
bool operator>(FixedHash const &_c) const
Definition: FixedHash.h:101
void randomize(Engine &_eng)
Populate with random data.
Definition: FixedHash.h:155
bool operator==(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
Definition: asn.h:558
SecureFixedHash(bytes const &_b, ConstructFromHashType _t=FixedHash< T >::FailIfDifferent)
Definition: FixedHash.h:231
bool containsBloom(FixedHash< M > const &_h)
Definition: FixedHash.h:175
bool operator<(FixedHash const &_c) const
Definition: FixedHash.h:98
FixedHash(bytes const &_b, ConstructFromHashType _t=FailIfDifferent)
Explicitly construct, copying from a byte array.
Definition: FixedHash.h:78
bytesConstRef ref() const
Definition: FixedHash.h:292
bool operator==(FixedHash const &_c) const
Definition: FixedHash.h:96
bool operator<=(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b)
compares degree
Definition: gf2n.h:264
bytes fromHex(std::string const &_s, WhenError _throw=WhenError::DontThrow)
Definition: CommonData.cpp:99
FixedHash(std::string const &_s, ConstructFromStringType _t=FromHex, ConstructFromHashType _ht=FailIfDifferent)
Explicitly construct, copying from a string.
Definition: FixedHash.h:87
boost::random_device s_fixedHashEngine
Definition: FixedHash.cpp:29
FixedHash(byte const *_bs, ConstructFromPointerType)
Explicitly construct, copying from a bytes in memory with given pointer.
Definition: FixedHash.h:84
FixedHash(Arith const &_arith)
Convert from the corresponding arithmetic type.
Definition: FixedHash.h:72
static SecureFixedHash< T > random()
Definition: FixedHash.h:295
vector_ref< byte > bytesRef
Definition: Common.h:76
bytesRef ref()
Definition: FixedHash.h:133
bytesSec asBytesSec() const
Definition: FixedHash.h:251
FixedHash< T > const & makeInsecure() const
Definition: FixedHash.h:253
bool contains(T const &_t, V const &_v)
Definition: CommonData.h:379
SecureFixedHash & operator|=(SecureFixedHash const &_c)
Definition: FixedHash.h:283
FixedHash(bytesConstRef _b, ConstructFromHashType _t=FailIfDifferent)
Explicitly construct, copying from a byte array.
Definition: FixedHash.h:81
SecureFixedHash(bytesConstRef _b, ConstructFromHashType _t=FixedHash< T >::FailIfDifferent)
Definition: FixedHash.h:232
std::unordered_set< h160 > h160Hash
Definition: FixedHash.h:350
std::vector< byte > bytes
Definition: Common.h:75
vector_ref< byte const > bytesConstRef
Definition: Common.h:77
SecureFixedHash & operator&=(SecureFixedHash const &_c)
Definition: FixedHash.h:285
Fixed-size raw-byte array container type, with an API optimised for storing hashes.
Definition: FixedHash.h:47
SecureFixedHash operator|(FixedHash< T > const &_c) const
Definition: FixedHash.h:277
bool operator!=(SecureFixedHash const &_c) const
Definition: FixedHash.h:260
FixedHash< T > & writable()
Definition: FixedHash.h:254
bytes asBytes(std::string const &_b)
Converts a string to a byte array containing the string&#39;s (byte) data.
Definition: CommonData.h:92
FixedHash< 32 > h256
Definition: FixedHash.h:340
size_t size() const
Definition: vector_ref.h:55
SecureFixedHash & operator^=(FixedHash< T > const &_c)
Definition: FixedHash.h:274
SecureFixedHash operator|(SecureFixedHash const &_c) const
Definition: FixedHash.h:284
static FixedHash random()
Definition: FixedHash.h:162
bytes asBytes() const
Definition: FixedHash.h:145
bool operator>=(SecureFixedHash const &_c) const
Definition: FixedHash.h:262
byte operator[](unsigned _i) const
Definition: FixedHash.h:121
std::vector< h160 > h160s
Definition: FixedHash.h:346
h160 left160(h256 const &_t)
Convert the given value into h160 (160-bit unsigned integer) using the left 20 bytes.
Definition: FixedHash.h:361
void clear()
Definition: FixedHash.h:217
FixedHash< 16 > h128
Definition: FixedHash.h:342
_T * data() const
Definition: vector_ref.h:51
SecureFixedHash(bytes const *_d, ConstructFromPointerType _t)
Definition: FixedHash.h:237
uint8_t const size_t const size
Definition: sha3.h:20
SecureFixedHash & operator^=(SecureFixedHash const &_c)
Definition: FixedHash.h:281
void * memcpy(void *a, const void *b, size_t c)
std::string abridgedMiddle() const
Definition: FixedHash.h:127
#define P
bool operator>=(FixedHash const &_c) const
Definition: FixedHash.h:99
size_t operator()(FixedHash const &_value) const
Make a hash of the object&#39;s data.
Definition: FixedHash.h:167
FixedHash & operator&=(FixedHash const &_c)
Definition: FixedHash.h:108
SecureFixedHash operator&(SecureFixedHash const &_c) const
Definition: FixedHash.h:286
SecureFixedHash operator&(FixedHash< T > const &_c) const
Definition: FixedHash.h:279
std::string abridged() const
Definition: FixedHash.h:124
std::unordered_set< h256 > h256Hash
Definition: FixedHash.h:349
FixedHash< 20 > h160
Definition: FixedHash.h:341
SecureFixedHash operator~() const
Definition: FixedHash.h:287
#define d(i)
Definition: sha.cpp:732
ConstructFromHashType
Method to convert from a string.
Definition: FixedHash.h:63
std::array< byte, N > & asArray()
Definition: FixedHash.h:148
std::array< byte, N > m_data
The binary data.
Definition: FixedHash.h:220
byte const * data() const
Definition: FixedHash.h:142
std::vector< h256 > h256s
Definition: FixedHash.h:345
ConstructFromPointerType
A dummy flag to avoid accidental construction from pointer.
Definition: FixedHash.h:57
bytesConstRef ref() const
Definition: FixedHash.h:136
ConstructFromStringType
Method to convert from a string.
Definition: FixedHash.h:60
unsigned firstBitSet() const
Returns the index of the first bit set to one, or size() * 8 if no bits are set.
Definition: FixedHash.h:203
SecureFixedHash operator^(FixedHash< T > const &_c) const
Definition: FixedHash.h:275
uint8_t const * data
Definition: sha3.h:19
FixedHash & operator^=(FixedHash const &_c)
Definition: FixedHash.h:104
SecureFixedHash(SecureFixedHash< M > const &_h, ConstructFromHashType _t=FixedHash< T >::AlignLeft)
Definition: FixedHash.h:235
SecureFixedHash< T > & operator=(SecureFixedHash< T > const &_c)
Definition: FixedHash.h:240
std::string toUUID(h128 const &_uuid)
Definition: FixedHash.cpp:43
bool operator<(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
Definition: asn.h:562
std::string hex() const
Definition: FixedHash.h:130
SecureFixedHash(FixedHash< M > const &_h, ConstructFromHashType _t=FixedHash< T >::AlignLeft)
Definition: FixedHash.h:234