sha1_policy.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2018-2019 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 2020 Nikita Kaskov <nbering@nil.foundation>
4 //
5 // MIT License
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
8 // of this software and associated documentation files (the "Software"), to deal
9 // in the Software without restriction, including without limitation the rights
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 // copies of the Software, and to permit persons to whom the Software is
12 // furnished to do so, subject to the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be included in all
15 // copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 // SOFTWARE.
24 //---------------------------------------------------------------------------//
25 
26 #ifndef CRYPTO3_HASH_DETAIL_SHA1_POLICY_HPP
27 #define CRYPTO3_HASH_DETAIL_SHA1_POLICY_HPP
28 
30 
31 #include <nil/crypto3/detail/static_digest.hpp>
32 
33 namespace nil {
34  namespace crypto3 {
35  namespace hashes {
36  namespace detail {
37  struct sha1_policy {
39 
40  constexpr static const std::size_t word_bits = block_cipher_type::word_bits;
42 
43  constexpr static const std::size_t state_bits = block_cipher_type::block_bits;
44  constexpr static const std::size_t state_words = block_cipher_type::block_words;
46 
47  constexpr static const std::size_t block_bits = block_cipher_type::key_bits;
48  constexpr static const std::size_t block_words = block_cipher_type::key_words;
50 
51  constexpr static const std::size_t length_bits = word_bits * 2;
52 
54 
55  constexpr static const std::size_t digest_bits = 160;
56  constexpr static const std::uint8_t ieee1363_hash_id = 0x33;
57 
59  typedef std::array<std::uint8_t, 15> pkcs_id_type;
60 
61  constexpr static const pkcs_id_type pkcs_id = {0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x0E,
62  0x03, 0x02, 0x1A, 0x05, 0x00, 0x04, 0x14};
63 
64  struct iv_generator {
65  state_type const &operator()() const {
66  // First 4 words are the same as MD4
67  static state_type const H0 = {{0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0}};
68  return H0;
69  }
70  };
71  };
72 
73  } // namespace detail
74  } // namespace hashes
75  } // namespace crypto3
76 } // namespace nil
77 
78 #endif // CRYPTO3_HASH_DETAIL_SHA1_POLICY_HPP
constexpr static const std::size_t word_bits
Definition: basic_shacal.hpp:64
policy_type::block_type block_type
Definition: basic_shacal.hpp:73
constexpr static const std::size_t key_bits
Definition: basic_shacal.hpp:67
constexpr static const std::size_t block_words
Definition: basic_shacal.hpp:72
policy_type::word_type word_type
Definition: basic_shacal.hpp:65
constexpr static const std::size_t key_words
Definition: basic_shacal.hpp:68
constexpr static const std::size_t block_bits
Definition: basic_shacal.hpp:71
policy_type::key_type key_type
Definition: basic_shacal.hpp:69
Shacal1. Merkle-Damgård construction foundation for SHA1 hashes.
Definition: shacal1.hpp:48
Definition: block/include/nil/crypto3/detail/static_digest.hpp:72
Definition: pair.hpp:31
state_type const & operator()() const
Definition: sha1_policy.hpp:65
Definition: sha1_policy.hpp:37
constexpr static const std::size_t state_words
Definition: sha1_policy.hpp:44
constexpr static const pkcs_id_type pkcs_id
Definition: sha1_policy.hpp:61
block_cipher_type::key_type block_type
Definition: sha1_policy.hpp:49
block_cipher_type::block_type state_type
Definition: sha1_policy.hpp:45
constexpr static const std::size_t digest_bits
Definition: sha1_policy.hpp:55
constexpr static const std::size_t block_bits
Definition: sha1_policy.hpp:47
static_digest< digest_bits > digest_type
Definition: sha1_policy.hpp:58
block::shacal1 block_cipher_type
Definition: sha1_policy.hpp:38
std::array< std::uint8_t, 15 > pkcs_id_type
Definition: sha1_policy.hpp:59
constexpr static const std::uint8_t ieee1363_hash_id
Definition: sha1_policy.hpp:56
stream_endian::big_octet_big_bit digest_endian
Definition: sha1_policy.hpp:53
constexpr static const std::size_t length_bits
Definition: sha1_policy.hpp:51
constexpr static const std::size_t state_bits
Definition: sha1_policy.hpp:43
constexpr static const std::size_t word_bits
Definition: sha1_policy.hpp:40
block_cipher_type::word_type word_type
Definition: sha1_policy.hpp:41
constexpr static const std::size_t block_words
Definition: sha1_policy.hpp:48
Definition: algebra/include/nil/crypto3/detail/stream_endian.hpp:39