Zeth - Zerocash on Ethereum  0.8
Reference implementation of the Zeth protocol by Clearmatics
utils.hpp
Go to the documentation of this file.
1 // Copyright (c) 2015-2022 Clearmatics Technologies Ltd
2 //
3 // SPDX-License-Identifier: LGPL-3.0+
4 
5 #ifndef __ZETH_CORE_UTILS_HPP__
6 #define __ZETH_CORE_UTILS_HPP__
7 
8 #include "libzeth/core/bits.hpp"
9 
10 #include <cstdint>
11 #include <gmp.h>
12 #include <string>
13 #include <vector>
14 
15 namespace libzeth
16 {
17 
19 template<size_t X> class bit_utils
20 {
21 public:
26  static constexpr size_t bit_size();
27 
32  static constexpr size_t hamming_weight();
33 };
34 
39 template<typename T> T swap_byte_endianness(T v);
40 
43 uint8_t char_to_nibble(const char c);
44 
46 void hex_to_bytes(const std::string &hex, void *dest, size_t bytes);
47 
50 void hex_to_bytes_reversed(const std::string &hex, void *dest, size_t bytes);
51 
53 std::string hex_to_bytes(const std::string &s);
54 
57 std::string bytes_to_hex(
58  const void *bytes, size_t num_bytes, bool prefix = false);
59 
62 std::string bytes_to_hex_reversed(
63  const void *bytes, size_t num_bytes, bool prefix = false);
64 
71 template<typename StructuredT>
72 void check_well_formed(const StructuredT &v, const char *name);
73 
76 template<typename StructuredTs>
77 bool container_is_well_formed(const StructuredTs &values);
78 
79 } // namespace libzeth
80 
81 #include "libzeth/core/utils.tcc"
82 
83 #endif // __ZETH_CORE_UTILS_HPP__
libzeth::hex_to_bytes
void hex_to_bytes(const std::string &hex, void *dest, size_t bytes)
Convert hex to bytes (first chars at lowest address)
Definition: utils.cpp:68
libzeth::bit_utils::bit_size
static constexpr size_t bit_size()
utils.tcc
libzeth::bit_utils::hamming_weight
static constexpr size_t hamming_weight()
libzeth::container_is_well_formed
bool container_is_well_formed(const StructuredTs &values)
libzeth
Definition: binary_operation.hpp:15
zeth.core.encryption.bytes
bytes
Definition: encryption.py:87
libzeth::check_well_formed
void check_well_formed(const StructuredT &v, const char *name)
libzeth::swap_byte_endianness
T swap_byte_endianness(T v)
libzeth::bytes_to_hex_reversed
std::string bytes_to_hex_reversed(const void *bytes, size_t num_bytes, bool prefix)
Definition: utils.cpp:126
setup.name
name
Definition: setup.py:20
libzeth::hex_to_bytes_reversed
void hex_to_bytes_reversed(const std::string &hex, void *dest, size_t bytes)
Definition: utils.cpp:80
bits.hpp
libzeth::char_to_nibble
uint8_t char_to_nibble(const char c)
Definition: utils.cpp:15
libzeth::bytes_to_hex
std::string bytes_to_hex(const void *bytes, size_t num_bytes, bool prefix)
Definition: utils.cpp:105
libzeth::bit_utils
Compile-time computations related to bit representations of size_t values.
Definition: utils.hpp:19