sha2.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2018-2020 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 2020 Nikita Kaskov <nbering@nil.foundation>
4 // Copyright (c) 2020 Alexander Sokolov <asokolov@nil.foundation>
5 //
6 // MIT License
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 //---------------------------------------------------------------------------//
26 
27 #ifndef CRYPTO3_HASH_SHA2_HPP
28 #define CRYPTO3_HASH_SHA2_HPP
29 
36 
37 namespace nil {
38  namespace crypto3 {
39  namespace hashes {
45  template<std::size_t Version>
46  class sha2 {
48  typedef typename policy_type::block_cipher_type block_cipher_type;
49 
50  public:
51  constexpr static const std::size_t version = Version;
52 
53  constexpr static const std::size_t word_bits = policy_type::word_bits;
54  typedef typename policy_type::word_type word_type;
55 
56  constexpr static const std::size_t block_bits = policy_type::block_bits;
57  constexpr static const std::size_t block_words = policy_type::block_words;
58  typedef typename policy_type::block_type block_type;
59 
60  constexpr static const std::size_t digest_bits = policy_type::digest_bits;
61  typedef typename policy_type::digest_type digest_type;
62 
63  constexpr static const std::size_t pkcs_id_size = policy_type::pkcs_id_size;
64  constexpr static const std::size_t pkcs_id_bits = policy_type::pkcs_id_bits;
65  typedef typename policy_type::pkcs_id_type pkcs_id_type;
66 
67  constexpr static const pkcs_id_type pkcs_id = policy_type::pkcs_id;
68 
69  struct construction {
70  struct params_type {
71  typedef typename policy_type::digest_endian digest_endian;
72 
73  constexpr static const std::size_t length_bits = policy_type::length_bits;
74  constexpr static const std::size_t digest_bits = policy_type::digest_bits;
75  };
76 
77  typedef merkle_damgard_construction<params_type, typename policy_type::iv_generator,
81  };
82 
83  template<typename StateAccumulator, std::size_t ValueBits>
85  struct params_type {
86  typedef typename policy_type::digest_endian digest_endian;
87 
88  constexpr static const std::size_t value_bits = ValueBits;
89  };
90 
92  };
93  };
94  } // namespace hashes
95  } // namespace crypto3
96 } // namespace nil
97 
98 #endif // CRYPTO3_HASH_SHA2_HPP
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
Definition: merkle_damgard_padding.hpp:39
Definition: merkle_damgard_construction.hpp:55
SHA2.
Definition: sha2.hpp:46
policy_type::block_type block_type
Definition: sha2.hpp:58
policy_type::pkcs_id_type pkcs_id_type
Definition: sha2.hpp:65
constexpr static const std::size_t block_words
Definition: sha2.hpp:57
constexpr static const std::size_t word_bits
Definition: sha2.hpp:53
policy_type::word_type word_type
Definition: sha2.hpp:54
constexpr static const std::size_t pkcs_id_bits
Definition: sha2.hpp:64
constexpr static const std::size_t digest_bits
Definition: sha2.hpp:60
constexpr static const std::size_t version
Definition: sha2.hpp:51
constexpr static const pkcs_id_type pkcs_id
Definition: sha2.hpp:67
constexpr static const std::size_t block_bits
Definition: sha2.hpp:56
policy_type::digest_type digest_type
Definition: sha2.hpp:61
constexpr static const std::size_t pkcs_id_size
Definition: sha2.hpp:63
Definition: pair.hpp:31
Definition: davies_meyer_compressor.hpp:44
Definition: sha2_policy.hpp:63
constexpr static const std::size_t digest_bits
Definition: sha2.hpp:74
constexpr static const std::size_t length_bits
Definition: sha2.hpp:73
policy_type::digest_endian digest_endian
Definition: sha2.hpp:71
merkle_damgard_construction< params_type, typename policy_type::iv_generator, davies_meyer_compressor< block_cipher_type, detail::state_adder >, detail::merkle_damgard_padding< policy_type > > type
Definition: sha2.hpp:80
policy_type::digest_endian digest_endian
Definition: sha2.hpp:86
constexpr static const std::size_t value_bits
Definition: sha2.hpp:88
block_stream_processor< construction, StateAccumulator, params_type > type
Definition: sha2.hpp:91