shacal.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_SHACAL_HPP
26 #define CRYPTO3_BLOCK_SHACAL_HPP
27 
29 
30 namespace nil {
31  namespace crypto3 {
32  namespace block {
52  class shacal : public basic_shacal {
53  public:
54  shacal(const key_type &k) : basic_shacal(build_schedule(k)) {
55  }
56 
57  shacal(schedule_type s) : basic_shacal((prepare_schedule(s), s)) {
58  }
59 
60  private:
61  static schedule_type build_schedule(const key_type &key) {
62  // Copy key into beginning of round_constants_words
63  schedule_type schedule;
64  for (unsigned t = 0; t < key_words; ++t) {
65  schedule[t] = key[t];
66  }
67  prepare_schedule(schedule);
68  return schedule;
69  }
70 
71  static void prepare_schedule(schedule_type &schedule) {
72  for (unsigned t = key_words; t < rounds; ++t) {
73  schedule[t] = schedule[t - 3] ^ schedule[t - 8] ^ schedule[t - 14] ^ schedule[t - 16];
74  }
75  }
76  };
77 
78  typedef shacal shacal0;
79 
80  } // namespace block
81  } // namespace crypto3
82 } // namespace nil
83 
84 #endif // CRYPTO3_BLOCK_CIPHERS_SHACAL_HPP
Definition: basic_shacal.hpp:59
constexpr static const std::size_t key_words
Definition: basic_shacal.hpp:68
policy_type::schedule_type schedule_type
Definition: basic_shacal.hpp:76
policy_type::key_type key_type
Definition: basic_shacal.hpp:69
constexpr static const std::size_t rounds
Definition: basic_shacal.hpp:75
Shacal. Merkle-Damgård construction foundation for SHA hashes.
Definition: shacal.hpp:52
shacal(const key_type &k)
Definition: shacal.hpp:54
shacal(schedule_type s)
Definition: shacal.hpp:57
boost::mpl::apply< AccumulatorSet, tag::block< Mode > >::type::result_type block(const AccumulatorSet &acc)
Definition: accumulators/block.hpp:259
shacal shacal0
Definition: shacal.hpp:78
Definition: pair.hpp:31