Crypto++  5.6.3
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 #if defined(CRYPTOPP_LLVM_CLANG_VERSION) && (CRYPTOPP_LLVM_CLANG_VERSION < 30400)
15 # define CRYPTOPP_DISABLE_SHA_ASM
16 #endif
17 
18 NAMESPACE_BEGIN(CryptoPP)
19 
20 /// <a href="http://www.weidai.com/scan-mirror/md.html#SHA-1">SHA-1</a>
21 class CRYPTOPP_DLL SHA1 : public IteratedHashWithStaticTransform<word32, BigEndian, 64, 20, SHA1>
22 {
23 public:
24  static void CRYPTOPP_API InitState(HashWordType *state);
25  static void CRYPTOPP_API Transform(word32 *digest, const word32 *data);
26  static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-1";}
27 };
28 
29 typedef SHA1 SHA; // for backwards compatibility
30 
31 //! implements the SHA-256 standard
32 class CRYPTOPP_DLL SHA256 : public IteratedHashWithStaticTransform<word32, BigEndian, 64, 32, SHA256, 32, true>
33 {
34 public:
35 #if (defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_X32_ASM_AVAILABLE) || defined(CRYPTOPP_X64_MASM_AVAILABLE)) && !defined(CRYPTOPP_DISABLE_SHA_ASM)
36  size_t HashMultipleBlocks(const word32 *input, size_t length);
37 #endif
38  static void CRYPTOPP_API InitState(HashWordType *state);
39  static void CRYPTOPP_API Transform(word32 *digest, const word32 *data);
40  static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-256";}
41 };
42 
43 //! implements the SHA-224 standard
44 class CRYPTOPP_DLL SHA224 : public IteratedHashWithStaticTransform<word32, BigEndian, 64, 32, SHA224, 28, true>
45 {
46 public:
47 #if (defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_X32_ASM_AVAILABLE) || defined(CRYPTOPP_X64_MASM_AVAILABLE)) && !defined(CRYPTOPP_DISABLE_SHA_ASM)
48  size_t HashMultipleBlocks(const word32 *input, size_t length);
49 #endif
50  static void CRYPTOPP_API InitState(HashWordType *state);
51  static void CRYPTOPP_API Transform(word32 *digest, const word32 *data) {SHA256::Transform(digest, data);}
52  static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-224";}
53 };
54 
55 //! implements the SHA-512 standard
56 class CRYPTOPP_DLL SHA512 : public IteratedHashWithStaticTransform<word64, BigEndian, 128, 64, SHA512, 64, (CRYPTOPP_BOOL_X86|CRYPTOPP_BOOL_X32)>
57 {
58 public:
59  static void CRYPTOPP_API InitState(HashWordType *state);
60  static void CRYPTOPP_API Transform(word64 *digest, const word64 *data);
61  static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-512";}
62 };
63 
64 //! implements the SHA-384 standard
65 class CRYPTOPP_DLL SHA384 : public IteratedHashWithStaticTransform<word64, BigEndian, 128, 64, SHA384, 48, (CRYPTOPP_BOOL_X86|CRYPTOPP_BOOL_X32)>
66 {
67 public:
68  static void CRYPTOPP_API InitState(HashWordType *state);
69  static void CRYPTOPP_API Transform(word64 *digest, const word64 *data) {SHA512::Transform(digest, data);}
70  static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-384";}
71 };
72 
73 NAMESPACE_END
74 
75 #endif
implements the SHA-384 standard
Definition: sha.h:65
implements the SHA-256 standard
Definition: sha.h:32
Converts a typename to an enumerated value.
Definition: cryptlib.h:115
Library configuration file.
implements the SHA-512 standard
Definition: sha.h:56
SHA-1
Definition: sha.h:21
Crypto++ library namespace.
implements the SHA-224 standard
Definition: sha.h:44