Botan 3.6.1
Crypto and TLS for C&
sha2_64.h
Go to the documentation of this file.
1/*
2* SHA-{384,512}
3* (C) 1999-2010,2015 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_SHA_64BIT_H_
9#define BOTAN_SHA_64BIT_H_
10
11#include <botan/internal/mdx_hash.h>
12
13namespace Botan {
14
15/**
16* SHA-384
17*/
18class SHA_384 final : public HashFunction {
19 public:
21
24 static constexpr size_t block_bytes = 128;
25 static constexpr size_t output_bytes = 48;
26 static constexpr size_t ctr_bytes = 16;
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-384"; }
33
34 size_t output_length() const override { return output_bytes; }
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 private:
47 void add_data(std::span<const uint8_t> input) override;
48
49 void final_result(std::span<uint8_t> output) override;
50
51 private:
53};
54
55/**
56* SHA-512
57*/
58class SHA_512 final : public HashFunction {
59 public:
61
64 static constexpr size_t block_bytes = 128;
65 static constexpr size_t output_bytes = 64;
66 static constexpr size_t ctr_bytes = 16;
67
68 static void compress_n(digest_type& digest, std::span<const uint8_t> input, size_t blocks);
69 static void init(digest_type& digest);
70
71 public:
72 std::string name() const override { return "SHA-512"; }
73
74 size_t output_length() const override { return output_bytes; }
75
76 size_t hash_block_size() const override { return block_bytes; }
77
78 std::unique_ptr<HashFunction> new_object() const override;
79
80 std::unique_ptr<HashFunction> copy_state() const override;
81
82 std::string provider() const override;
83
84 void clear() override { m_md.clear(); }
85
86 public:
87 static void compress_digest(digest_type& digest, std::span<const uint8_t> input, size_t blocks);
88
89#if defined(BOTAN_HAS_SHA2_64_BMI2)
90 static void compress_digest_bmi2(digest_type& digest, std::span<const uint8_t> input, size_t blocks);
91#endif
92
93#if defined(BOTAN_HAS_SHA2_64_ARMV8)
94 static void compress_digest_armv8(digest_type& digest, std::span<const uint8_t> input, size_t blocks);
95#endif
96
97 private:
98 void add_data(std::span<const uint8_t> input) override;
99
100 void final_result(std::span<uint8_t> output) override;
101
102 private:
104};
105
106/**
107* SHA-512/256
108*/
110 public:
112
115 static constexpr size_t block_bytes = 128;
116 static constexpr size_t output_bytes = 32;
117 static constexpr size_t ctr_bytes = 16;
118
119 static void compress_n(digest_type& digest, std::span<const uint8_t> input, size_t blocks);
120 static void init(digest_type& digest);
121
122 public:
123 std::string name() const override { return "SHA-512-256"; }
124
125 size_t output_length() const override { return output_bytes; }
126
127 size_t hash_block_size() const override { return block_bytes; }
128
129 std::unique_ptr<HashFunction> new_object() const override;
130
131 std::unique_ptr<HashFunction> copy_state() const override;
132
133 std::string provider() const override;
134
135 void clear() override { m_md.clear(); }
136
137 private:
138 void add_data(std::span<const uint8_t> input) override;
139
140 void final_result(std::span<uint8_t> output) override;
141
142 private:
144};
145
146} // namespace Botan
147
148#endif
std::string name() const override
Definition sha2_64.h:32
size_t hash_block_size() const override
Definition sha2_64.h:36
static constexpr size_t ctr_bytes
Definition sha2_64.h:26
std::unique_ptr< HashFunction > new_object() const override
Definition sha2_64.cpp:219
std::unique_ptr< HashFunction > copy_state() const override
Definition sha2_64.cpp:231
secure_vector< uint64_t > digest_type
Definition sha2_64.h:20
static constexpr size_t output_bytes
Definition sha2_64.h:25
std::string provider() const override
Definition sha2_64.cpp:166
static constexpr MD_Endian bit_endianness
Definition sha2_64.h:23
static constexpr size_t block_bytes
Definition sha2_64.h:24
void clear() override
Definition sha2_64.h:44
static constexpr MD_Endian byte_endianness
Definition sha2_64.h:22
size_t output_length() const override
Definition sha2_64.h:34
static void compress_n(digest_type &digest, std::span< const uint8_t > input, size_t blocks)
Definition sha2_64.cpp:178
size_t hash_block_size() const override
Definition sha2_64.h:127
secure_vector< uint64_t > digest_type
Definition sha2_64.h:111
size_t output_length() const override
Definition sha2_64.h:125
std::string provider() const override
Definition sha2_64.cpp:162
static constexpr MD_Endian bit_endianness
Definition sha2_64.h:114
static constexpr size_t output_bytes
Definition sha2_64.h:116
std::unique_ptr< HashFunction > copy_state() const override
Definition sha2_64.cpp:239
std::unique_ptr< HashFunction > new_object() const override
Definition sha2_64.cpp:227
static constexpr MD_Endian byte_endianness
Definition sha2_64.h:113
static constexpr size_t ctr_bytes
Definition sha2_64.h:117
std::string name() const override
Definition sha2_64.h:123
static void compress_n(digest_type &digest, std::span< const uint8_t > input, size_t blocks)
Definition sha2_64.cpp:174
void clear() override
Definition sha2_64.h:135
static constexpr size_t block_bytes
Definition sha2_64.h:115
static void compress_n(digest_type &digest, std::span< const uint8_t > input, size_t blocks)
Definition sha2_64.cpp:182
void clear() override
Definition sha2_64.h:84
std::unique_ptr< HashFunction > new_object() const override
Definition sha2_64.cpp:223
size_t output_length() const override
Definition sha2_64.h:74
size_t hash_block_size() const override
Definition sha2_64.h:76
static constexpr size_t block_bytes
Definition sha2_64.h:64
static constexpr size_t output_bytes
Definition sha2_64.h:65
static constexpr MD_Endian byte_endianness
Definition sha2_64.h:62
std::string provider() const override
Definition sha2_64.cpp:170
static void compress_digest_bmi2(digest_type &digest, std::span< const uint8_t > input, size_t blocks)
static constexpr size_t ctr_bytes
Definition sha2_64.h:66
secure_vector< uint64_t > digest_type
Definition sha2_64.h:60
std::string name() const override
Definition sha2_64.h:72
std::unique_ptr< HashFunction > copy_state() const override
Definition sha2_64.cpp:235
static void compress_digest(digest_type &digest, std::span< const uint8_t > input, size_t blocks)
Definition sha2_64.cpp:43
static constexpr MD_Endian bit_endianness
Definition sha2_64.h:63
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