Botan 3.6.1
Crypto and TLS for C&
sha2_32.h
Go to the documentation of this file.
1/*
2* SHA-{224,256}
3* (C) 1999-2011 Jack Lloyd
4* 2007 FlexSecure GmbH
5*
6* Botan is released under the Simplified BSD License (see license.txt)
7*/
8
9#ifndef BOTAN_SHA_224_256_H_
10#define BOTAN_SHA_224_256_H_
11
12#include <botan/internal/mdx_hash.h>
13
14namespace Botan {
15
16/**
17* SHA-224
18*/
19class SHA_224 final : public HashFunction {
20 public:
22
25 static constexpr size_t block_bytes = 64;
26 static constexpr size_t output_bytes = 28;
27 static constexpr size_t ctr_bytes = 8;
28
29 static void compress_n(digest_type& digest, std::span<const uint8_t> input, size_t blocks);
30 static void init(digest_type& digest);
31
32 public:
33 std::string name() const override { return "SHA-224"; }
34
35 size_t output_length() const override { return output_bytes; }
36
37 size_t hash_block_size() const override { return block_bytes; }
38
39 std::unique_ptr<HashFunction> new_object() const override;
40
41 std::unique_ptr<HashFunction> copy_state() const override;
42
43 void clear() override { m_md.clear(); }
44
45 std::string provider() const override;
46
47 private:
48 void add_data(std::span<const uint8_t> input) override;
49
50 void final_result(std::span<uint8_t> output) override;
51
52 private:
54};
55
56/**
57* SHA-256
58*/
59class SHA_256 final : public HashFunction {
60 public:
62
65 static constexpr size_t block_bytes = 64;
66 static constexpr size_t output_bytes = 32;
67 static constexpr size_t ctr_bytes = 8;
68
69 static void compress_n(digest_type& digest, std::span<const uint8_t> input, size_t blocks);
70 static void init(digest_type& digest);
71
72 public:
73 std::string name() const override { return "SHA-256"; }
74
75 size_t output_length() const override { return output_bytes; }
76
77 size_t hash_block_size() const override { return block_bytes; }
78
79 std::unique_ptr<HashFunction> new_object() const override;
80
81 std::unique_ptr<HashFunction> copy_state() const override;
82
83 void clear() override { m_md.clear(); }
84
85 std::string provider() const override;
86
87 public:
88 static void compress_digest(digest_type& digest, std::span<const uint8_t> input, size_t blocks);
89
90#if defined(BOTAN_HAS_SHA2_32_ARMV8)
91 static void compress_digest_armv8(digest_type& digest, std::span<const uint8_t> input, size_t blocks);
92#endif
93
94#if defined(BOTAN_HAS_SHA2_32_X86_BMI2)
95 static void compress_digest_x86_bmi2(digest_type& digest, std::span<const uint8_t> input, size_t blocks);
96#endif
97
98#if defined(BOTAN_HAS_SHA2_32_X86)
99 static void compress_digest_x86(digest_type& digest, std::span<const uint8_t> input, size_t blocks);
100#endif
101
102 private:
103 void add_data(std::span<const uint8_t> input) override;
104
105 void final_result(std::span<uint8_t> output) override;
106
107 private:
109};
110
111} // namespace Botan
112
113#endif
static constexpr size_t ctr_bytes
Definition sha2_32.h:27
size_t output_length() const override
Definition sha2_32.h:35
static void compress_n(digest_type &digest, std::span< const uint8_t > input, size_t blocks)
Definition sha2_32.cpp:165
size_t hash_block_size() const override
Definition sha2_32.h:37
static constexpr size_t block_bytes
Definition sha2_32.h:25
std::string name() const override
Definition sha2_32.h:33
static constexpr MD_Endian bit_endianness
Definition sha2_32.h:24
std::string provider() const override
Definition sha2_32.cpp:161
secure_vector< uint32_t > digest_type
Definition sha2_32.h:21
static constexpr MD_Endian byte_endianness
Definition sha2_32.h:23
void clear() override
Definition sha2_32.h:43
static constexpr size_t output_bytes
Definition sha2_32.h:26
std::unique_ptr< HashFunction > new_object() const override
Definition sha2_32.cpp:173
std::unique_ptr< HashFunction > copy_state() const override
Definition sha2_32.cpp:177
size_t output_length() const override
Definition sha2_32.h:75
static void compress_digest_x86(digest_type &digest, std::span< const uint8_t > input, size_t blocks)
secure_vector< uint32_t > digest_type
Definition sha2_32.h:61
static void compress_digest_armv8(digest_type &digest, std::span< const uint8_t > input, size_t blocks)
size_t hash_block_size() const override
Definition sha2_32.h:77
static constexpr size_t ctr_bytes
Definition sha2_32.h:67
std::string name() const override
Definition sha2_32.h:73
static void compress_n(digest_type &digest, std::span< const uint8_t > input, size_t blocks)
Definition sha2_32.cpp:193
static constexpr size_t output_bytes
Definition sha2_32.h:66
void clear() override
Definition sha2_32.h:83
static constexpr MD_Endian byte_endianness
Definition sha2_32.h:63
std::unique_ptr< HashFunction > new_object() const override
Definition sha2_32.cpp:201
std::unique_ptr< HashFunction > copy_state() const override
Definition sha2_32.cpp:205
static constexpr MD_Endian bit_endianness
Definition sha2_32.h:64
std::string provider() const override
Definition sha2_32.cpp:189
static void compress_digest_x86_bmi2(digest_type &digest, std::span< const uint8_t > input, size_t blocks)
static constexpr size_t block_bytes
Definition sha2_32.h:65
static void compress_digest(digest_type &digest, std::span< const uint8_t > input, size_t blocks)
Definition sha2_32.cpp:49
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