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