Botan 3.13.0
Crypto and TLS for C&
sha3.h
Go to the documentation of this file.
1/*
2* SHA-3
3* (C) 2010,2016 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_SHA3_H_
9#define BOTAN_SHA3_H_
10
11#include <botan/hash.h>
12#include <botan/secmem.h>
13#include <botan/internal/keccak_perm.h>
14#include <string>
15
16namespace Botan {
17
18/**
19* SHA-3
20*/
21class SHA_3 : public HashFunction {
22 public:
23 /**
24 * @param output_bits the size of the hash output; must be one of
25 * 224, 256, 384, or 512
26 */
27 explicit SHA_3(size_t output_bits);
28
29 size_t hash_block_size() const override { return m_keccak.byte_rate(); }
30
31 size_t output_length() const override { return m_output_length; }
32
33 std::unique_ptr<HashFunction> new_object() const override;
34 std::unique_ptr<HashFunction> copy_state() const override;
35 std::string name() const override;
36 void clear() override;
37 std::string provider() const override;
38
39 private:
40 void add_data(std::span<const uint8_t> input) override;
41 void final_result(std::span<uint8_t> out) override;
42
43 private:
44 Keccak_Permutation m_keccak;
45 size_t m_output_length;
46};
47
48/**
49* SHA-3-224
50*/
51class SHA_3_224 final : public SHA_3 {
52 public:
53 SHA_3_224() : SHA_3(224) {}
54
55 std::unique_ptr<HashFunction> new_object() const override { return std::make_unique<SHA_3_224>(); }
56
57 std::unique_ptr<HashFunction> copy_state() const override { return std::make_unique<SHA_3_224>(*this); }
58};
59
60/**
61* SHA-3-256
62*/
63class SHA_3_256 final : public SHA_3 {
64 public:
65 SHA_3_256() : SHA_3(256) {}
66
67 std::unique_ptr<HashFunction> new_object() const override { return std::make_unique<SHA_3_256>(); }
68
69 std::unique_ptr<HashFunction> copy_state() const override { return std::make_unique<SHA_3_256>(*this); }
70};
71
72/**
73* SHA-3-384
74*/
75class SHA_3_384 final : public SHA_3 {
76 public:
77 SHA_3_384() : SHA_3(384) {}
78
79 std::unique_ptr<HashFunction> new_object() const override { return std::make_unique<SHA_3_384>(); }
80
81 std::unique_ptr<HashFunction> copy_state() const override { return std::make_unique<SHA_3_384>(*this); }
82};
83
84/**
85* SHA-3-512
86*/
87class SHA_3_512 final : public SHA_3 {
88 public:
89 SHA_3_512() : SHA_3(512) {}
90
91 std::unique_ptr<HashFunction> new_object() const override { return std::make_unique<SHA_3_512>(); }
92
93 std::unique_ptr<HashFunction> copy_state() const override { return std::make_unique<SHA_3_512>(*this); }
94};
95
96} // namespace Botan
97
98#endif
void final(uint8_t out[])
Definition buf_comp.h:97
std::unique_ptr< HashFunction > copy_state() const override
Definition sha3.h:57
std::unique_ptr< HashFunction > new_object() const override
Definition sha3.h:55
std::unique_ptr< HashFunction > new_object() const override
Definition sha3.h:67
std::unique_ptr< HashFunction > copy_state() const override
Definition sha3.h:69
std::unique_ptr< HashFunction > new_object() const override
Definition sha3.h:79
std::unique_ptr< HashFunction > copy_state() const override
Definition sha3.h:81
std::unique_ptr< HashFunction > new_object() const override
Definition sha3.h:91
std::unique_ptr< HashFunction > copy_state() const override
Definition sha3.h:93
void clear() override
Definition sha3.cpp:41
SHA_3(size_t output_bits)
Definition sha3.cpp:16
size_t hash_block_size() const override
Definition sha3.h:29
std::unique_ptr< HashFunction > new_object() const override
Definition sha3.cpp:37
std::string provider() const override
Definition sha3.cpp:29
std::string name() const override
Definition sha3.cpp:25
size_t output_length() const override
Definition sha3.h:31
std::unique_ptr< HashFunction > copy_state() const override
Definition sha3.cpp:33