/
poseidon.hpp
102 lines (85 loc) · 4.04 KB
/
poseidon.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//---------------------------------------------------------------------------//
// Copyright (c) 2020 Ilias Khairullin <ilias@nil.foundation>
// Copyright (c) 2020 Mikhail Komarov <nemo@nil.foundation>
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//---------------------------------------------------------------------------//
#ifndef CRYPTO3_HASH_POSEIDON_HPP
#define CRYPTO3_HASH_POSEIDON_HPP
#ifdef __ZKLLVM__
#include <nil/crypto3/algebra/curves/pallas.hpp>
#else
#include <nil/crypto3/hash/accumulators/hash.hpp>
#include <nil/crypto3/hash/detail/poseidon/nil_poseidon_sponge.hpp>
#include <nil/crypto3/hash/detail/poseidon/poseidon_functions.hpp>
#include <nil/crypto3/hash/detail/poseidon/poseidon_permutation.hpp>
#include <nil/crypto3/hash/detail/sponge_construction.hpp>
#include <nil/crypto3/hash/detail/stream_processors/stream_processors_enum.hpp>
#endif
namespace nil {
namespace crypto3 {
namespace hashes {
#ifdef __ZKLLVM__
class poseidon {
public:
typedef typename algebra::curves::pallas::base_field_type::value_type block_type;
struct process{
block_type operator()(block_type first_input_block, block_type second_input_block){
return __builtin_assigner_poseidon_pallas_base({0, first_input_block, second_input_block})[2];
}
};
};
#else
template<typename PolicyType>
struct poseidon {
public:
typedef PolicyType policy_type;
typedef typename policy_type::word_type word_type;
constexpr static const std::size_t block_words = policy_type::block_words;
typedef typename policy_type::block_type block_type;
// This is required by 'is_hash' concept.
constexpr static const std::size_t digest_bits = 0;
using digest_type = typename policy_type::digest_type;
struct construction {
struct params_type {
// This is required by 'is_hash' concept.
};
using type = detail::nil_poseidon_sponge_construction<
policy_type
>;
};
constexpr static detail::stream_processor_type stream_processor = detail::stream_processor_type::Raw;
using accumulator_tag = accumulators::tag::algebraic_hash<poseidon<PolicyType>>;
};
template<typename PolicyType>
struct original_poseidon {
public:
typedef PolicyType policy_type;
typedef typename policy_type::word_type word_type;
constexpr static const std::size_t block_words = policy_type::block_words;
typedef typename policy_type::block_type block_type;
// This is required by 'is_hash' concept.
constexpr static const std::size_t digest_bits = 0;
using digest_type = typename policy_type::digest_type;
struct construction {
struct params_type {
// This is required by 'is_hash' concept.
};
using type = algebraic_sponge_construction<
policy_type,
typename policy_type::iv_generator,
detail::poseidon_functions<policy_type>,
detail::poseidon_functions<policy_type>,
detail::poseidon_functions<policy_type>
>;
};
constexpr static detail::stream_processor_type stream_processor = detail::stream_processor_type::Raw;
using accumulator_tag = accumulators::tag::algebraic_hash<original_poseidon<PolicyType>>;
};
#endif
} // namespace hashes
} // namespace crypto3
} // namespace nil
#endif