Botan  2.4.0
Crypto and TLS for C++11
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/mdx_hash.h>
13 
14 namespace Botan {
15 
16 /**
17 * SHA-224
18 */
19 class BOTAN_PUBLIC_API(2,0) SHA_224 final : public MDx_HashFunction
20  {
21  public:
22  std::string name() const override { return "SHA-224"; }
23  size_t output_length() const override { return 28; }
24  HashFunction* clone() const override { return new SHA_224; }
25  std::unique_ptr<HashFunction> copy_state() const override;
26 
27  void clear() override;
28 
29  SHA_224() : MDx_HashFunction(64, true, true), m_digest(8)
30  { clear(); }
31  private:
32  void compress_n(const uint8_t[], size_t blocks) override;
33  void copy_out(uint8_t[]) override;
34 
35  secure_vector<uint32_t> m_digest;
36  };
37 
38 /**
39 * SHA-256
40 */
41 class BOTAN_PUBLIC_API(2,0) SHA_256 final : public MDx_HashFunction
42  {
43  public:
44  std::string name() const override { return "SHA-256"; }
45  size_t output_length() const override { return 32; }
46  HashFunction* clone() const override { return new SHA_256; }
47  std::unique_ptr<HashFunction> copy_state() const override;
48 
49  void clear() override;
50 
51  SHA_256() : MDx_HashFunction(64, true, true), m_digest(8)
52  { clear(); }
53 
54  /*
55  * Perform a SHA-256 compression. For internal use
56  */
57  static void compress_digest(secure_vector<uint32_t>& digest,
58  const uint8_t input[],
59  size_t blocks);
60 
61  private:
62 
63 #if defined(BOTAN_HAS_SHA2_32_ARMV8)
64  static void compress_digest_armv8(secure_vector<uint32_t>& digest,
65  const uint8_t input[],
66  size_t blocks);
67 #endif
68 
69 #if defined(BOTAN_HAS_SHA2_32_X86)
70  static void compress_digest_x86(secure_vector<uint32_t>& digest,
71  const uint8_t input[],
72  size_t blocks);
73 #endif
74 
75  void compress_n(const uint8_t[], size_t blocks) override;
76  void copy_out(uint8_t[]) override;
77 
78  secure_vector<uint32_t> m_digest;
79  };
80 
81 }
82 
83 #endif
std::string name() const override
Definition: sha2_32.h:22
std::string name() const override
Definition: sha2_32.h:44
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
HashFunction * clone() const override
Definition: sha2_32.h:46
HashFunction * clone() const override
Definition: sha2_32.h:24
size_t output_length() const override
Definition: sha2_32.h:23
Definition: alg_id.cpp:13
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
size_t output_length() const override
Definition: sha2_32.h:45