Ethereum  PoC-8
The C++ Implementation of Ethereum
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 <random>
30 #include <boost/functional/hash.hpp>
31 #include "CommonData.h"
32 
33 namespace dev
34 {
35 
37 template <unsigned N> struct StaticLog2 { enum { result = 1 + StaticLog2<N/2>::result }; };
38 template <> struct StaticLog2<1> { enum { result = 0 }; };
39 
40 extern std::random_device s_fixedHashEngine;
41 
45 template <unsigned N>
46 class FixedHash
47 {
48 public:
50  using Arith = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<N * 8, N * 8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>;
51 
53  enum { size = N };
54 
57 
60 
63 
65  FixedHash() { m_data.fill(0); }
66 
68  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]; }
69 
71  FixedHash(Arith const& _arith) { toBigEndian(_arith, m_data); }
72 
74  explicit FixedHash(unsigned _u) { toBigEndian(_u, m_data); }
75 
77  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]; } } }
78 
80  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]; } } }
81 
83  explicit FixedHash(byte const* _bs, ConstructFromPointerType) { memcpy(m_data.data(), _bs, N); }
84 
86  explicit FixedHash(std::string const& _s, ConstructFromStringType _t = FromHex, ConstructFromHashType _ht = FailIfDifferent): FixedHash(_t == FromHex ? fromHex(_s, WhenError::Throw) : dev::asBytes(_s), _ht) {}
87 
89  operator Arith() const { return fromBigEndian<Arith>(m_data); }
90 
92  explicit operator bool() const { return std::any_of(m_data.begin(), m_data.end(), [](byte _b) { return _b != 0; }); }
93 
94  // The obvious comparison operators.
95  bool operator==(FixedHash const& _c) const { return m_data == _c.m_data; }
96  bool operator!=(FixedHash const& _c) const { return m_data != _c.m_data; }
97  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; }
98  bool operator>=(FixedHash const& _c) const { return !operator<(_c); }
99  bool operator<=(FixedHash const& _c) const { return operator==(_c) || operator<(_c); }
100  bool operator>(FixedHash const& _c) const { return !operator<=(_c); }
101 
102  // The obvious binary operators.
103  FixedHash& operator^=(FixedHash const& _c) { for (unsigned i = 0; i < N; ++i) m_data[i] ^= _c.m_data[i]; return *this; }
104  FixedHash operator^(FixedHash const& _c) const { return FixedHash(*this) ^= _c; }
105  FixedHash& operator|=(FixedHash const& _c) { for (unsigned i = 0; i < N; ++i) m_data[i] |= _c.m_data[i]; return *this; }
106  FixedHash operator|(FixedHash const& _c) const { return FixedHash(*this) |= _c; }
107  FixedHash& operator&=(FixedHash const& _c) { for (unsigned i = 0; i < N; ++i) m_data[i] &= _c.m_data[i]; return *this; }
108  FixedHash operator&(FixedHash const& _c) const { return FixedHash(*this) &= _c; }
109  FixedHash operator~() const { FixedHash ret; for (unsigned i = 0; i < N; ++i) ret[i] = ~m_data[i]; return ret; }
110 
111  // Big-endian increment.
112  FixedHash& operator++() { for (unsigned i = size; i > 0 && !++m_data[--i]; ) {} return *this; }
113 
115  bool contains(FixedHash const& _c) const { return (*this & _c) == _c; }
116 
118  byte& operator[](unsigned _i) { return m_data[_i]; }
120  byte operator[](unsigned _i) const { return m_data[_i]; }
121 
123  std::string abridged() const { return toHex(ref().cropped(0, 4)) + "\342\200\246"; }
124 
126  std::string abridgedMiddle() const { return toHex(ref().cropped(0, 4)) + "\342\200\246" + toHex(ref().cropped(N - 4)); }
127 
129  std::string hex() const { return toHex(ref()); }
130 
132  bytesRef ref() { return bytesRef(m_data.data(), N); }
133 
135  bytesConstRef ref() const { return bytesConstRef(m_data.data(), N); }
136 
138  byte* data() { return m_data.data(); }
139 
141  byte const* data() const { return m_data.data(); }
142 
144  auto begin() const -> typename std::array<byte, N>::const_iterator { return m_data.begin(); }
145 
147  auto end() const -> typename std::array<byte, N>::const_iterator { return m_data.end(); }
148 
150  bytes asBytes() const { return bytes(data(), data() + N); }
151 
153  std::array<byte, N>& asArray() { return m_data; }
154 
156  std::array<byte, N> const& asArray() const { return m_data; }
157 
159  template <class Engine>
160  void randomize(Engine& _eng)
161  {
162  for (auto& i: m_data)
163  i = (uint8_t)std::uniform_int_distribution<uint16_t>(0, 255)(_eng);
164  }
165 
167  static FixedHash random() { FixedHash ret; ret.randomize(s_fixedHashEngine); return ret; }
168 
169  struct hash
170  {
172  size_t operator()(FixedHash const& _value) const { return boost::hash_range(_value.m_data.cbegin(), _value.m_data.cend()); }
173  };
174 
175  template <unsigned P, unsigned M> inline FixedHash& shiftBloom(FixedHash<M> const& _h)
176  {
177  return (*this |= _h.template bloomPart<P, N>());
178  }
179 
180  template <unsigned P, unsigned M> inline bool containsBloom(FixedHash<M> const& _h)
181  {
182  return contains(_h.template bloomPart<P, N>());
183  }
184 
185  template <unsigned P, unsigned M> inline FixedHash<M> bloomPart() const
186  {
187  unsigned const c_bloomBits = M * 8;
188  unsigned const c_mask = c_bloomBits - 1;
189  unsigned const c_bloomBytes = (StaticLog2<c_bloomBits>::result + 7) / 8;
190 
191  static_assert((M & (M - 1)) == 0, "M must be power-of-two");
192  static_assert(P * c_bloomBytes <= N, "out of range");
193 
194  FixedHash<M> ret;
195  byte const* p = data();
196  for (unsigned i = 0; i < P; ++i)
197  {
198  unsigned index = 0;
199  for (unsigned j = 0; j < c_bloomBytes; ++j, ++p)
200  index = (index << 8) | *p;
201  index &= c_mask;
202  ret[M - 1 - index / 8] |= (1 << (index % 8));
203  }
204  return ret;
205  }
206 
208  inline unsigned firstBitSet() const
209  {
210  unsigned ret = 0;
211  for (auto d: m_data)
212  if (d)
213  {
214  for (;; ++ret, d <<= 1)
215  {
216  if (d & 0x80)
217  return ret;
218  }
219  }
220  else
221  ret += 8;
222  return ret;
223  }
224 
225  void clear() { m_data.fill(0); }
226 
227 private:
228  std::array<byte, N> m_data;
229 };
230 
231 template <unsigned T>
232 class SecureFixedHash: private FixedHash<T>
233 {
234 public:
238  SecureFixedHash() = default;
242  template <unsigned M> explicit SecureFixedHash(FixedHash<M> const& _h, ConstructFromHashType _t = FixedHash<T>::AlignLeft): FixedHash<T>(_h, _t) {}
243  template <unsigned M> explicit SecureFixedHash(SecureFixedHash<M> const& _h, ConstructFromHashType _t = FixedHash<T>::AlignLeft): FixedHash<T>(_h.makeInsecure(), _t) {}
245  explicit SecureFixedHash(byte const* _d, ConstructFromPointerType _t): FixedHash<T>(_d, _t) {}
247 
249 
251  {
252  if (&_c == this)
253  return *this;
254  ref().cleanse();
255  FixedHash<T>::operator=(static_cast<FixedHash<T> const&>(_c));
256  return *this;
257  }
258 
259  using FixedHash<T>::size;
260 
261  bytesSec asBytesSec() const { return bytesSec(ref()); }
262 
263  FixedHash<T> const& makeInsecure() const { return static_cast<FixedHash<T> const&>(*this); }
264  FixedHash<T>& writable() { clear(); return static_cast<FixedHash<T>&>(*this); }
265 
266  using FixedHash<T>::operator bool;
267 
268  // The obvious comparison operators.
269  bool operator==(SecureFixedHash const& _c) const { return static_cast<FixedHash<T> const&>(*this).operator==(static_cast<FixedHash<T> const&>(_c)); }
270  bool operator!=(SecureFixedHash const& _c) const { return static_cast<FixedHash<T> const&>(*this).operator!=(static_cast<FixedHash<T> const&>(_c)); }
271  bool operator<(SecureFixedHash const& _c) const { return static_cast<FixedHash<T> const&>(*this).operator<(static_cast<FixedHash<T> const&>(_c)); }
272  bool operator>=(SecureFixedHash const& _c) const { return static_cast<FixedHash<T> const&>(*this).operator>=(static_cast<FixedHash<T> const&>(_c)); }
273  bool operator<=(SecureFixedHash const& _c) const { return static_cast<FixedHash<T> const&>(*this).operator<=(static_cast<FixedHash<T> const&>(_c)); }
274  bool operator>(SecureFixedHash const& _c) const { return static_cast<FixedHash<T> const&>(*this).operator>(static_cast<FixedHash<T> const&>(_c)); }
275 
276  using FixedHash<T>::operator==;
277  using FixedHash<T>::operator!=;
278  using FixedHash<T>::operator<;
279  using FixedHash<T>::operator>=;
280  using FixedHash<T>::operator<=;
281  using FixedHash<T>::operator>;
282 
283  // The obvious binary operators.
284  SecureFixedHash& operator^=(FixedHash<T> const& _c) { static_cast<FixedHash<T>&>(*this).operator^=(_c); return *this; }
285  SecureFixedHash operator^(FixedHash<T> const& _c) const { return SecureFixedHash(*this) ^= _c; }
286  SecureFixedHash& operator|=(FixedHash<T> const& _c) { static_cast<FixedHash<T>&>(*this).operator^=(_c); return *this; }
287  SecureFixedHash operator|(FixedHash<T> const& _c) const { return SecureFixedHash(*this) |= _c; }
288  SecureFixedHash& operator&=(FixedHash<T> const& _c) { static_cast<FixedHash<T>&>(*this).operator^=(_c); return *this; }
289  SecureFixedHash operator&(FixedHash<T> const& _c) const { return SecureFixedHash(*this) &= _c; }
290 
291  SecureFixedHash& operator^=(SecureFixedHash const& _c) { static_cast<FixedHash<T>&>(*this).operator^=(static_cast<FixedHash<T> const&>(_c)); return *this; }
292  SecureFixedHash operator^(SecureFixedHash const& _c) const { return SecureFixedHash(*this) ^= _c; }
293  SecureFixedHash& operator|=(SecureFixedHash const& _c) { static_cast<FixedHash<T>&>(*this).operator^=(static_cast<FixedHash<T> const&>(_c)); return *this; }
294  SecureFixedHash operator|(SecureFixedHash const& _c) const { return SecureFixedHash(*this) |= _c; }
295  SecureFixedHash& operator&=(SecureFixedHash const& _c) { static_cast<FixedHash<T>&>(*this).operator^=(static_cast<FixedHash<T> const&>(_c)); return *this; }
296  SecureFixedHash operator&(SecureFixedHash const& _c) const { return SecureFixedHash(*this) &= _c; }
297  SecureFixedHash operator~() const { auto r = ~static_cast<FixedHash<T> const&>(*this); return static_cast<SecureFixedHash const&>(r); }
298 
301 
302  bytesConstRef ref() const { return FixedHash<T>::ref(); }
303  byte const* data() const { return FixedHash<T>::data(); }
304 
305  static SecureFixedHash<T> random() { SecureFixedHash<T> ret; ret.randomize(s_fixedHashEngine); return ret; }
307 
308  void clear() { ref().cleanse(); }
309 };
310 
312 template<> inline bool FixedHash<32>::operator==(FixedHash<32> const& _other) const
313 {
314  const uint64_t* hash1 = (const uint64_t*)data();
315  const uint64_t* hash2 = (const uint64_t*)_other.data();
316  return (hash1[0] == hash2[0]) && (hash1[1] == hash2[1]) && (hash1[2] == hash2[2]) && (hash1[3] == hash2[3]);
317 }
318 
320 template<> inline size_t FixedHash<32>::hash::operator()(FixedHash<32> const& value) const
321 {
322  uint64_t const* data = reinterpret_cast<uint64_t const*>(value.data());
323  return boost::hash_range(data, data + 4);
324 }
325 
327 template <unsigned N>
328 inline std::ostream& operator<<(std::ostream& _out, FixedHash<N> const& _h)
329 {
330  _out << toHex(_h);
331  return _out;
332 }
333 
334 template <unsigned N>
335 inline std::istream& operator>>(std::istream& _in, FixedHash<N>& o_h)
336 {
337  std::string s;
338  _in >> s;
340  return _in;
341 }
342 
344 template <unsigned N>
345 inline std::ostream& operator<<(std::ostream& _out, SecureFixedHash<N> const& _h)
346 {
347  _out << "SecureFixedHash#" << std::hex << typename FixedHash<N>::hash()(_h.makeInsecure()) << std::dec;
348  return _out;
349 }
350 
351 // Common types of FixedHash.
360 using h512s = std::vector<h512>;
361 using h256s = std::vector<h256>;
362 using h160s = std::vector<h160>;
363 using h256Set = std::set<h256>;
364 using h160Set = std::set<h160>;
365 using h256Hash = std::unordered_set<h256>;
366 using h160Hash = std::unordered_set<h160>;
367 
369 inline h160 right160(h256 const& _t)
370 {
371  h160 ret;
372  memcpy(ret.data(), _t.data() + 12, 20);
373  return ret;
374 }
375 
376 h128 fromUUID(std::string const& _uuid);
377 
378 std::string toUUID(h128 const& _uuid);
379 
380 inline std::string toString(h256s const& _bs)
381 {
382  std::ostringstream out;
383  out << "[ ";
384  for (h256 const& i: _bs)
385  out << i.abridged() << ", ";
386  out << "]";
387  return out.str();
388 }
389 
390 }
391 
392 namespace std
393 {
395  template<> struct hash<dev::h64>: dev::h64::hash {};
396  template<> struct hash<dev::h128>: dev::h128::hash {};
397  template<> struct hash<dev::h160>: dev::h160::hash {};
398  template<> struct hash<dev::h256>: dev::h256::hash {};
399  template<> struct hash<dev::h512>: dev::h512::hash {};
400 }
dev::SecureFixedHash::clear
void clear()
Definition: FixedHash.h:308
dev::FixedHash::AlignLeft
@ AlignLeft
Definition: FixedHash.h:62
dev::SecureFixedHash::SecureFixedHash
SecureFixedHash(bytes const &_b, ConstructFromHashType _t=FixedHash< T >::FailIfDifferent)
Definition: FixedHash.h:239
dev::FixedHash::shiftBloom
FixedHash & shiftBloom(FixedHash< M > const &_h)
Definition: FixedHash.h:175
dev::FixedHash::FromBinary
@ FromBinary
Definition: FixedHash.h:59
dev::SecureFixedHash::SecureFixedHash
SecureFixedHash(std::string const &_s, ConstructFromStringType _t=FixedHash< T >::FromHex, ConstructFromHashType _ht=FixedHash< T >::FailIfDifferent)
Definition: FixedHash.h:244
dev::FixedHash::operator++
FixedHash & operator++()
Definition: FixedHash.h:112
dev::SecureFixedHash::operator>=
bool operator>=(SecureFixedHash const &_c) const
Definition: FixedHash.h:272
dev::SecureFixedHash::SecureFixedHash
SecureFixedHash(bytesSec const &_b, ConstructFromHashType _t=FixedHash< T >::FailIfDifferent)
Definition: FixedHash.h:241
dev::SecureFixedHash::operator==
bool operator==(SecureFixedHash const &_c) const
Definition: FixedHash.h:269
dev::FixedHash::AlignRight
@ AlignRight
Definition: FixedHash.h:62
dev::toBigEndian
void toBigEndian(T _val, Out &o_out)
Definition: CommonData.h:124
dev::FixedHash::operator~
FixedHash operator~() const
Definition: FixedHash.h:109
dev::FixedHash::hash::operator()
size_t operator()(FixedHash const &_value) const
Make a hash of the object's data.
Definition: FixedHash.h:172
dev::SecureFixedHash::data
byte const * data() const
Definition: FixedHash.h:303
dev::vector_ref< byte const >
dev::SecureFixedHash::operator^=
SecureFixedHash & operator^=(FixedHash< T > const &_c)
Definition: FixedHash.h:284
dev::FixedHash::FixedHash
FixedHash(bytes const &_b, ConstructFromHashType _t=FailIfDifferent)
Explicitly construct, copying from a byte array.
Definition: FixedHash.h:77
dev::FixedHash::operator|
FixedHash operator|(FixedHash const &_c) const
Definition: FixedHash.h:106
dev::FixedHash< T >::Arith
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:50
dev::FixedHash::data
byte * data()
Definition: FixedHash.h:138
dev::SecureFixedHash
Definition: FixedHash.h:233
dev::SecureFixedHash::operator|=
SecureFixedHash & operator|=(FixedHash< T > const &_c)
Definition: FixedHash.h:286
dev::SecureFixedHash::operator>
bool operator>(SecureFixedHash const &_c) const
Definition: FixedHash.h:274
dev::toString
std::string toString(h256s const &_bs)
Definition: FixedHash.h:380
dev::SecureFixedHash::~SecureFixedHash
~SecureFixedHash()
Definition: FixedHash.h:246
dev::h160
FixedHash< 20 > h160
Definition: FixedHash.h:357
dev::FixedHash::ref
bytesRef ref()
Definition: FixedHash.h:132
dev::FixedHash::FixedHash
FixedHash()
Construct an empty hash.
Definition: FixedHash.h:65
dev::h256Set
std::set< h256 > h256Set
Definition: FixedHash.h:363
dev::SecureFixedHash::operator<
bool operator<(SecureFixedHash const &_c) const
Definition: FixedHash.h:271
dev::FixedHash< T >::ConstructFromPointerType
ConstructFromPointerType
A dummy flag to avoid accidental construction from pointer.
Definition: FixedHash.h:56
dev::h256
FixedHash< 32 > h256
Definition: FixedHash.h:356
dev::h160Hash
std::unordered_set< h160 > h160Hash
Definition: FixedHash.h:366
dev::FixedHash::FailIfDifferent
@ FailIfDifferent
Definition: FixedHash.h:62
dev::FixedHash::ref
bytesConstRef ref() const
Definition: FixedHash.h:135
dev::FixedHash::hash
Definition: FixedHash.h:170
dev::FixedHash::randomize
void randomize(Engine &_eng)
Populate with random data.
Definition: FixedHash.h:160
dev::FixedHash::operator&
FixedHash operator&(FixedHash const &_c) const
Definition: FixedHash.h:108
dev::fromUUID
h128 fromUUID(std::string const &_uuid)
Definition: FixedHash.cpp:26
dev::SecureFixedHash::operator^=
SecureFixedHash & operator^=(SecureFixedHash const &_c)
Definition: FixedHash.h:291
dev::FixedHash::operator>
bool operator>(FixedHash const &_c) const
Definition: FixedHash.h:100
dev::h512
FixedHash< 64 > h512
Definition: FixedHash.h:355
dev::FixedHash::contains
bool contains(FixedHash const &_c) const
Definition: FixedHash.h:115
dev::operator>>
std::istream & operator>>(std::istream &_in, FixedHash< N > &o_h)
Definition: FixedHash.h:335
dev::FixedHash::FixedHash
FixedHash(unsigned _u)
Convert from unsigned.
Definition: FixedHash.h:74
dev::FixedHash
Definition: FixedHash.h:47
dev::FixedHash::end
auto end() const -> typename std::array< byte, N >::const_iterator
Definition: FixedHash.h:147
dev::FixedHash::operator!=
bool operator!=(FixedHash const &_c) const
Definition: FixedHash.h:96
dev::FixedHash::operator[]
byte operator[](unsigned _i) const
Definition: FixedHash.h:120
dev::SecureFixedHash::operator<=
bool operator<=(SecureFixedHash const &_c) const
Definition: FixedHash.h:273
dev::FixedHash::FixedHash
FixedHash(std::string const &_s, ConstructFromStringType _t=FromHex, ConstructFromHashType _ht=FailIfDifferent)
Explicitly construct, copying from a string.
Definition: FixedHash.h:86
dev::FixedHash::asArray
std::array< byte, N > const & asArray() const
Definition: FixedHash.h:156
dev::FixedHash::ConstructFromPointer
@ ConstructFromPointer
Definition: FixedHash.h:56
dev::right160
h160 right160(h256 const &_t)
Convert the given value into h160 (160-bit unsigned integer) using the right 20 bytes.
Definition: FixedHash.h:369
dev::SecureFixedHash::asBytesSec
bytesSec asBytesSec() const
Definition: FixedHash.h:261
dev::SecureFixedHash::SecureFixedHash
SecureFixedHash(SecureFixedHash< T > const &_c)
Definition: FixedHash.h:248
dev::SecureFixedHash::operator|=
SecureFixedHash & operator|=(SecureFixedHash const &_c)
Definition: FixedHash.h:293
dev::FixedHash::abridgedMiddle
std::string abridgedMiddle() const
Definition: FixedHash.h:126
dev::FixedHash::data
byte const * data() const
Definition: FixedHash.h:141
dev::SecureFixedHash::makeInsecure
FixedHash< T > const & makeInsecure() const
Definition: FixedHash.h:263
dev::FixedHash::containsBloom
bool containsBloom(FixedHash< M > const &_h)
Definition: FixedHash.h:180
dev::FixedHash::begin
auto begin() const -> typename std::array< byte, N >::const_iterator
Definition: FixedHash.h:144
dev::FixedHash::clear
void clear()
Definition: FixedHash.h:225
dev::secure_vector
Definition: Common.h:78
dev::h128
FixedHash< 16 > h128
Definition: FixedHash.h:358
dev::h256Hash
std::unordered_set< h256 > h256Hash
Definition: FixedHash.h:365
dev::h256s
std::vector< h256 > h256s
Definition: FixedHash.h:361
dev::SecureFixedHash::operator|
SecureFixedHash operator|(SecureFixedHash const &_c) const
Definition: FixedHash.h:294
dev::FixedHash::FixedHash
FixedHash(Arith const &_arith)
Convert from the corresponding arithmetic type.
Definition: FixedHash.h:71
dev::FixedHash::FixedHash
FixedHash(FixedHash< M > const &_h, ConstructFromHashType _t=AlignLeft)
Construct from another hash, filling with zeroes or cropping as necessary.
Definition: FixedHash.h:68
dev::SecureFixedHash::operator&
SecureFixedHash operator&(FixedHash< T > const &_c) const
Definition: FixedHash.h:289
dev::FixedHash::operator&=
FixedHash & operator&=(FixedHash const &_c)
Definition: FixedHash.h:107
dev::bytes
std::vector< byte > bytes
Definition: Common.h:72
dev::SecureFixedHash::operator!=
bool operator!=(SecureFixedHash const &_c) const
Definition: FixedHash.h:270
dev::FixedHash::abridged
std::string abridged() const
Definition: FixedHash.h:123
dev::vector_ref::data
_T * data() const
Definition: vector_ref.h:49
dev::bytesConstRef
vector_ref< byte const > bytesConstRef
Definition: Common.h:74
dev::FixedHash::asArray
std::array< byte, N > & asArray()
Definition: FixedHash.h:153
dev::h160Set
std::set< h160 > h160Set
Definition: FixedHash.h:364
dev::SecureFixedHash::operator|
SecureFixedHash operator|(FixedHash< T > const &_c) const
Definition: FixedHash.h:287
dev::FixedHash::random
static FixedHash random()
Definition: FixedHash.h:167
dev::FixedHash::operator==
bool operator==(FixedHash const &_c) const
Definition: FixedHash.h:95
dev::SecureFixedHash::operator&=
SecureFixedHash & operator&=(SecureFixedHash const &_c)
Definition: FixedHash.h:295
dev::vector_ref::size
size_t size() const
Definition: vector_ref.h:53
CommonData.h
dev::toUUID
std::string toUUID(h128 const &_uuid)
Definition: FixedHash.cpp:38
dev::bytesSec
secure_vector< byte > bytesSec
Definition: Common.h:115
dev::SecureFixedHash::operator&=
SecureFixedHash & operator&=(FixedHash< T > const &_c)
Definition: FixedHash.h:288
dev::bytesRef
vector_ref< byte > bytesRef
Definition: Common.h:73
dev::FixedHash::operator^
FixedHash operator^(FixedHash const &_c) const
Definition: FixedHash.h:104
dev::FixedHash::operator<
bool operator<(FixedHash const &_c) const
Definition: FixedHash.h:97
dev::SecureFixedHash::SecureFixedHash
SecureFixedHash(FixedHash< M > const &_h, ConstructFromHashType _t=FixedHash< T >::AlignLeft)
Definition: FixedHash.h:242
dev::SecureFixedHash::operator=
SecureFixedHash< T > & operator=(SecureFixedHash< T > const &_c)
Definition: FixedHash.h:250
dev::FixedHash::FixedHash
FixedHash(byte const *_bs, ConstructFromPointerType)
Explicitly construct, copying from a bytes in memory with given pointer.
Definition: FixedHash.h:83
dev::SecureFixedHash::random
static SecureFixedHash< T > random()
Definition: FixedHash.h:305
dev::WhenError::Throw
@ Throw
dev::SecureFixedHash::operator~
SecureFixedHash operator~() const
Definition: FixedHash.h:297
dev::SecureFixedHash::SecureFixedHash
SecureFixedHash()=default
dev::h64
FixedHash< 8 > h64
Definition: FixedHash.h:359
dev::s_fixedHashEngine
std::random_device s_fixedHashEngine
Definition: FixedHash.cpp:24
dev::FixedHash::size
@ size
Definition: FixedHash.h:53
std
Definition: FixedHash.h:393
dev::operator<<
std::ostream & operator<<(std::ostream &_out, SecureFixedHash< N > const &_h)
Stream I/O for the SecureFixedHash class.
Definition: FixedHash.h:345
dev::FixedHash::operator>=
bool operator>=(FixedHash const &_c) const
Definition: FixedHash.h:98
dev::FixedHash::FixedHash
FixedHash(bytesConstRef _b, ConstructFromHashType _t=FailIfDifferent)
Explicitly construct, copying from a byte array.
Definition: FixedHash.h:80
dev::FixedHash< T >::ConstructFromStringType
ConstructFromStringType
Method to convert from a string.
Definition: FixedHash.h:59
dev::FixedHash::FromHex
@ FromHex
Definition: FixedHash.h:59
dev::FixedHash< T >::ConstructFromHashType
ConstructFromHashType
Method to convert from a string.
Definition: FixedHash.h:62
dev
Definition: Address.cpp:21
dev::SecureFixedHash::SecureFixedHash
SecureFixedHash(bytesConstRef _b, ConstructFromHashType _t=FixedHash< T >::FailIfDifferent)
Definition: FixedHash.h:240
dev::FixedHash::operator|=
FixedHash & operator|=(FixedHash const &_c)
Definition: FixedHash.h:105
dev::vector_ref::cleanse
void cleanse()
Definition: vector_ref.h:72
dev::FixedHash::operator^=
FixedHash & operator^=(FixedHash const &_c)
Definition: FixedHash.h:103
dev::StaticLog2
Compile-time calculation of Log2 of constant values.
Definition: FixedHash.h:37
dev::FixedHash::hex
std::string hex() const
Definition: FixedHash.h:129
dev::FixedHash::firstBitSet
unsigned firstBitSet() const
Returns the index of the first bit set to one, or size() * 8 if no bits are set.
Definition: FixedHash.h:208
dev::FixedHash::asBytes
bytes asBytes() const
Definition: FixedHash.h:150
dev::SecureFixedHash::SecureFixedHash
SecureFixedHash(SecureFixedHash< M > const &_h, ConstructFromHashType _t=FixedHash< T >::AlignLeft)
Definition: FixedHash.h:243
dev::SecureFixedHash::SecureFixedHash
SecureFixedHash(byte const *_d, ConstructFromPointerType _t)
Definition: FixedHash.h:245
dev::SecureFixedHash::operator^
SecureFixedHash operator^(FixedHash< T > const &_c) const
Definition: FixedHash.h:285
dev::toHex
std::string toHex(Iterator _it, Iterator _end, std::string const &_prefix)
Definition: CommonData.h:46
dev::FixedHash::bloomPart
FixedHash< M > bloomPart() const
Definition: FixedHash.h:185
dev::FixedHash::operator<=
bool operator<=(FixedHash const &_c) const
Definition: FixedHash.h:99
dev::h512s
std::vector< h512 > h512s
Definition: FixedHash.h:360
dev::SecureFixedHash::operator&
SecureFixedHash operator&(SecureFixedHash const &_c) const
Definition: FixedHash.h:296
dev::SecureFixedHash::operator^
SecureFixedHash operator^(SecureFixedHash const &_c) const
Definition: FixedHash.h:292
dev::SecureFixedHash::ref
bytesConstRef ref() const
Definition: FixedHash.h:302
dev::fromHex
bytes fromHex(std::string const &_s, WhenError _throw=WhenError::DontThrow)
Definition: CommonData.cpp:81
dev::FixedHash::operator[]
byte & operator[](unsigned _i)
Definition: FixedHash.h:118
dev::h160s
std::vector< h160 > h160s
Definition: FixedHash.h:362
dev::StaticLog2::result
@ result
Definition: FixedHash.h:37
dev::SecureFixedHash::writable
FixedHash< T > & writable()
Definition: FixedHash.h:264
dev::WhenError
WhenError
Definition: CommonData.h:40