Crypto++  5.6.5
Free C++ class library of cryptographic schemes
sha.h
Go to the documentation of this file.
1 // sha.h - originally written and placed in the public domain by Wei Dai
2 
3 //! \file sha.h
4 //! \brief Classes for SHA-1 and SHA-2 family of message digests
5 //! \since SHA1 since Crypto++ 1.0, SHA2 since Crypto++ 4.0, Intel SHA extensions since Crypto++ 6.0
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 //! \class SHA1
22 //! \brief SHA-1 message digest
23 //! \sa <a href="http://www.weidai.com/scan-mirror/md.html#SHA-1">SHA-1</a>
24 //! \since Crypto++ 1.0, Intel SHA extensions since Crypto++ 6.0
25 class CRYPTOPP_DLL SHA1 : public IteratedHashWithStaticTransform<word32, BigEndian, 64, 20, SHA1>
26 {
27 public:
28 #if CRYPTOPP_BOOL_SSE_SHA_INTRINSICS_AVAILABLE
29  size_t HashMultipleBlocks(const word32 *input, size_t length);
30 #endif
31  static void CRYPTOPP_API InitState(HashWordType *state);
32  static void CRYPTOPP_API Transform(word32 *digest, const word32 *data);
33  CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-1";}
34 };
35 
36 //! \class SHA256
37 //! \brief SHA-256 message digest
38 //! \sa <a href="http://www.weidai.com/scan-mirror/md.html#SHA-256">SHA-256</a>
39 //! \since Crypto++ 4.0, Intel SHA extensions since Crypto++ 6.0
40 class CRYPTOPP_DLL SHA256 : public IteratedHashWithStaticTransform<word32, BigEndian, 64, 32, SHA256, 32, true>
41 {
42 public:
43 #if (defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_X32_ASM_AVAILABLE) || defined(CRYPTOPP_X64_MASM_AVAILABLE)) && !defined(CRYPTOPP_DISABLE_SHA_ASM)
44  size_t HashMultipleBlocks(const word32 *input, size_t length);
45 #endif
46  static void CRYPTOPP_API InitState(HashWordType *state);
47  static void CRYPTOPP_API Transform(word32 *digest, const word32 *data);
48  CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-256";}
49 };
50 
51 //! \class SHA224
52 //! \brief SHA-224 message digest
53 //! \sa <a href="http://www.weidai.com/scan-mirror/md.html#SHA-224">SHA-224</a>
54 //! \since Crypto++ 4.0, Intel SHA extensions since Crypto++ 6.0
55 class CRYPTOPP_DLL SHA224 : public IteratedHashWithStaticTransform<word32, BigEndian, 64, 32, SHA224, 28, true>
56 {
57 public:
58 #if (defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_X32_ASM_AVAILABLE) || defined(CRYPTOPP_X64_MASM_AVAILABLE)) && !defined(CRYPTOPP_DISABLE_SHA_ASM)
59  size_t HashMultipleBlocks(const word32 *input, size_t length);
60 #endif
61  static void CRYPTOPP_API InitState(HashWordType *state);
62  static void CRYPTOPP_API Transform(word32 *digest, const word32 *data) {SHA256::Transform(digest, data);}
63  CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-224";}
64 };
65 
66 //! \class SHA512
67 //! \brief SHA-512 message digest
68 //! \sa <a href="http://www.weidai.com/scan-mirror/md.html#SHA-512">SHA-512</a>
69 //! \since Crypto++ 4.0
70 class CRYPTOPP_DLL SHA512 : public IteratedHashWithStaticTransform<word64, BigEndian, 128, 64, SHA512, 64, (CRYPTOPP_BOOL_X86|CRYPTOPP_BOOL_X32)>
71 {
72 public:
73  static void CRYPTOPP_API InitState(HashWordType *state);
74  static void CRYPTOPP_API Transform(word64 *digest, const word64 *data);
75  CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-512";}
76 };
77 
78 //! \class SHA384
79 //! \brief SHA-384 message digest
80 //! \sa <a href="http://www.weidai.com/scan-mirror/md.html#SHA-384">SHA-384</a>
81 //! \since Crypto++ 4.0
82 class CRYPTOPP_DLL SHA384 : public IteratedHashWithStaticTransform<word64, BigEndian, 128, 64, SHA384, 48, (CRYPTOPP_BOOL_X86|CRYPTOPP_BOOL_X32)>
83 {
84 public:
85  static void CRYPTOPP_API InitState(HashWordType *state);
86  static void CRYPTOPP_API Transform(word64 *digest, const word64 *data) {SHA512::Transform(digest, data);}
87  CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-384";}
88 };
89 
90 NAMESPACE_END
91 
92 #endif
SHA-384 message digest.
Definition: sha.h:82
SHA-256 message digest.
Definition: sha.h:40
Iterated hash with a static transformation function.
Definition: iterhash.h:150
Converts an enumeration to a type suitable for use as a template parameter.
Definition: cryptlib.h:126
Library configuration file.
SHA-512 message digest.
Definition: sha.h:70
SHA-1 message digest.
Definition: sha.h:25
Crypto++ library namespace.
SHA-224 message digest.
Definition: sha.h:55