Botan 3.6.1
Crypto and TLS for C&
sha1.h
Go to the documentation of this file.
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
13namespace Botan {
14
15/**
16* NIST's SHA-1
17*/
18class SHA_1 final : public HashFunction {
19 public:
21
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_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:
66};
67
68} // namespace Botan
69
70#endif
std::unique_ptr< HashFunction > new_object() const override
Definition sha1.cpp:230
std::unique_ptr< HashFunction > copy_state() const override
Definition sha1.cpp:234
std::string provider() const override
Definition sha1.cpp:208
size_t hash_block_size() const override
Definition sha1.h:36
static constexpr MD_Endian bit_endianness
Definition sha1.h:23
void clear() override
Definition sha1.h:44
static void sha1_compress_x86(digest_type &digest, std::span< const uint8_t > blocks, size_t block_count)
Definition sha1_x86.cpp:21
static constexpr MD_Endian byte_endianness
Definition sha1.h:22
static constexpr size_t ctr_bytes
Definition sha1.h:26
static constexpr size_t output_bytes
Definition sha1.h:25
std::string name() const override
Definition sha1.h:32
static constexpr size_t block_bytes
Definition sha1.h:24
static void compress_n(digest_type &digest, std::span< const uint8_t > input, size_t blocks)
Definition sha1.cpp:63
secure_vector< uint32_t > digest_type
Definition sha1.h:20
static void sse2_compress_n(digest_type &digest, std::span< const uint8_t > blocks, size_t block_count)
size_t output_length() const override
Definition sha1.h:34
static void sha1_armv8_compress_n(digest_type &digest, std::span< const uint8_t > blocks, size_t block_count)
int(* init)(CTX *)
int(* final)(unsigned char *, CTX *)
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61
MD_Endian
Definition mdx_hash.h:20