25 #ifndef CRYPTO3_DETAIL_IMPLODER_HPP
26 #define CRYPTO3_DETAIL_IMPLODER_HPP
28 #include <nil/crypto3/detail/stream_endian.hpp>
29 #include <nil/crypto3/detail/unbounded_shift.hpp>
31 #include <boost/static_assert.hpp>
44 template<
typename Endianness,
int InputBits,
int OutputBits,
int k>
47 template<
int UnitBits,
int InputBits,
int OutputBits,
int k>
48 struct imploder_step<stream_endian::big_unit_big_bit<UnitBits>, InputBits, OutputBits, k> {
49 template<
typename InputValue,
typename OutputValue>
50 static void step(InputValue z, OutputValue &x) {
51 int const shift = OutputBits - (InputBits + k);
52 OutputValue y = low_bits<InputBits>(OutputValue(z));
53 x |= unbounded_shl<shift>(y);
57 template<
int UnitBits,
int InputBits,
int OutputBits,
int k>
58 struct imploder_step<stream_endian::little_unit_big_bit<UnitBits>, InputBits, OutputBits, k> {
59 template<
typename InputValue,
typename OutputValue>
60 static void step(InputValue z, OutputValue &x) {
61 int const kb = (k % UnitBits);
62 int const ku = k - kb;
63 int const shift = InputBits >= UnitBits ? k : OutputBits >= UnitBits ? ku + (UnitBits -
64 (InputBits + kb)) : OutputBits - (InputBits + kb);
65 OutputValue y = low_bits<InputBits>(OutputValue(z));
66 x |= unbounded_shl<shift>(y);
70 template<
int UnitBits,
int InputBits,
int OutputBits,
int k>
71 struct imploder_step<stream_endian::big_unit_little_bit < UnitBits>, InputBits, OutputBits, k> {
72 template<
typename InputValue,
typename OutputValue>
73 static void step(InputValue z, OutputValue &x) {
74 int const kb = (k % UnitBits);
75 int const ku = k - kb;
76 int const shift = InputBits >= UnitBits ? OutputBits - (InputBits + k) : OutputBits >=
77 UnitBits ? OutputBits - (UnitBits + ku) + kb : kb;
78 OutputValue y = low_bits<InputBits>(OutputValue(z));
79 x |= unbounded_shl<shift>(y);
83 template<
int UnitBits,
int InputBits,
int OutputBits,
int k>
84 struct imploder_step<stream_endian::little_unit_little_bit < UnitBits>, InputBits, OutputBits, k> {
85 template<
typename InputValue,
typename OutputValue>
86 static void step(InputValue z, OutputValue &x) {
88 OutputValue y = low_bits<InputBits>(OutputValue(z));
89 x |= unbounded_shl<shift>(y);
93 template<
int UnitBits,
int InputBits,
int OutputBits,
int k>
94 struct imploder_step<stream_endian::host_unit < UnitBits>, InputBits, OutputBits, k> {
95 template<
typename InputValue,
typename OutputValue>
96 static void step(InputValue z, OutputValue &x) {
97 BOOST_STATIC_ASSERT(
sizeof(InputValue) * CHAR_BIT == InputBits);
98 BOOST_STATIC_ASSERT(
sizeof(OutputValue) * CHAR_BIT == OutputBits);
99 std::memcpy((
char *) &x + k / CHAR_BIT, &z, InputBits / CHAR_BIT);
103 template<
typename Endianness,
int InputBits,
int OutputBits,
int k = 0>
106 template<
template<
int>
class Endian,
int UnitBits,
int InputBits,
int OutputBits,
int k>
107 struct imploder<Endian<UnitBits>, InputBits, OutputBits, k> {
120 template<
typename InIter,
typename OutputValue>
121 static void implode(InIter &in, OutputValue &x) {
122 step_type::step(*in++, x);
123 next_type::implode(in, x);
127 template<
template<
int>
class Endian,
int UnitBits,
int InputBits,
int OutputBits>
128 struct imploder<Endian<UnitBits>, InputBits, OutputBits, OutputBits> {
129 template<
typename InIter,
typename OutputValue>
130 static void implode(InIter &, OutputValue &) {
static void step(InputValue z, OutputValue &x)
Definition: passhash/include/nil/crypto3/detail/imploder.hpp:50
static void step(InputValue z, OutputValue &x)
Definition: passhash/include/nil/crypto3/detail/imploder.hpp:73
static void step(InputValue z, OutputValue &x)
Definition: passhash/include/nil/crypto3/detail/imploder.hpp:96
static void step(InputValue z, OutputValue &x)
Definition: passhash/include/nil/crypto3/detail/imploder.hpp:60
static void step(InputValue z, OutputValue &x)
Definition: passhash/include/nil/crypto3/detail/imploder.hpp:86
imploder_step packs an input value represented in InputEndianness endianness into an output value rep...
Definition: block/include/nil/crypto3/detail/imploder.hpp:93
constexpr static int const shift
Definition: block/include/nil/crypto3/detail/imploder.hpp:94
imploder processes a sequence of input values represented in InputEndianness endianness into an outpu...
Definition: block/include/nil/crypto3/detail/imploder.hpp:122