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>
43 template<
typename Endianness,
int InputBits,
int OutputBits,
int k>
46 template<
int UnitBits,
int InputBits,
int OutputBits,
int k>
47 struct imploder_step<stream_endian::big_unit_big_bit<UnitBits>, InputBits, OutputBits, k> {
48 template<
typename InputValue,
typename OutputValue>
49 static void step(InputValue z, OutputValue &x) {
50 int const shift = OutputBits - (InputBits + k);
51 OutputValue y = low_bits<InputBits>(OutputValue(z));
52 x |= unbounded_shl<shift>(y);
56 template<
int UnitBits,
int InputBits,
int OutputBits,
int k>
57 struct imploder_step<stream_endian::little_unit_big_bit<UnitBits>, InputBits, OutputBits, k> {
58 template<
typename InputValue,
typename OutputValue>
59 static void step(InputValue z, OutputValue &x) {
60 int const kb = (k % UnitBits);
61 int const ku = k - kb;
63 InputBits >= UnitBits ?
65 OutputBits >= UnitBits ? ku + (UnitBits - (InputBits + kb)) : OutputBits - (InputBits + kb);
66 OutputValue y = low_bits<InputBits>(OutputValue(z));
67 x |= unbounded_shl<shift>(y);
71 template<
int UnitBits,
int InputBits,
int OutputBits,
int k>
72 struct imploder_step<stream_endian::big_unit_little_bit<UnitBits>, InputBits, OutputBits, k> {
73 template<
typename InputValue,
typename OutputValue>
74 static void step(InputValue z, OutputValue &x) {
75 int const kb = (k % UnitBits);
76 int const ku = k - kb;
77 int const shift = InputBits >= UnitBits ?
78 OutputBits - (InputBits + k) :
79 OutputBits >= UnitBits ? OutputBits - (UnitBits + ku) + kb : kb;
80 OutputValue y = low_bits<InputBits>(OutputValue(z));
81 x |= unbounded_shl<shift>(y);
85 template<
int UnitBits,
int InputBits,
int OutputBits,
int k>
86 struct imploder_step<stream_endian::little_unit_little_bit<UnitBits>, InputBits, OutputBits, k> {
87 template<
typename InputValue,
typename OutputValue>
88 static void step(InputValue z, OutputValue &x) {
90 OutputValue y = low_bits<InputBits>(OutputValue(z));
91 x |= unbounded_shl<shift>(y);
95 template<
int UnitBits,
int InputBits,
int OutputBits,
int k>
96 struct imploder_step<stream_endian::host_unit<UnitBits>, InputBits, OutputBits, k> {
97 template<
typename InputValue,
typename OutputValue>
98 static void step(InputValue z, OutputValue &x) {
99 BOOST_STATIC_ASSERT(
sizeof(InputValue) * CHAR_BIT == InputBits);
100 BOOST_STATIC_ASSERT(
sizeof(OutputValue) * CHAR_BIT == OutputBits);
101 std::memcpy((
char *)&x + k / CHAR_BIT, &z, InputBits / CHAR_BIT);
105 template<
typename Endianness,
int InputBits,
int OutputBits,
int k = 0>
108 template<
template<
int>
class Endian,
int UnitBits,
int InputBits,
int OutputBits,
int k>
109 struct imploder<Endian<UnitBits>, InputBits, OutputBits, k> {
122 template<
typename InIter,
typename OutputValue>
123 static void implode(InIter &in, OutputValue &x) {
124 step_type::step(*in++, x);
125 next_type::implode(in, x);
129 template<
template<
int>
class Endian,
int UnitBits,
int InputBits,
int OutputBits>
130 struct imploder<Endian<UnitBits>, InputBits, OutputBits, OutputBits> {
131 template<
typename InIter,
typename OutputValue>
132 static void implode(InIter &, OutputValue &) {
static void step(InputValue z, OutputValue &x)
Definition: stream/include/nil/crypto3/detail/imploder.hpp:49
static void step(InputValue z, OutputValue &x)
Definition: stream/include/nil/crypto3/detail/imploder.hpp:74
static void step(InputValue z, OutputValue &x)
Definition: stream/include/nil/crypto3/detail/imploder.hpp:98
static void step(InputValue z, OutputValue &x)
Definition: stream/include/nil/crypto3/detail/imploder.hpp:59
static void step(InputValue z, OutputValue &x)
Definition: stream/include/nil/crypto3/detail/imploder.hpp:88
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