Botan  2.11.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 */
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  std::string provider() const override;
30 
31  SHA_224() : MDx_HashFunction(64, true, true), m_digest(8)
32  { clear(); }
33  private:
34  void compress_n(const uint8_t[], size_t blocks) override;
35  void copy_out(uint8_t[]) override;
36 
37  secure_vector<uint32_t> m_digest;
38  };
39 
40 /**
41 * SHA-256
42 */
44  {
45  public:
46  std::string name() const override { return "SHA-256"; }
47  size_t output_length() const override { return 32; }
48  HashFunction* clone() const override { return new SHA_256; }
49  std::unique_ptr<HashFunction> copy_state() const override;
50 
51  void clear() override;
52 
53  std::string provider() const override;
54 
55  SHA_256() : MDx_HashFunction(64, true, true), m_digest(8)
56  { clear(); }
57 
58  /*
59  * Perform a SHA-256 compression. For internal use
60  */
61  static void compress_digest(secure_vector<uint32_t>& digest,
62  const uint8_t input[],
63  size_t blocks);
64 
65  private:
66 
67 #if defined(BOTAN_HAS_SHA2_32_ARMV8)
68  static void compress_digest_armv8(secure_vector<uint32_t>& digest,
69  const uint8_t input[],
70  size_t blocks);
71 #endif
72 
73 #if defined(BOTAN_HAS_SHA2_32_X86_BMI2)
74  static void compress_digest_x86_bmi2(secure_vector<uint32_t>& digest,
75  const uint8_t input[],
76  size_t blocks);
77 #endif
78 
79 #if defined(BOTAN_HAS_SHA2_32_X86)
80  static void compress_digest_x86(secure_vector<uint32_t>& digest,
81  const uint8_t input[],
82  size_t blocks);
83 #endif
84 
85  void compress_n(const uint8_t[], size_t blocks) override;
86  void copy_out(uint8_t[]) override;
87 
88  secure_vector<uint32_t> m_digest;
89  };
90 
91 }
92 
93 #endif
std::string name() const override
Definition: sha2_32.h:22
std::string name() const override
Definition: sha2_32.h:46
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
HashFunction * clone() const override
Definition: sha2_32.h:48
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:65
size_t output_length() const override
Definition: sha2_32.h:47