/src/Botan-3.4.0/build/include/internal/botan/internal/sha1.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * SHA-1 |
3 | | * (C) 1999-2007,2016 Jack Lloyd |
4 | | * |
5 | | * Botan is released under the Simplified BSD License (see license.txt) |
6 | | */ |
7 | | |
8 | | #ifndef BOTAN_SHA1_H_ |
9 | | #define BOTAN_SHA1_H_ |
10 | | |
11 | | #include <botan/internal/mdx_hash.h> |
12 | | |
13 | | namespace Botan { |
14 | | |
15 | | /** |
16 | | * NIST's SHA-1 |
17 | | */ |
18 | | class SHA_1 final : public HashFunction { |
19 | | public: |
20 | | using digest_type = secure_vector<uint32_t>; |
21 | | |
22 | | static constexpr MD_Endian byte_endianness = MD_Endian::Big; |
23 | | static constexpr MD_Endian bit_endianness = MD_Endian::Big; |
24 | | static constexpr size_t block_bytes = 64; |
25 | | static constexpr size_t output_bytes = 20; |
26 | | static constexpr size_t ctr_bytes = 8; |
27 | | |
28 | | static void compress_n(digest_type& digest, std::span<const uint8_t> input, size_t blocks); |
29 | | static void init(digest_type& digest); |
30 | | |
31 | | public: |
32 | 10.1k | std::string name() const override { return "SHA-1"; } |
33 | | |
34 | 11.9k | size_t output_length() const override { return 20; } |
35 | | |
36 | 0 | size_t hash_block_size() const override { return block_bytes; } |
37 | | |
38 | | std::unique_ptr<HashFunction> new_object() const override; |
39 | | |
40 | | std::unique_ptr<HashFunction> copy_state() const override; |
41 | | |
42 | | std::string provider() const override; |
43 | | |
44 | 0 | void clear() override { m_md.clear(); } |
45 | | |
46 | | #if defined(BOTAN_HAS_SHA1_ARMV8) |
47 | | static void sha1_armv8_compress_n(digest_type& digest, std::span<const uint8_t> blocks, size_t block_count); |
48 | | #endif |
49 | | |
50 | | #if defined(BOTAN_HAS_SHA1_SSE2) |
51 | | static void sse2_compress_n(digest_type& digest, std::span<const uint8_t> blocks, size_t block_count); |
52 | | #endif |
53 | | |
54 | | #if defined(BOTAN_HAS_SHA1_X86_SHA_NI) |
55 | | // Using x86 SHA instructions in Intel Goldmont and Cannonlake |
56 | | static void sha1_compress_x86(digest_type& digest, std::span<const uint8_t> blocks, size_t block_count); |
57 | | #endif |
58 | | |
59 | | private: |
60 | | void add_data(std::span<const uint8_t> input) override; |
61 | | |
62 | | void final_result(std::span<uint8_t> output) override; |
63 | | |
64 | | private: |
65 | | MerkleDamgard_Hash<SHA_1> m_md; |
66 | | }; |
67 | | |
68 | | } // namespace Botan |
69 | | |
70 | | #endif |