shacal2_policy.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2018-2020 Mikhail Komarov <nemo@nil.foundation>
3 //
4 // MIT License
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in all
14 // copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 // SOFTWARE.
23 //---------------------------------------------------------------------------//
24 
25 #ifndef CRYPTO3_BLOCK_DETAIL_SHACAL2_POLICY_HPP
26 #define CRYPTO3_BLOCK_DETAIL_SHACAL2_POLICY_HPP
27 
28 #include <array>
29 
31 
32 #include <boost/cstdint.hpp>
33 
34 namespace nil {
35  namespace crypto3 {
36  namespace block {
37  namespace detail {
38 
39  template<unsigned WordBits>
40  struct basic_shacal2_policy : public shacal2_functions<WordBits> {
41 
44 
45  constexpr static const std::size_t block_words = 8;
46  constexpr static const std::size_t block_bits = block_words * word_bits;
47  typedef std::array<word_type, block_words> block_type;
48 
49  constexpr static const std::size_t key_words = 16;
50  constexpr static const std::size_t key_bits = key_words * word_bits;
51  typedef std::array<word_type, key_words> key_type;
52  };
53 
54  template<std::size_t Version>
56 
57  template<>
58  struct shacal2_policy<256> : public basic_shacal2_policy<32> {
59 
60  constexpr static const std::size_t rounds = 64;
61  typedef std::array<word_type, rounds> key_schedule_type;
62  typedef std::array<word_type, rounds> constants_type;
63 
64  constexpr static constants_type const constants = {
65  0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
66  0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
67  0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
68  0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
69  0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
70  0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
71  0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
72  0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2};
73  };
74 
76 
77  template<>
78  struct shacal2_policy<512> : public basic_shacal2_policy<64> {
79 
80  constexpr static const std::size_t rounds = 80;
81  typedef std::array<word_type, rounds> key_schedule_type;
82  typedef std::array<word_type, rounds> constants_type;
83 
84  constexpr static const constants_type constants = {
85  UINT64_C(0x428a2f98d728ae22), UINT64_C(0x7137449123ef65cd), UINT64_C(0xb5c0fbcfec4d3b2f),
86  UINT64_C(0xe9b5dba58189dbbc), UINT64_C(0x3956c25bf348b538), UINT64_C(0x59f111f1b605d019),
87  UINT64_C(0x923f82a4af194f9b), UINT64_C(0xab1c5ed5da6d8118), UINT64_C(0xd807aa98a3030242),
88  UINT64_C(0x12835b0145706fbe), UINT64_C(0x243185be4ee4b28c), UINT64_C(0x550c7dc3d5ffb4e2),
89  UINT64_C(0x72be5d74f27b896f), UINT64_C(0x80deb1fe3b1696b1), UINT64_C(0x9bdc06a725c71235),
90  UINT64_C(0xc19bf174cf692694), UINT64_C(0xe49b69c19ef14ad2), UINT64_C(0xefbe4786384f25e3),
91  UINT64_C(0x0fc19dc68b8cd5b5), UINT64_C(0x240ca1cc77ac9c65), UINT64_C(0x2de92c6f592b0275),
92  UINT64_C(0x4a7484aa6ea6e483), UINT64_C(0x5cb0a9dcbd41fbd4), UINT64_C(0x76f988da831153b5),
93  UINT64_C(0x983e5152ee66dfab), UINT64_C(0xa831c66d2db43210), UINT64_C(0xb00327c898fb213f),
94  UINT64_C(0xbf597fc7beef0ee4), UINT64_C(0xc6e00bf33da88fc2), UINT64_C(0xd5a79147930aa725),
95  UINT64_C(0x06ca6351e003826f), UINT64_C(0x142929670a0e6e70), UINT64_C(0x27b70a8546d22ffc),
96  UINT64_C(0x2e1b21385c26c926), UINT64_C(0x4d2c6dfc5ac42aed), UINT64_C(0x53380d139d95b3df),
97  UINT64_C(0x650a73548baf63de), UINT64_C(0x766a0abb3c77b2a8), UINT64_C(0x81c2c92e47edaee6),
98  UINT64_C(0x92722c851482353b), UINT64_C(0xa2bfe8a14cf10364), UINT64_C(0xa81a664bbc423001),
99  UINT64_C(0xc24b8b70d0f89791), UINT64_C(0xc76c51a30654be30), UINT64_C(0xd192e819d6ef5218),
100  UINT64_C(0xd69906245565a910), UINT64_C(0xf40e35855771202a), UINT64_C(0x106aa07032bbd1b8),
101  UINT64_C(0x19a4c116b8d2d0c8), UINT64_C(0x1e376c085141ab53), UINT64_C(0x2748774cdf8eeb99),
102  UINT64_C(0x34b0bcb5e19b48a8), UINT64_C(0x391c0cb3c5c95a63), UINT64_C(0x4ed8aa4ae3418acb),
103  UINT64_C(0x5b9cca4f7763e373), UINT64_C(0x682e6ff3d6b2b8a3), UINT64_C(0x748f82ee5defb2fc),
104  UINT64_C(0x78a5636f43172f60), UINT64_C(0x84c87814a1f0ab72), UINT64_C(0x8cc702081a6439ec),
105  UINT64_C(0x90befffa23631e28), UINT64_C(0xa4506cebde82bde9), UINT64_C(0xbef9a3f7b2c67915),
106  UINT64_C(0xc67178f2e372532b), UINT64_C(0xca273eceea26619c), UINT64_C(0xd186b8c721c0c207),
107  UINT64_C(0xeada7dd6cde0eb1e), UINT64_C(0xf57d4f7fee6ed178), UINT64_C(0x06f067aa72176fba),
108  UINT64_C(0x0a637dc5a2c898a6), UINT64_C(0x113f9804bef90dae), UINT64_C(0x1b710b35131c471b),
109  UINT64_C(0x28db77f523047d84), UINT64_C(0x32caab7b40c72493), UINT64_C(0x3c9ebe0a15c9bebc),
110  UINT64_C(0x431d67c49c100d4c), UINT64_C(0x4cc5d4becb3e42b6), UINT64_C(0x597f299cfc657e2a),
111  UINT64_C(0x5fcb6fab3ad6faec), UINT64_C(0x6c44198c4a475817)};
112  };
113 
115  } // namespace detail
116  } // namespace block
117  } // namespace crypto3
118 } // namespace nil
119 
120 #endif // CRYPTO3_BLOCK_CIPHERS_DETAIL_SHACAL2_POLICY_HPP
boost::mpl::apply< AccumulatorSet, tag::block< Mode > >::type::result_type block(const AccumulatorSet &acc)
Definition: accumulators/block.hpp:259
Definition: pair.hpp:31
Definition: shacal2_policy.hpp:40
std::array< word_type, key_words > key_type
Definition: shacal2_policy.hpp:51
std::array< word_type, block_words > block_type
Definition: shacal2_policy.hpp:47
constexpr static const std::size_t block_bits
Definition: shacal2_policy.hpp:46
shacal2_functions< WordBits >::word_type word_type
Definition: shacal2_policy.hpp:43
constexpr static const std::size_t key_bits
Definition: shacal2_policy.hpp:50
constexpr static const std::size_t block_words
Definition: shacal2_policy.hpp:45
constexpr static const std::size_t key_words
Definition: shacal2_policy.hpp:49
Definition: shacal_functions.hpp:79
std::array< word_type, rounds > constants_type
Definition: shacal2_policy.hpp:62
std::array< word_type, rounds > key_schedule_type
Definition: shacal2_policy.hpp:61
constexpr static constants_type const constants
Definition: shacal2_policy.hpp:64
constexpr static const constants_type constants
Definition: shacal2_policy.hpp:84
std::array< word_type, rounds > constants_type
Definition: shacal2_policy.hpp:82
std::array< word_type, rounds > key_schedule_type
Definition: shacal2_policy.hpp:81
Definition: shacal2_policy.hpp:55