Crypto++  5.6.5
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 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++ 5.7
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++ 5.7
25 class CRYPTOPP_DLL SHA1 : public IteratedHashWithStaticTransform<word32, BigEndian, 64, 20, SHA1>
26 {
27 public:
28  static void CRYPTOPP_API InitState(HashWordType *state);
29  static void CRYPTOPP_API Transform(word32 *digest, const word32 *data);
30  CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-1";}
31 };
32 
33 typedef SHA1 SHA; // for backwards compatibility
34 
35 //! \class SHA256
36 //! \brief SHA-256 message digest
37 //! \sa <a href="http://www.weidai.com/scan-mirror/md.html#SHA-256">SHA-256</a>
38 //! \since Crypto++ 4.0, Intel SHA extensions since Crypto++ 5.7
39 class CRYPTOPP_DLL SHA256 : public IteratedHashWithStaticTransform<word32, BigEndian, 64, 32, SHA256, 32, true>
40 {
41 public:
42 #if (defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_X32_ASM_AVAILABLE) || defined(CRYPTOPP_X64_MASM_AVAILABLE)) && !defined(CRYPTOPP_DISABLE_SHA_ASM)
43  size_t HashMultipleBlocks(const word32 *input, size_t length);
44 #endif
45  static void CRYPTOPP_API InitState(HashWordType *state);
46  static void CRYPTOPP_API Transform(word32 *digest, const word32 *data);
47  CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-256";}
48 };
49 
50 //! \class SHA224
51 //! \brief SHA-224 message digest
52 //! \sa <a href="http://www.weidai.com/scan-mirror/md.html#SHA-224">SHA-224</a>
53 //! \since Crypto++ 4.0, Intel SHA extensions since Crypto++ 5.7
54 class CRYPTOPP_DLL SHA224 : public IteratedHashWithStaticTransform<word32, BigEndian, 64, 32, SHA224, 28, true>
55 {
56 public:
57 #if (defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_X32_ASM_AVAILABLE) || defined(CRYPTOPP_X64_MASM_AVAILABLE)) && !defined(CRYPTOPP_DISABLE_SHA_ASM)
58  size_t HashMultipleBlocks(const word32 *input, size_t length);
59 #endif
60  static void CRYPTOPP_API InitState(HashWordType *state);
61  static void CRYPTOPP_API Transform(word32 *digest, const word32 *data) {SHA256::Transform(digest, data);}
62  CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-224";}
63 };
64 
65 //! \class SHA512
66 //! \brief SHA-512 message digest
67 //! \sa <a href="http://www.weidai.com/scan-mirror/md.html#SHA-512">SHA-512</a>
68 //! \since Crypto++ 4.0
69 class CRYPTOPP_DLL SHA512 : public IteratedHashWithStaticTransform<word64, BigEndian, 128, 64, SHA512, 64, (CRYPTOPP_BOOL_X86|CRYPTOPP_BOOL_X32)>
70 {
71 public:
72  static void CRYPTOPP_API InitState(HashWordType *state);
73  static void CRYPTOPP_API Transform(word64 *digest, const word64 *data);
74  CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-512";}
75 };
76 
77 //! \class SHA384
78 //! \brief SHA-384 message digest
79 //! \sa <a href="http://www.weidai.com/scan-mirror/md.html#SHA-384">SHA-384</a>
80 //! \since Crypto++ 4.0
81 class CRYPTOPP_DLL SHA384 : public IteratedHashWithStaticTransform<word64, BigEndian, 128, 64, SHA384, 48, (CRYPTOPP_BOOL_X86|CRYPTOPP_BOOL_X32)>
82 {
83 public:
84  static void CRYPTOPP_API InitState(HashWordType *state);
85  static void CRYPTOPP_API Transform(word64 *digest, const word64 *data) {SHA512::Transform(digest, data);}
86  CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-384";}
87 };
88 
89 NAMESPACE_END
90 
91 #endif
SHA-384 message digest.
Definition: sha.h:81
SHA-256 message digest.
Definition: sha.h:39
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:116
Library configuration file.
SHA-512 message digest.
Definition: sha.h:69
SHA-1 message digest.
Definition: sha.h:25
Crypto++ library namespace.
SHA-224 message digest.
Definition: sha.h:54