Crypto++  5.6.4
Free C++ class library of cryptographic schemes
sha.h
Go to the documentation of this file.
1 // sha.h - written and placed in the public domain by Wei Dai
2 
3 //! \file
4 //! \headerfile sha.h
5 //! \brief Classes for SHA-1 and SHA-2 family of message digests
6 
7 #ifndef CRYPTOPP_SHA_H
8 #define CRYPTOPP_SHA_H
9 
10 #include "config.h"
11 #include "iterhash.h"
12 
13 // Clang 3.3 integrated assembler crash on Linux
14 // http://github.com/weidai11/cryptopp/issues/264
15 #if defined(CRYPTOPP_LLVM_CLANG_VERSION) && (CRYPTOPP_LLVM_CLANG_VERSION < 30400)
16 # define CRYPTOPP_DISABLE_SHA_ASM
17 #endif
18 
19 NAMESPACE_BEGIN(CryptoPP)
20 
21 /// <a href="http://www.weidai.com/scan-mirror/md.html#SHA-1">SHA-1</a>
22 class CRYPTOPP_DLL SHA1 : public IteratedHashWithStaticTransform<word32, BigEndian, 64, 20, SHA1>
23 {
24 public:
25  static void CRYPTOPP_API InitState(HashWordType *state);
26  static void CRYPTOPP_API Transform(word32 *digest, const word32 *data);
27  CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-1";}
28 };
29 
30 typedef SHA1 SHA; // for backwards compatibility
31 
32 //! implements the SHA-256 standard
33 class CRYPTOPP_DLL SHA256 : public IteratedHashWithStaticTransform<word32, BigEndian, 64, 32, SHA256, 32, true>
34 {
35 public:
36 #if (defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_X32_ASM_AVAILABLE) || defined(CRYPTOPP_X64_MASM_AVAILABLE)) && !defined(CRYPTOPP_DISABLE_SHA_ASM)
37  size_t HashMultipleBlocks(const word32 *input, size_t length);
38 #endif
39  static void CRYPTOPP_API InitState(HashWordType *state);
40  static void CRYPTOPP_API Transform(word32 *digest, const word32 *data);
41  CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-256";}
42 };
43 
44 //! implements the SHA-224 standard
45 class CRYPTOPP_DLL SHA224 : public IteratedHashWithStaticTransform<word32, BigEndian, 64, 32, SHA224, 28, true>
46 {
47 public:
48 #if (defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_X32_ASM_AVAILABLE) || defined(CRYPTOPP_X64_MASM_AVAILABLE)) && !defined(CRYPTOPP_DISABLE_SHA_ASM)
49  size_t HashMultipleBlocks(const word32 *input, size_t length);
50 #endif
51  static void CRYPTOPP_API InitState(HashWordType *state);
52  static void CRYPTOPP_API Transform(word32 *digest, const word32 *data) {SHA256::Transform(digest, data);}
53  CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-224";}
54 };
55 
56 //! implements the SHA-512 standard
57 class CRYPTOPP_DLL SHA512 : public IteratedHashWithStaticTransform<word64, BigEndian, 128, 64, SHA512, 64, (CRYPTOPP_BOOL_X86|CRYPTOPP_BOOL_X32)>
58 {
59 public:
60  static void CRYPTOPP_API InitState(HashWordType *state);
61  static void CRYPTOPP_API Transform(word64 *digest, const word64 *data);
62  CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-512";}
63 };
64 
65 //! implements the SHA-384 standard
66 class CRYPTOPP_DLL SHA384 : public IteratedHashWithStaticTransform<word64, BigEndian, 128, 64, SHA384, 48, (CRYPTOPP_BOOL_X86|CRYPTOPP_BOOL_X32)>
67 {
68 public:
69  static void CRYPTOPP_API InitState(HashWordType *state);
70  static void CRYPTOPP_API Transform(word64 *digest, const word64 *data) {SHA512::Transform(digest, data);}
71  CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-384";}
72 };
73 
74 NAMESPACE_END
75 
76 #endif
implements the SHA-384 standard
Definition: sha.h:66
implements the SHA-256 standard
Definition: sha.h:33
Iterated hash with a static transformation function.
Definition: iterhash.h:152
Converts a typename to an enumerated value.
Definition: cryptlib.h:120
Library configuration file.
implements the SHA-512 standard
Definition: sha.h:57
SHA-1
Definition: sha.h:22
Crypto++ library namespace.
implements the SHA-224 standard
Definition: sha.h:45