poseidon.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2020 Ilias Khairullin <ilias@nil.foundation>
3 // Copyright (c) 2020 Mikhail Komarov <nemo@nil.foundation>
4 //
5 // Distributed under the Boost Software License, Version 1.0
6 // See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt
8 //---------------------------------------------------------------------------//
9 
10 #ifndef CRYPTO3_HASH_POSEIDON_HPP
11 #define CRYPTO3_HASH_POSEIDON_HPP
12 
16 
17 namespace nil {
18  namespace crypto3 {
19  namespace hashes {
20  template<typename FieldType, std::size_t Arity, std::size_t PartRounds>
22  protected:
24 
25  public:
26  constexpr static const std::size_t word_bits = policy_type::word_bits;
28 
29  constexpr static const std::size_t state_bits = policy_type::state_bits;
30  constexpr static const std::size_t state_words = policy_type::state_words;
32 
33  constexpr static const std::size_t block_bits = policy_type::block_bits;
34  constexpr static const std::size_t block_words = policy_type::block_words;
36 
37  static void process_block(state_type &state, const block_type &block) {
38 
39  for (std::size_t i = 0; i < state_words; ++i)
40  state[i] ^= block[i];
41 
42  // for (std::size_t i = 0; i != state_words; ++i)
43  // boost::endian::endian_reverse_inplace(state[i]);
44 
45  policy_type::permute(state);
46 
47  // for (std::size_t i = 0; i != state_words; ++i)
48  // boost::endian::endian_reverse_inplace(state[i]);
49  }
50  };
51 
52  template<typename FieldType, std::size_t Arity, std::size_t PartRounds>
53  struct poseidon {
54  protected:
56 
57  public:
58  constexpr static const std::size_t word_bits = policy_type::word_bits;
59  typedef typename policy_type::word_type word_type;
60 
61  constexpr static const std::size_t block_bits = policy_type::block_bits;
62  constexpr static const std::size_t block_words = policy_type::block_words;
63  typedef typename policy_type::block_type block_type;
64 
65  constexpr static const std::size_t digest_bits = policy_type::digest_bits;
66  typedef typename policy_type::digest_type digest_type;
67 
68  struct construction {
69  struct params_type {
70  typedef typename policy_type::digest_endian digest_endian;
71 
72  // constexpr static const std::size_t length_bits = policy_type::length_bits;
73  constexpr static const std::size_t digest_bits = policy_type::digest_bits;
74  };
75 
76  // typedef sponge_construction<params_type, typename policy_type::iv_generator,
77  // poseidon_compressor<FieldType, Arity, strength>,
78  // // TODO: padding and finalizer
79  // detail::poseidon_padding<policy_type>,
80  // detail::poseidon_finalizer<policy_type>>
81  // type;
82  };
83 
84  template<typename StateAccumulator, std::size_t ValueBits>
86  struct params_type {
87  typedef typename policy_type::digest_endian digest_endian;
88 
89  constexpr static const std::size_t value_bits = ValueBits;
90  };
91 
93  };
94  };
95  } // namespace hashes
96  } // namespace crypto3
97 } // namespace nil
98 
99 #endif
This will do the usual Merkle-Damgård-style strengthening, padding with a 1 bit, then 0 bits as neede...
Definition: hash/include/nil/crypto3/hash/detail/block_stream_processor.hpp:55
detail::poseidon_functions< FieldType, Arity, PartRounds > policy_type
Definition: poseidon.hpp:23
constexpr static const std::size_t state_bits
Definition: poseidon.hpp:29
static void process_block(state_type &state, const block_type &block)
Definition: poseidon.hpp:37
constexpr static const std::size_t block_bits
Definition: poseidon.hpp:33
constexpr static const std::size_t block_words
Definition: poseidon.hpp:34
policy_type::word_type word_type
Definition: poseidon.hpp:27
policy_type::block_type block_type
Definition: poseidon.hpp:35
constexpr static const std::size_t word_bits
Definition: poseidon.hpp:26
policy_type::state_type state_type
Definition: poseidon.hpp:31
constexpr static const std::size_t state_words
Definition: poseidon.hpp:30
boost::mpl::apply< AccumulatorSet, tag::block< Mode > >::type::result_type block(const AccumulatorSet &acc)
Definition: accumulators/block.hpp:259
Definition: pair.hpp:31
Definition: poseidon_functions.hpp:23
policy_type::block_type block_type
Definition: poseidon_functions.hpp:38
static void permute(state_type &A)
Definition: poseidon_functions.hpp:60
constexpr static const std::size_t state_bits
Definition: poseidon_functions.hpp:32
constexpr static const std::size_t state_words
Definition: poseidon_functions.hpp:33
constexpr static const std::size_t block_words
Definition: poseidon_functions.hpp:37
constexpr static const std::size_t block_bits
Definition: poseidon_functions.hpp:36
policy_type::word_type word_type
Definition: poseidon_functions.hpp:45
constexpr static const std::size_t word_bits
Definition: poseidon_functions.hpp:44
policy_type::state_type state_type
Definition: poseidon_functions.hpp:34
Definition: poseidon_policy.hpp:65
policy_type::digest_endian digest_endian
Definition: poseidon.hpp:70
constexpr static const std::size_t digest_bits
Definition: poseidon.hpp:73
policy_type::digest_endian digest_endian
Definition: poseidon.hpp:87
constexpr static const std::size_t value_bits
Definition: poseidon.hpp:89
block_stream_processor< construction, StateAccumulator, params_type > type
Definition: poseidon.hpp:92
Definition: poseidon.hpp:53
policy_type::digest_type digest_type
Definition: poseidon.hpp:66
policy_type::block_type block_type
Definition: poseidon.hpp:63
detail::poseidon_policy< FieldType, Arity, PartRounds > policy_type
Definition: poseidon.hpp:55
constexpr static const std::size_t block_bits
Definition: poseidon.hpp:61
constexpr static const std::size_t digest_bits
Definition: poseidon.hpp:65
constexpr static const std::size_t word_bits
Definition: poseidon.hpp:58
constexpr static const std::size_t block_words
Definition: poseidon.hpp:62
policy_type::word_type word_type
Definition: poseidon.hpp:59