| 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 |
std::string name() const override { return "SHA-1"; } |
| 33 |
|
| 34 |
size_t output_length() const override { return 20; } |
| 35 |
|
| 36 |
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 |
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_SIMD_4X32) |
| 51 |
static void simd_compress_n(digest_type& digest, std::span<const uint8_t> blocks, size_t block_count); |
| 52 |
#endif |
| 53 |
|
| 54 |
#if defined(BOTAN_HAS_SHA1_AVX2) |
| 55 |
static void avx2_compress_n(digest_type& digest, std::span<const uint8_t> blocks, size_t block_count); |
| 56 |
#endif |
| 57 |
|
| 58 |
#if defined(BOTAN_HAS_SHA1_X86_SHA_NI) |
| 59 |
// Using x86 SHA instructions in Intel Goldmont and Cannonlake |
| 60 |
static void sha1_compress_x86(digest_type& digest, std::span<const uint8_t> blocks, size_t block_count); |
| 61 |
#endif |
| 62 |
|
| 63 |
private: |
| 64 |
void add_data(std::span<const uint8_t> input) override; |
| 65 |
|
| 66 |
void final_result(std::span<uint8_t> output) override; |
| 67 |
|
| 68 |
private: |
| 69 |
MerkleDamgard_Hash<SHA_1> m_md; |
| 70 |
}; |
| 71 |
|
| 72 |
} // namespace Botan |
| 73 |
|
| 74 |
#endif |