Electroneum
Loading...
Searching...
No Matches
serialization.h File Reference

Simple DSL AAPI based on. More...

#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <string>
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/integral_constant.hpp>
Include dependency graph for serialization.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  is_blob_type< T >
 a descriptor for dispatching serialize More...
struct  has_free_serializer< T >
 a descriptor for dispatching serialize More...
struct  is_basic_type< T >
 a descriptor for dispatching serialize More...
struct  is_basic_type< std::pair< F, S > >
struct  is_basic_type< std::string >
struct  serializer< Archive, T >
 ... wouldn't a class be better? More...

Namespaces

namespace  serialization
namespace  detail
 declaration and default definition for the functions used the API
namespace  serialization::detail

Macros

#define BLOB_SERIALIZER(T)
 makes the type have a blob serializer trait defined
#define FREE_SERIALIZER(T)
 adds the has_free_serializer to the type
#define VARIANT_TAG(Archive, Type, Tag)
 Adds the tag \tag to the Archive of Type.
#define BEGIN_SERIALIZE()
 Begins the environment of the DSL \detailed for describing how to serialize an of an archive type.
#define BEGIN_SERIALIZE_OBJECT()
 begins the environment of the DSL \detailed for described the serialization of an object
#define PREPARE_CUSTOM_VECTOR_SERIALIZATION(size, vec)
#define PREPARE_CUSTOM_DEQUE_SERIALIZATION(size, vec)
#define END_SERIALIZE()
 self-explanatory
#define VALUE(f)
 the same as FIELD(f)
#define FIELD_N(t, f)
 serializes a field f tagged t
#define FIELD(f)
 tags the field with the variable name and then serializes it
#define FIELDS(f)
 does not add a tag to the serialized value
#define VARINT_FIELD(f)
 tags and serializes the varint f
#define VARINT_FIELD_N(t, f)
 tags (as t) and serializes the varint f

Functions

template<class Archive, class T>
bool do_serialize (Archive &ar, T &v)
 just calls the serialize function defined for ar and v...
template<class Archive>
bool do_serialize (Archive &ar, bool &v)
template<typename T>
void serialization::detail::prepare_custom_vector_serialization (size_t size, std::vector< T > &vec, const boost::mpl::bool_< true > &)
template<typename T>
void serialization::detail::prepare_custom_vector_serialization (size_t size, std::vector< T > &vec, const boost::mpl::bool_< false > &)
template<typename T>
void serialization::detail::prepare_custom_deque_serialization (size_t size, std::deque< T > &vec, const boost::mpl::bool_< true > &)
template<typename T>
void serialization::detail::prepare_custom_deque_serialization (size_t size, std::deque< T > &vec, const boost::mpl::bool_< false > &)
template<class Stream>
bool serialization::detail::do_check_stream_state (Stream &s, boost::mpl::bool_< true >, bool noeof)
template<class Stream>
bool serialization::detail::do_check_stream_state (Stream &s, boost::mpl::bool_< false >, bool noeof)
template<class Archive>
bool serialization::check_stream_state (Archive &ar, bool noeof=false)
template<class Archive, class T>
bool serialization::serialize (Archive &ar, T &v)
template<class Archive, class T>
bool serialization::serialize_noeof (Archive &ar, T &v)

Detailed Description

Simple DSL AAPI based on.

\detailed is_blob_type and has_free_serializer are both descriptors for dispatching on to the serialize function.

The API itself defines a domain specific language via dirty macro hacks. Greenspun's tenth rule is very much in action throughout this entire code base.

Definition in file serialization.h.

Macro Definition Documentation

◆ BEGIN_SERIALIZE

#define BEGIN_SERIALIZE ( )
Value:
template <bool W, template <bool> class Archive> \
bool do_serialize(Archive<W> &ar) {
bool do_serialize(Archive< false > &ar, std::vector< crypto::signature > &v)
Definition crypto.h:44

Begins the environment of the DSL \detailed for describing how to serialize an of an archive type.

\macro BEGIN_SERIALIZE

Definition at line 182 of file hash.h.

◆ BEGIN_SERIALIZE_OBJECT

#define BEGIN_SERIALIZE_OBJECT ( )
Value:
template <bool W, template <bool> class Archive> \
bool do_serialize(Archive<W> &ar) { \
ar.begin_object(); \
bool r = do_serialize_object(ar); \
ar.end_object(); \
return r; \
} \
template <bool W, template <bool> class Archive> \
bool do_serialize_object(Archive<W> &ar){

begins the environment of the DSL \detailed for described the serialization of an object

\macro BEGIN_SERIALIZE_OBJECT

Definition at line 191 of file hash.h.

191// Copyrights(c) 2017-2021, The Electroneum Project
192// Copyrights(c) 2014-2019, The Monero Project
193//
194// All rights reserved.
195//
196// Redistribution and use in source and binary forms, with or without modification, are
197// permitted provided that the following conditions are met:
198//
199// 1. Redistributions of source code must retain the above copyright notice, this list of
200// conditions and the following disclaimer.
201//
202// 2. Redistributions in binary form must reproduce the above copyright notice, this list
203// of conditions and the following disclaimer in the documentation and/or other
204// materials provided with the distribution.
205//
206// 3. Neither the name of the copyright holder nor the names of its contributors may be
207// used to endorse or promote products derived from this software without specific
208// prior written permission.
209//
210// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
211// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
212// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
213// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
214// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
215// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
216// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
217// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
218// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
219//
220// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
221
222#pragma once
223
224#include <stddef.h>
225#include <iostream>
226#include <boost/utility/value_init.hpp>
227
228#include "common/pod-class.h"
229#include "generic-ops.h"
230#include "hex.h"
231#include "span.h"
232
233namespace crypto {
234
235 extern "C" {
236#include "hash-ops.h"
237 }
238
239#pragma pack(push, 1)
241 char data[HASH_SIZE];
242 };
244 char data[8];
245 };
247 char data[64];
248 };
249#pragma pack(pop)
250
251 static_assert(sizeof(hash) == HASH_SIZE, "Invalid structure size");
252 static_assert(sizeof(hash8) == 8, "Invalid structure size");
253 static_assert(sizeof(hash64) == 64, "Invalid structure size");
254
255 /*
256 Cryptonight hash functions
257 */
258
259 inline void cn_fast_hash(const void *data, std::size_t length, hash &hash) {
260 cn_fast_hash(data, length, reinterpret_cast<char *>(&hash));
261 }
262
263 inline hash cn_fast_hash(const void *data, std::size_t length) {
264 hash h;
265 cn_fast_hash(data, length, reinterpret_cast<char *>(&h));
266 return h;
267 }
268
269 inline void cn_slow_hash(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
270 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 0/*prehashed*/, height);
271 }
272
273 inline void cn_slow_hash_prehashed(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
274 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 1/*prehashed*/, height);
275 }
276
277 inline void tree_hash(const hash *hashes, std::size_t count, hash &root_hash) {
278 tree_hash(reinterpret_cast<const char (*)[HASH_SIZE]>(hashes), count, reinterpret_cast<char *>(&root_hash));
279 }
280
281 inline std::ostream &operator <<(std::ostream &o, const crypto::hash &v) {
283 }
284 inline std::ostream &operator <<(std::ostream &o, const crypto::hash8 &v) {
286 }
287 inline std::ostream &operator <<(std::ostream &o, const crypto::hash64 &v) {
289 }
290
291 const static crypto::hash null_hash = boost::value_initialized<crypto::hash>();
292 const static crypto::hash8 null_hash8 = boost::value_initialized<crypto::hash8>();
293 const static crypto::hash64 null_hash64 = boost::value_initialized<crypto::hash64>();
294}
295
uint64_t height
#define CRYPTO_MAKE_COMPARABLE(type)
Definition generic-ops.h:39
#define CRYPTO_MAKE_HASHABLE(type)
Definition generic-ops.h:76
crypto namespace.
Definition crypto.cpp:58
void cn_slow_hash_prehashed(const void *data, std::size_t length, hash &hash, int variant=0, uint64_t height=0)
Definition hash.h:83
void cn_fast_hash(const void *data, size_t length, char *hash)
POD_CLASS hash8
Definition hash.h:53
void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int prehashed, uint64_t height)
unsigned __int64 uint64_t
Definition hash.h:137
void tree_hash(const char(*hashes)[HASH_SIZE], size_t count, char *root_hash)
std::ostream & operator<<(std::ostream &o, const crypto::public_key &v)
Definition crypto.h:357
POD_CLASS hash64
Definition hash.h:56
POD_CLASS hash
Definition hash.h:50
@ HASH_SIZE
Definition hash.h:78
span< const std::uint8_t > as_byte_span(const T &src) noexcept
Definition span.h:153
#define POD_CLASS
Definition pod-class.h:44
static void formatted(std::ostream &out, const span< const std::uint8_t > src)
Append < + src + > as hex to out.
Definition hex.cpp:76
struct hash_func hashes[]

◆ BLOB_SERIALIZER

#define BLOB_SERIALIZER ( T)
Value:
template<> \
struct is_blob_type<T> { \
typedef boost::true_type type; \
}
a descriptor for dispatching serialize
#define T(x)

makes the type have a blob serializer trait defined

\macro BLOB_SERIALIZER

Definition at line 148 of file hash.h.

148// Copyrights(c) 2017-2021, The Electroneum Project
149// Copyrights(c) 2014-2019, The Monero Project
150//
151// All rights reserved.
152//
153// Redistribution and use in source and binary forms, with or without modification, are
154// permitted provided that the following conditions are met:
155//
156// 1. Redistributions of source code must retain the above copyright notice, this list of
157// conditions and the following disclaimer.
158//
159// 2. Redistributions in binary form must reproduce the above copyright notice, this list
160// of conditions and the following disclaimer in the documentation and/or other
161// materials provided with the distribution.
162//
163// 3. Neither the name of the copyright holder nor the names of its contributors may be
164// used to endorse or promote products derived from this software without specific
165// prior written permission.
166//
167// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
168// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
169// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
170// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
171// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
172// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
173// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
174// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
175// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
176//
177// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
178
179#pragma once
180
181#include <stddef.h>
182#include <iostream>
183#include <boost/utility/value_init.hpp>
184
185#include "common/pod-class.h"
186#include "generic-ops.h"
187#include "hex.h"
188#include "span.h"
189
190namespace crypto {
191
192 extern "C" {
193#include "hash-ops.h"
194 }
195
196#pragma pack(push, 1)
198 char data[HASH_SIZE];
199 };
201 char data[8];
202 };
204 char data[64];
205 };
206#pragma pack(pop)
207
208 static_assert(sizeof(hash) == HASH_SIZE, "Invalid structure size");
209 static_assert(sizeof(hash8) == 8, "Invalid structure size");
210 static_assert(sizeof(hash64) == 64, "Invalid structure size");
211
212 /*
213 Cryptonight hash functions
214 */
215
216 inline void cn_fast_hash(const void *data, std::size_t length, hash &hash) {
217 cn_fast_hash(data, length, reinterpret_cast<char *>(&hash));
218 }
219
220 inline hash cn_fast_hash(const void *data, std::size_t length) {
221 hash h;
222 cn_fast_hash(data, length, reinterpret_cast<char *>(&h));
223 return h;
224 }
225
226 inline void cn_slow_hash(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
227 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 0/*prehashed*/, height);
228 }
229
230 inline void cn_slow_hash_prehashed(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
231 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 1/*prehashed*/, height);
232 }
233
234 inline void tree_hash(const hash *hashes, std::size_t count, hash &root_hash) {
235 tree_hash(reinterpret_cast<const char (*)[HASH_SIZE]>(hashes), count, reinterpret_cast<char *>(&root_hash));
236 }
237
238 inline std::ostream &operator <<(std::ostream &o, const crypto::hash &v) {
240 }
241 inline std::ostream &operator <<(std::ostream &o, const crypto::hash8 &v) {
243 }
244 inline std::ostream &operator <<(std::ostream &o, const crypto::hash64 &v) {
246 }
247
248 const static crypto::hash null_hash = boost::value_initialized<crypto::hash>();
249 const static crypto::hash8 null_hash8 = boost::value_initialized<crypto::hash8>();
250 const static crypto::hash64 null_hash64 = boost::value_initialized<crypto::hash64>();
251}
252

◆ END_SERIALIZE

#define END_SERIALIZE ( )
Value:
return ar.stream().good(); \
}

self-explanatory

\macro END_SERIALIZE

Definition at line 215 of file hash.h.

215// Copyrights(c) 2017-2021, The Electroneum Project
216// Copyrights(c) 2014-2019, The Monero Project
217//
218// All rights reserved.
219//
220// Redistribution and use in source and binary forms, with or without modification, are
221// permitted provided that the following conditions are met:
222//
223// 1. Redistributions of source code must retain the above copyright notice, this list of
224// conditions and the following disclaimer.
225//
226// 2. Redistributions in binary form must reproduce the above copyright notice, this list
227// of conditions and the following disclaimer in the documentation and/or other
228// materials provided with the distribution.
229//
230// 3. Neither the name of the copyright holder nor the names of its contributors may be
231// used to endorse or promote products derived from this software without specific
232// prior written permission.
233//
234// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
235// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
236// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
237// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
238// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
239// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
240// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
241// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
242// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
243//
244// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
245
246#pragma once
247
248#include <stddef.h>
249#include <iostream>
250#include <boost/utility/value_init.hpp>
251
252#include "common/pod-class.h"
253#include "generic-ops.h"
254#include "hex.h"
255#include "span.h"
256
257namespace crypto {
258
259 extern "C" {
260#include "hash-ops.h"
261 }
262
263#pragma pack(push, 1)
265 char data[HASH_SIZE];
266 };
268 char data[8];
269 };
271 char data[64];
272 };
273#pragma pack(pop)
274
275 static_assert(sizeof(hash) == HASH_SIZE, "Invalid structure size");
276 static_assert(sizeof(hash8) == 8, "Invalid structure size");
277 static_assert(sizeof(hash64) == 64, "Invalid structure size");
278
279 /*
280 Cryptonight hash functions
281 */
282
283 inline void cn_fast_hash(const void *data, std::size_t length, hash &hash) {
284 cn_fast_hash(data, length, reinterpret_cast<char *>(&hash));
285 }
286
287 inline hash cn_fast_hash(const void *data, std::size_t length) {
288 hash h;
289 cn_fast_hash(data, length, reinterpret_cast<char *>(&h));
290 return h;
291 }
292
293 inline void cn_slow_hash(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
294 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 0/*prehashed*/, height);
295 }
296
297 inline void cn_slow_hash_prehashed(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
298 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 1/*prehashed*/, height);
299 }
300
301 inline void tree_hash(const hash *hashes, std::size_t count, hash &root_hash) {
302 tree_hash(reinterpret_cast<const char (*)[HASH_SIZE]>(hashes), count, reinterpret_cast<char *>(&root_hash));
303 }
304
305 inline std::ostream &operator <<(std::ostream &o, const crypto::hash &v) {
307 }
308 inline std::ostream &operator <<(std::ostream &o, const crypto::hash8 &v) {
310 }
311 inline std::ostream &operator <<(std::ostream &o, const crypto::hash64 &v) {
313 }
314
315 const static crypto::hash null_hash = boost::value_initialized<crypto::hash>();
316 const static crypto::hash8 null_hash8 = boost::value_initialized<crypto::hash8>();
317 const static crypto::hash64 null_hash64 = boost::value_initialized<crypto::hash64>();
318}
319

◆ FIELD

#define FIELD ( f)
Value:
do { \
ar.tag(#f); \
bool r = ::do_serialize(ar, f); \
if (!r || !ar.stream().good()) return false; \
} while(0);
#define false

tags the field with the variable name and then serializes it

\macro FIELD(f)

Definition at line 244 of file hash.h.

244// Copyrights(c) 2017-2021, The Electroneum Project
245// Copyrights(c) 2014-2019, The Monero Project
246//
247// All rights reserved.
248//
249// Redistribution and use in source and binary forms, with or without modification, are
250// permitted provided that the following conditions are met:
251//
252// 1. Redistributions of source code must retain the above copyright notice, this list of
253// conditions and the following disclaimer.
254//
255// 2. Redistributions in binary form must reproduce the above copyright notice, this list
256// of conditions and the following disclaimer in the documentation and/or other
257// materials provided with the distribution.
258//
259// 3. Neither the name of the copyright holder nor the names of its contributors may be
260// used to endorse or promote products derived from this software without specific
261// prior written permission.
262//
263// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
264// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
266// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
267// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
268// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
269// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
270// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
271// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272//
273// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
274
275#pragma once
276
277#include <stddef.h>
278#include <iostream>
279#include <boost/utility/value_init.hpp>
280
281#include "common/pod-class.h"
282#include "generic-ops.h"
283#include "hex.h"
284#include "span.h"
285
286namespace crypto {
287
288 extern "C" {
289#include "hash-ops.h"
290 }
291
292#pragma pack(push, 1)
294 char data[HASH_SIZE];
295 };
297 char data[8];
298 };
300 char data[64];
301 };
302#pragma pack(pop)
303
304 static_assert(sizeof(hash) == HASH_SIZE, "Invalid structure size");
305 static_assert(sizeof(hash8) == 8, "Invalid structure size");
306 static_assert(sizeof(hash64) == 64, "Invalid structure size");
307
308 /*
309 Cryptonight hash functions
310 */
311
312 inline void cn_fast_hash(const void *data, std::size_t length, hash &hash) {
313 cn_fast_hash(data, length, reinterpret_cast<char *>(&hash));
314 }
315
316 inline hash cn_fast_hash(const void *data, std::size_t length) {
317 hash h;
318 cn_fast_hash(data, length, reinterpret_cast<char *>(&h));
319 return h;
320 }
321
322 inline void cn_slow_hash(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
323 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 0/*prehashed*/, height);
324 }
325
326 inline void cn_slow_hash_prehashed(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
327 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 1/*prehashed*/, height);
328 }
329
330 inline void tree_hash(const hash *hashes, std::size_t count, hash &root_hash) {
331 tree_hash(reinterpret_cast<const char (*)[HASH_SIZE]>(hashes), count, reinterpret_cast<char *>(&root_hash));
332 }
333
334 inline std::ostream &operator <<(std::ostream &o, const crypto::hash &v) {
336 }
337 inline std::ostream &operator <<(std::ostream &o, const crypto::hash8 &v) {
339 }
340 inline std::ostream &operator <<(std::ostream &o, const crypto::hash64 &v) {
342 }
343
344 const static crypto::hash null_hash = boost::value_initialized<crypto::hash>();
345 const static crypto::hash8 null_hash8 = boost::value_initialized<crypto::hash8>();
346 const static crypto::hash64 null_hash64 = boost::value_initialized<crypto::hash64>();
347}
348

◆ FIELD_N

#define FIELD_N ( t,
f )
Value:
do { \
ar.tag(t); \
bool r = ::do_serialize(ar, f); \
if (!r || !ar.stream().good()) return false; \
} while(0);

serializes a field f tagged t

\macro FIELD_N(t,f)

Definition at line 233 of file hash.h.

233// Copyrights(c) 2017-2021, The Electroneum Project
234// Copyrights(c) 2014-2019, The Monero Project
235//
236// All rights reserved.
237//
238// Redistribution and use in source and binary forms, with or without modification, are
239// permitted provided that the following conditions are met:
240//
241// 1. Redistributions of source code must retain the above copyright notice, this list of
242// conditions and the following disclaimer.
243//
244// 2. Redistributions in binary form must reproduce the above copyright notice, this list
245// of conditions and the following disclaimer in the documentation and/or other
246// materials provided with the distribution.
247//
248// 3. Neither the name of the copyright holder nor the names of its contributors may be
249// used to endorse or promote products derived from this software without specific
250// prior written permission.
251//
252// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
253// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
254// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
255// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
256// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
257// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
258// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
259// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
260// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
261//
262// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
263
264#pragma once
265
266#include <stddef.h>
267#include <iostream>
268#include <boost/utility/value_init.hpp>
269
270#include "common/pod-class.h"
271#include "generic-ops.h"
272#include "hex.h"
273#include "span.h"
274
275namespace crypto {
276
277 extern "C" {
278#include "hash-ops.h"
279 }
280
281#pragma pack(push, 1)
283 char data[HASH_SIZE];
284 };
286 char data[8];
287 };
289 char data[64];
290 };
291#pragma pack(pop)
292
293 static_assert(sizeof(hash) == HASH_SIZE, "Invalid structure size");
294 static_assert(sizeof(hash8) == 8, "Invalid structure size");
295 static_assert(sizeof(hash64) == 64, "Invalid structure size");
296
297 /*
298 Cryptonight hash functions
299 */
300
301 inline void cn_fast_hash(const void *data, std::size_t length, hash &hash) {
302 cn_fast_hash(data, length, reinterpret_cast<char *>(&hash));
303 }
304
305 inline hash cn_fast_hash(const void *data, std::size_t length) {
306 hash h;
307 cn_fast_hash(data, length, reinterpret_cast<char *>(&h));
308 return h;
309 }
310
311 inline void cn_slow_hash(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
312 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 0/*prehashed*/, height);
313 }
314
315 inline void cn_slow_hash_prehashed(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
316 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 1/*prehashed*/, height);
317 }
318
319 inline void tree_hash(const hash *hashes, std::size_t count, hash &root_hash) {
320 tree_hash(reinterpret_cast<const char (*)[HASH_SIZE]>(hashes), count, reinterpret_cast<char *>(&root_hash));
321 }
322
323 inline std::ostream &operator <<(std::ostream &o, const crypto::hash &v) {
325 }
326 inline std::ostream &operator <<(std::ostream &o, const crypto::hash8 &v) {
328 }
329 inline std::ostream &operator <<(std::ostream &o, const crypto::hash64 &v) {
331 }
332
333 const static crypto::hash null_hash = boost::value_initialized<crypto::hash>();
334 const static crypto::hash8 null_hash8 = boost::value_initialized<crypto::hash8>();
335 const static crypto::hash64 null_hash64 = boost::value_initialized<crypto::hash64>();
336}
337

◆ FIELDS

#define FIELDS ( f)
Value:
do { \
bool r = ::do_serialize(ar, f); \
if (!r || !ar.stream().good()) return false; \
} while(0);

does not add a tag to the serialized value

\macro FIELDS(f)

Definition at line 255 of file hash.h.

255// Copyrights(c) 2017-2021, The Electroneum Project
256// Copyrights(c) 2014-2019, The Monero Project
257//
258// All rights reserved.
259//
260// Redistribution and use in source and binary forms, with or without modification, are
261// permitted provided that the following conditions are met:
262//
263// 1. Redistributions of source code must retain the above copyright notice, this list of
264// conditions and the following disclaimer.
265//
266// 2. Redistributions in binary form must reproduce the above copyright notice, this list
267// of conditions and the following disclaimer in the documentation and/or other
268// materials provided with the distribution.
269//
270// 3. Neither the name of the copyright holder nor the names of its contributors may be
271// used to endorse or promote products derived from this software without specific
272// prior written permission.
273//
274// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
275// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
276// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
277// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
278// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
279// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
280// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
281// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
282// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
283//
284// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
285
286#pragma once
287
288#include <stddef.h>
289#include <iostream>
290#include <boost/utility/value_init.hpp>
291
292#include "common/pod-class.h"
293#include "generic-ops.h"
294#include "hex.h"
295#include "span.h"
296
297namespace crypto {
298
299 extern "C" {
300#include "hash-ops.h"
301 }
302
303#pragma pack(push, 1)
305 char data[HASH_SIZE];
306 };
308 char data[8];
309 };
311 char data[64];
312 };
313#pragma pack(pop)
314
315 static_assert(sizeof(hash) == HASH_SIZE, "Invalid structure size");
316 static_assert(sizeof(hash8) == 8, "Invalid structure size");
317 static_assert(sizeof(hash64) == 64, "Invalid structure size");
318
319 /*
320 Cryptonight hash functions
321 */
322
323 inline void cn_fast_hash(const void *data, std::size_t length, hash &hash) {
324 cn_fast_hash(data, length, reinterpret_cast<char *>(&hash));
325 }
326
327 inline hash cn_fast_hash(const void *data, std::size_t length) {
328 hash h;
329 cn_fast_hash(data, length, reinterpret_cast<char *>(&h));
330 return h;
331 }
332
333 inline void cn_slow_hash(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
334 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 0/*prehashed*/, height);
335 }
336
337 inline void cn_slow_hash_prehashed(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
338 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 1/*prehashed*/, height);
339 }
340
341 inline void tree_hash(const hash *hashes, std::size_t count, hash &root_hash) {
342 tree_hash(reinterpret_cast<const char (*)[HASH_SIZE]>(hashes), count, reinterpret_cast<char *>(&root_hash));
343 }
344
345 inline std::ostream &operator <<(std::ostream &o, const crypto::hash &v) {
347 }
348 inline std::ostream &operator <<(std::ostream &o, const crypto::hash8 &v) {
350 }
351 inline std::ostream &operator <<(std::ostream &o, const crypto::hash64 &v) {
353 }
354
355 const static crypto::hash null_hash = boost::value_initialized<crypto::hash>();
356 const static crypto::hash8 null_hash8 = boost::value_initialized<crypto::hash8>();
357 const static crypto::hash64 null_hash64 = boost::value_initialized<crypto::hash64>();
358}
359

◆ FREE_SERIALIZER

#define FREE_SERIALIZER ( T)
Value:
template<> \
typedef boost::true_type type; \
}
a descriptor for dispatching serialize

adds the has_free_serializer to the type

\macro FREE_SERIALIZER

Definition at line 158 of file hash.h.

158// Copyrights(c) 2017-2021, The Electroneum Project
159// Copyrights(c) 2014-2019, The Monero Project
160//
161// All rights reserved.
162//
163// Redistribution and use in source and binary forms, with or without modification, are
164// permitted provided that the following conditions are met:
165//
166// 1. Redistributions of source code must retain the above copyright notice, this list of
167// conditions and the following disclaimer.
168//
169// 2. Redistributions in binary form must reproduce the above copyright notice, this list
170// of conditions and the following disclaimer in the documentation and/or other
171// materials provided with the distribution.
172//
173// 3. Neither the name of the copyright holder nor the names of its contributors may be
174// used to endorse or promote products derived from this software without specific
175// prior written permission.
176//
177// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
178// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
179// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
180// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
181// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
182// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
183// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
184// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
185// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
186//
187// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
188
189#pragma once
190
191#include <stddef.h>
192#include <iostream>
193#include <boost/utility/value_init.hpp>
194
195#include "common/pod-class.h"
196#include "generic-ops.h"
197#include "hex.h"
198#include "span.h"
199
200namespace crypto {
201
202 extern "C" {
203#include "hash-ops.h"
204 }
205
206#pragma pack(push, 1)
208 char data[HASH_SIZE];
209 };
211 char data[8];
212 };
214 char data[64];
215 };
216#pragma pack(pop)
217
218 static_assert(sizeof(hash) == HASH_SIZE, "Invalid structure size");
219 static_assert(sizeof(hash8) == 8, "Invalid structure size");
220 static_assert(sizeof(hash64) == 64, "Invalid structure size");
221
222 /*
223 Cryptonight hash functions
224 */
225
226 inline void cn_fast_hash(const void *data, std::size_t length, hash &hash) {
227 cn_fast_hash(data, length, reinterpret_cast<char *>(&hash));
228 }
229
230 inline hash cn_fast_hash(const void *data, std::size_t length) {
231 hash h;
232 cn_fast_hash(data, length, reinterpret_cast<char *>(&h));
233 return h;
234 }
235
236 inline void cn_slow_hash(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
237 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 0/*prehashed*/, height);
238 }
239
240 inline void cn_slow_hash_prehashed(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
241 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 1/*prehashed*/, height);
242 }
243
244 inline void tree_hash(const hash *hashes, std::size_t count, hash &root_hash) {
245 tree_hash(reinterpret_cast<const char (*)[HASH_SIZE]>(hashes), count, reinterpret_cast<char *>(&root_hash));
246 }
247
248 inline std::ostream &operator <<(std::ostream &o, const crypto::hash &v) {
250 }
251 inline std::ostream &operator <<(std::ostream &o, const crypto::hash8 &v) {
253 }
254 inline std::ostream &operator <<(std::ostream &o, const crypto::hash64 &v) {
256 }
257
258 const static crypto::hash null_hash = boost::value_initialized<crypto::hash>();
259 const static crypto::hash8 null_hash8 = boost::value_initialized<crypto::hash8>();
260 const static crypto::hash64 null_hash64 = boost::value_initialized<crypto::hash64>();
261}
262

◆ PREPARE_CUSTOM_DEQUE_SERIALIZATION

#define PREPARE_CUSTOM_DEQUE_SERIALIZATION ( size,
vec )
Value:
::serialization::detail::prepare_custom_deque_serialization(size, vec, typename Archive<W>::is_saving())
void prepare_custom_deque_serialization(size_t size, std::deque< T > &vec, const boost::mpl::bool_< true > &)

\macro PREPARE_CUSTOM_DEQUE_SERIALIZATION

Definition at line 209 of file hash.h.

209// Copyrights(c) 2017-2021, The Electroneum Project
210// Copyrights(c) 2014-2019, The Monero Project
211//
212// All rights reserved.
213//
214// Redistribution and use in source and binary forms, with or without modification, are
215// permitted provided that the following conditions are met:
216//
217// 1. Redistributions of source code must retain the above copyright notice, this list of
218// conditions and the following disclaimer.
219//
220// 2. Redistributions in binary form must reproduce the above copyright notice, this list
221// of conditions and the following disclaimer in the documentation and/or other
222// materials provided with the distribution.
223//
224// 3. Neither the name of the copyright holder nor the names of its contributors may be
225// used to endorse or promote products derived from this software without specific
226// prior written permission.
227//
228// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
229// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
230// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
231// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
232// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
233// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
234// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
235// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
236// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
237//
238// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
239
240#pragma once
241
242#include <stddef.h>
243#include <iostream>
244#include <boost/utility/value_init.hpp>
245
246#include "common/pod-class.h"
247#include "generic-ops.h"
248#include "hex.h"
249#include "span.h"
250
251namespace crypto {
252
253 extern "C" {
254#include "hash-ops.h"
255 }
256
257#pragma pack(push, 1)
259 char data[HASH_SIZE];
260 };
262 char data[8];
263 };
265 char data[64];
266 };
267#pragma pack(pop)
268
269 static_assert(sizeof(hash) == HASH_SIZE, "Invalid structure size");
270 static_assert(sizeof(hash8) == 8, "Invalid structure size");
271 static_assert(sizeof(hash64) == 64, "Invalid structure size");
272
273 /*
274 Cryptonight hash functions
275 */
276
277 inline void cn_fast_hash(const void *data, std::size_t length, hash &hash) {
278 cn_fast_hash(data, length, reinterpret_cast<char *>(&hash));
279 }
280
281 inline hash cn_fast_hash(const void *data, std::size_t length) {
282 hash h;
283 cn_fast_hash(data, length, reinterpret_cast<char *>(&h));
284 return h;
285 }
286
287 inline void cn_slow_hash(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
288 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 0/*prehashed*/, height);
289 }
290
291 inline void cn_slow_hash_prehashed(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
292 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 1/*prehashed*/, height);
293 }
294
295 inline void tree_hash(const hash *hashes, std::size_t count, hash &root_hash) {
296 tree_hash(reinterpret_cast<const char (*)[HASH_SIZE]>(hashes), count, reinterpret_cast<char *>(&root_hash));
297 }
298
299 inline std::ostream &operator <<(std::ostream &o, const crypto::hash &v) {
301 }
302 inline std::ostream &operator <<(std::ostream &o, const crypto::hash8 &v) {
304 }
305 inline std::ostream &operator <<(std::ostream &o, const crypto::hash64 &v) {
307 }
308
309 const static crypto::hash null_hash = boost::value_initialized<crypto::hash>();
310 const static crypto::hash8 null_hash8 = boost::value_initialized<crypto::hash8>();
311 const static crypto::hash64 null_hash64 = boost::value_initialized<crypto::hash64>();
312}
313

◆ PREPARE_CUSTOM_VECTOR_SERIALIZATION

#define PREPARE_CUSTOM_VECTOR_SERIALIZATION ( size,
vec )
Value:
::serialization::detail::prepare_custom_vector_serialization(size, vec, typename Archive<W>::is_saving())
void prepare_custom_vector_serialization(size_t size, std::vector< T > &vec, const boost::mpl::bool_< true > &)

\macro PREPARE_CUSTOM_VECTOR_SERIALIZATION

Definition at line 204 of file hash.h.

204// Copyrights(c) 2017-2021, The Electroneum Project
205// Copyrights(c) 2014-2019, The Monero Project
206//
207// All rights reserved.
208//
209// Redistribution and use in source and binary forms, with or without modification, are
210// permitted provided that the following conditions are met:
211//
212// 1. Redistributions of source code must retain the above copyright notice, this list of
213// conditions and the following disclaimer.
214//
215// 2. Redistributions in binary form must reproduce the above copyright notice, this list
216// of conditions and the following disclaimer in the documentation and/or other
217// materials provided with the distribution.
218//
219// 3. Neither the name of the copyright holder nor the names of its contributors may be
220// used to endorse or promote products derived from this software without specific
221// prior written permission.
222//
223// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
224// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
225// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
226// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
227// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
228// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
229// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
230// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
231// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
232//
233// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
234
235#pragma once
236
237#include <stddef.h>
238#include <iostream>
239#include <boost/utility/value_init.hpp>
240
241#include "common/pod-class.h"
242#include "generic-ops.h"
243#include "hex.h"
244#include "span.h"
245
246namespace crypto {
247
248 extern "C" {
249#include "hash-ops.h"
250 }
251
252#pragma pack(push, 1)
254 char data[HASH_SIZE];
255 };
257 char data[8];
258 };
260 char data[64];
261 };
262#pragma pack(pop)
263
264 static_assert(sizeof(hash) == HASH_SIZE, "Invalid structure size");
265 static_assert(sizeof(hash8) == 8, "Invalid structure size");
266 static_assert(sizeof(hash64) == 64, "Invalid structure size");
267
268 /*
269 Cryptonight hash functions
270 */
271
272 inline void cn_fast_hash(const void *data, std::size_t length, hash &hash) {
273 cn_fast_hash(data, length, reinterpret_cast<char *>(&hash));
274 }
275
276 inline hash cn_fast_hash(const void *data, std::size_t length) {
277 hash h;
278 cn_fast_hash(data, length, reinterpret_cast<char *>(&h));
279 return h;
280 }
281
282 inline void cn_slow_hash(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
283 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 0/*prehashed*/, height);
284 }
285
286 inline void cn_slow_hash_prehashed(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
287 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 1/*prehashed*/, height);
288 }
289
290 inline void tree_hash(const hash *hashes, std::size_t count, hash &root_hash) {
291 tree_hash(reinterpret_cast<const char (*)[HASH_SIZE]>(hashes), count, reinterpret_cast<char *>(&root_hash));
292 }
293
294 inline std::ostream &operator <<(std::ostream &o, const crypto::hash &v) {
296 }
297 inline std::ostream &operator <<(std::ostream &o, const crypto::hash8 &v) {
299 }
300 inline std::ostream &operator <<(std::ostream &o, const crypto::hash64 &v) {
302 }
303
304 const static crypto::hash null_hash = boost::value_initialized<crypto::hash>();
305 const static crypto::hash8 null_hash8 = boost::value_initialized<crypto::hash8>();
306 const static crypto::hash64 null_hash64 = boost::value_initialized<crypto::hash64>();
307}
308

◆ VALUE

#define VALUE ( f)
Value:
do { \
ar.tag(#f); \
bool r = ::do_serialize(ar, f); \
if (!r || !ar.stream().good()) return false; \
} while(0);

the same as FIELD(f)

\macro VALUE(f)

Definition at line 222 of file hash.h.

222// Copyrights(c) 2017-2021, The Electroneum Project
223// Copyrights(c) 2014-2019, The Monero Project
224//
225// All rights reserved.
226//
227// Redistribution and use in source and binary forms, with or without modification, are
228// permitted provided that the following conditions are met:
229//
230// 1. Redistributions of source code must retain the above copyright notice, this list of
231// conditions and the following disclaimer.
232//
233// 2. Redistributions in binary form must reproduce the above copyright notice, this list
234// of conditions and the following disclaimer in the documentation and/or other
235// materials provided with the distribution.
236//
237// 3. Neither the name of the copyright holder nor the names of its contributors may be
238// used to endorse or promote products derived from this software without specific
239// prior written permission.
240//
241// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
242// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
243// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
244// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
245// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
246// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
247// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
248// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
249// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
250//
251// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
252
253#pragma once
254
255#include <stddef.h>
256#include <iostream>
257#include <boost/utility/value_init.hpp>
258
259#include "common/pod-class.h"
260#include "generic-ops.h"
261#include "hex.h"
262#include "span.h"
263
264namespace crypto {
265
266 extern "C" {
267#include "hash-ops.h"
268 }
269
270#pragma pack(push, 1)
272 char data[HASH_SIZE];
273 };
275 char data[8];
276 };
278 char data[64];
279 };
280#pragma pack(pop)
281
282 static_assert(sizeof(hash) == HASH_SIZE, "Invalid structure size");
283 static_assert(sizeof(hash8) == 8, "Invalid structure size");
284 static_assert(sizeof(hash64) == 64, "Invalid structure size");
285
286 /*
287 Cryptonight hash functions
288 */
289
290 inline void cn_fast_hash(const void *data, std::size_t length, hash &hash) {
291 cn_fast_hash(data, length, reinterpret_cast<char *>(&hash));
292 }
293
294 inline hash cn_fast_hash(const void *data, std::size_t length) {
295 hash h;
296 cn_fast_hash(data, length, reinterpret_cast<char *>(&h));
297 return h;
298 }
299
300 inline void cn_slow_hash(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
301 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 0/*prehashed*/, height);
302 }
303
304 inline void cn_slow_hash_prehashed(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
305 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 1/*prehashed*/, height);
306 }
307
308 inline void tree_hash(const hash *hashes, std::size_t count, hash &root_hash) {
309 tree_hash(reinterpret_cast<const char (*)[HASH_SIZE]>(hashes), count, reinterpret_cast<char *>(&root_hash));
310 }
311
312 inline std::ostream &operator <<(std::ostream &o, const crypto::hash &v) {
314 }
315 inline std::ostream &operator <<(std::ostream &o, const crypto::hash8 &v) {
317 }
318 inline std::ostream &operator <<(std::ostream &o, const crypto::hash64 &v) {
320 }
321
322 const static crypto::hash null_hash = boost::value_initialized<crypto::hash>();
323 const static crypto::hash8 null_hash8 = boost::value_initialized<crypto::hash8>();
324 const static crypto::hash64 null_hash64 = boost::value_initialized<crypto::hash64>();
325}
326

◆ VARIANT_TAG

#define VARIANT_TAG ( Archive,
Type,
Tag )
Value:
template <bool W> \
struct variant_serialization_traits<Archive<W>, Type> { \
static inline typename Archive<W>::variant_tag_type get_tag() { \
return Tag; \
} \
}
Type
Type of JSON value.
Definition rapidjson.h:620

Adds the tag \tag to the Archive of Type.

\macro VARIANT_TAG

Definition at line 168 of file hash.h.

168// Copyrights(c) 2017-2021, The Electroneum Project
169// Copyrights(c) 2014-2019, The Monero Project
170//
171// All rights reserved.
172//
173// Redistribution and use in source and binary forms, with or without modification, are
174// permitted provided that the following conditions are met:
175//
176// 1. Redistributions of source code must retain the above copyright notice, this list of
177// conditions and the following disclaimer.
178//
179// 2. Redistributions in binary form must reproduce the above copyright notice, this list
180// of conditions and the following disclaimer in the documentation and/or other
181// materials provided with the distribution.
182//
183// 3. Neither the name of the copyright holder nor the names of its contributors may be
184// used to endorse or promote products derived from this software without specific
185// prior written permission.
186//
187// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
188// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
189// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
190// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
191// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
192// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
193// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
194// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
195// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
196//
197// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
198
199#pragma once
200
201#include <stddef.h>
202#include <iostream>
203#include <boost/utility/value_init.hpp>
204
205#include "common/pod-class.h"
206#include "generic-ops.h"
207#include "hex.h"
208#include "span.h"
209
210namespace crypto {
211
212 extern "C" {
213#include "hash-ops.h"
214 }
215
216#pragma pack(push, 1)
218 char data[HASH_SIZE];
219 };
221 char data[8];
222 };
224 char data[64];
225 };
226#pragma pack(pop)
227
228 static_assert(sizeof(hash) == HASH_SIZE, "Invalid structure size");
229 static_assert(sizeof(hash8) == 8, "Invalid structure size");
230 static_assert(sizeof(hash64) == 64, "Invalid structure size");
231
232 /*
233 Cryptonight hash functions
234 */
235
236 inline void cn_fast_hash(const void *data, std::size_t length, hash &hash) {
237 cn_fast_hash(data, length, reinterpret_cast<char *>(&hash));
238 }
239
240 inline hash cn_fast_hash(const void *data, std::size_t length) {
241 hash h;
242 cn_fast_hash(data, length, reinterpret_cast<char *>(&h));
243 return h;
244 }
245
246 inline void cn_slow_hash(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
247 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 0/*prehashed*/, height);
248 }
249
250 inline void cn_slow_hash_prehashed(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
251 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 1/*prehashed*/, height);
252 }
253
254 inline void tree_hash(const hash *hashes, std::size_t count, hash &root_hash) {
255 tree_hash(reinterpret_cast<const char (*)[HASH_SIZE]>(hashes), count, reinterpret_cast<char *>(&root_hash));
256 }
257
258 inline std::ostream &operator <<(std::ostream &o, const crypto::hash &v) {
260 }
261 inline std::ostream &operator <<(std::ostream &o, const crypto::hash8 &v) {
263 }
264 inline std::ostream &operator <<(std::ostream &o, const crypto::hash64 &v) {
266 }
267
268 const static crypto::hash null_hash = boost::value_initialized<crypto::hash>();
269 const static crypto::hash8 null_hash8 = boost::value_initialized<crypto::hash8>();
270 const static crypto::hash64 null_hash64 = boost::value_initialized<crypto::hash64>();
271}
272

◆ VARINT_FIELD

#define VARINT_FIELD ( f)
Value:
do { \
ar.tag(#f); \
ar.serialize_varint(f); \
if (!ar.stream().good()) return false; \
} while(0);

tags and serializes the varint f

\macro VARINT_FIELD(f)

Definition at line 264 of file hash.h.

264// Copyrights(c) 2017-2021, The Electroneum Project
265// Copyrights(c) 2014-2019, The Monero Project
266//
267// All rights reserved.
268//
269// Redistribution and use in source and binary forms, with or without modification, are
270// permitted provided that the following conditions are met:
271//
272// 1. Redistributions of source code must retain the above copyright notice, this list of
273// conditions and the following disclaimer.
274//
275// 2. Redistributions in binary form must reproduce the above copyright notice, this list
276// of conditions and the following disclaimer in the documentation and/or other
277// materials provided with the distribution.
278//
279// 3. Neither the name of the copyright holder nor the names of its contributors may be
280// used to endorse or promote products derived from this software without specific
281// prior written permission.
282//
283// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
284// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
285// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
286// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
287// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
288// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
289// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
290// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
291// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
292//
293// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
294
295#pragma once
296
297#include <stddef.h>
298#include <iostream>
299#include <boost/utility/value_init.hpp>
300
301#include "common/pod-class.h"
302#include "generic-ops.h"
303#include "hex.h"
304#include "span.h"
305
306namespace crypto {
307
308 extern "C" {
309#include "hash-ops.h"
310 }
311
312#pragma pack(push, 1)
314 char data[HASH_SIZE];
315 };
317 char data[8];
318 };
320 char data[64];
321 };
322#pragma pack(pop)
323
324 static_assert(sizeof(hash) == HASH_SIZE, "Invalid structure size");
325 static_assert(sizeof(hash8) == 8, "Invalid structure size");
326 static_assert(sizeof(hash64) == 64, "Invalid structure size");
327
328 /*
329 Cryptonight hash functions
330 */
331
332 inline void cn_fast_hash(const void *data, std::size_t length, hash &hash) {
333 cn_fast_hash(data, length, reinterpret_cast<char *>(&hash));
334 }
335
336 inline hash cn_fast_hash(const void *data, std::size_t length) {
337 hash h;
338 cn_fast_hash(data, length, reinterpret_cast<char *>(&h));
339 return h;
340 }
341
342 inline void cn_slow_hash(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
343 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 0/*prehashed*/, height);
344 }
345
346 inline void cn_slow_hash_prehashed(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
347 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 1/*prehashed*/, height);
348 }
349
350 inline void tree_hash(const hash *hashes, std::size_t count, hash &root_hash) {
351 tree_hash(reinterpret_cast<const char (*)[HASH_SIZE]>(hashes), count, reinterpret_cast<char *>(&root_hash));
352 }
353
354 inline std::ostream &operator <<(std::ostream &o, const crypto::hash &v) {
356 }
357 inline std::ostream &operator <<(std::ostream &o, const crypto::hash8 &v) {
359 }
360 inline std::ostream &operator <<(std::ostream &o, const crypto::hash64 &v) {
362 }
363
364 const static crypto::hash null_hash = boost::value_initialized<crypto::hash>();
365 const static crypto::hash8 null_hash8 = boost::value_initialized<crypto::hash8>();
366 const static crypto::hash64 null_hash64 = boost::value_initialized<crypto::hash64>();
367}
368

◆ VARINT_FIELD_N

#define VARINT_FIELD_N ( t,
f )
Value:
do { \
ar.tag(t); \
ar.serialize_varint(f); \
if (!ar.stream().good()) return false; \
} while(0);

tags (as t) and serializes the varint f

\macro VARINT_FIELD_N(t, f)

Definition at line 275 of file hash.h.

275// Copyrights(c) 2017-2021, The Electroneum Project
276// Copyrights(c) 2014-2019, The Monero Project
277//
278// All rights reserved.
279//
280// Redistribution and use in source and binary forms, with or without modification, are
281// permitted provided that the following conditions are met:
282//
283// 1. Redistributions of source code must retain the above copyright notice, this list of
284// conditions and the following disclaimer.
285//
286// 2. Redistributions in binary form must reproduce the above copyright notice, this list
287// of conditions and the following disclaimer in the documentation and/or other
288// materials provided with the distribution.
289//
290// 3. Neither the name of the copyright holder nor the names of its contributors may be
291// used to endorse or promote products derived from this software without specific
292// prior written permission.
293//
294// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
295// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
296// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
297// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
298// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
299// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
300// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
301// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
302// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
303//
304// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
305
306#pragma once
307
308#include <stddef.h>
309#include <iostream>
310#include <boost/utility/value_init.hpp>
311
312#include "common/pod-class.h"
313#include "generic-ops.h"
314#include "hex.h"
315#include "span.h"
316
317namespace crypto {
318
319 extern "C" {
320#include "hash-ops.h"
321 }
322
323#pragma pack(push, 1)
325 char data[HASH_SIZE];
326 };
328 char data[8];
329 };
331 char data[64];
332 };
333#pragma pack(pop)
334
335 static_assert(sizeof(hash) == HASH_SIZE, "Invalid structure size");
336 static_assert(sizeof(hash8) == 8, "Invalid structure size");
337 static_assert(sizeof(hash64) == 64, "Invalid structure size");
338
339 /*
340 Cryptonight hash functions
341 */
342
343 inline void cn_fast_hash(const void *data, std::size_t length, hash &hash) {
344 cn_fast_hash(data, length, reinterpret_cast<char *>(&hash));
345 }
346
347 inline hash cn_fast_hash(const void *data, std::size_t length) {
348 hash h;
349 cn_fast_hash(data, length, reinterpret_cast<char *>(&h));
350 return h;
351 }
352
353 inline void cn_slow_hash(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
354 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 0/*prehashed*/, height);
355 }
356
357 inline void cn_slow_hash_prehashed(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
358 cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 1/*prehashed*/, height);
359 }
360
361 inline void tree_hash(const hash *hashes, std::size_t count, hash &root_hash) {
362 tree_hash(reinterpret_cast<const char (*)[HASH_SIZE]>(hashes), count, reinterpret_cast<char *>(&root_hash));
363 }
364
365 inline std::ostream &operator <<(std::ostream &o, const crypto::hash &v) {
367 }
368 inline std::ostream &operator <<(std::ostream &o, const crypto::hash8 &v) {
370 }
371 inline std::ostream &operator <<(std::ostream &o, const crypto::hash64 &v) {
373 }
374
375 const static crypto::hash null_hash = boost::value_initialized<crypto::hash>();
376 const static crypto::hash8 null_hash8 = boost::value_initialized<crypto::hash8>();
377 const static crypto::hash64 null_hash64 = boost::value_initialized<crypto::hash64>();
378}
379

Function Documentation

◆ do_serialize() [1/2]

template<class Archive>
bool do_serialize ( Archive & ar,
bool & v )
inline

Definition at line 128 of file serialization.h.

129{
130 ar.serialize_blob(&v, sizeof(v));
131 return true;
132}

◆ do_serialize() [2/2]

template<class Archive, class T>
bool do_serialize ( Archive & ar,
T & v )
inline

just calls the serialize function defined for ar and v...

Definition at line 123 of file serialization.h.

124{
125 return ::serializer<Archive, T>::serialize(ar, v);
126}
Here is the caller graph for this function: