|
||||
File indexing completed on 2025-01-18 09:55:09
0001 // sha.h - originally written and placed in the public domain by Wei Dai 0002 0003 /// \file sha.h 0004 /// \brief Classes for SHA-1 and SHA-2 family of message digests 0005 /// \since SHA1 since Crypto++ 1.0, SHA2 since Crypto++ 4.0, ARMv8 SHA since 0006 /// Crypto++ 6.0, Intel SHA since Crypto++ 6.0, Power8 SHA since Crypto++ 6.1 0007 0008 #ifndef CRYPTOPP_SHA_H 0009 #define CRYPTOPP_SHA_H 0010 0011 #include "config.h" 0012 #include "iterhash.h" 0013 0014 // Clang 3.3 integrated assembler crash on Linux. Clang 3.4 due to compiler 0015 // error with .intel_syntax, http://llvm.org/bugs/show_bug.cgi?id=24232 0016 #if CRYPTOPP_BOOL_X32 || defined(CRYPTOPP_DISABLE_MIXED_ASM) 0017 # define CRYPTOPP_DISABLE_SHA_ASM 1 0018 #endif 0019 0020 NAMESPACE_BEGIN(CryptoPP) 0021 0022 /// \brief SHA-1 message digest 0023 /// \sa <a href="http://www.weidai.com/scan-mirror/md.html#SHA-1">SHA-1</a> 0024 /// \since SHA1 since Crypto++ 1.0, SHA2 since Crypto++ 4.0, ARMv8 SHA since 0025 /// Crypto++ 6.0, Intel SHA since Crypto++ 6.0 0026 class CRYPTOPP_DLL SHA1 : public IteratedHashWithStaticTransform<word32, BigEndian, 64, 20, SHA1> 0027 { 0028 public: 0029 /// \brief Initialize state array 0030 /// \param state the state of the hash 0031 /// \details InitState sets a state array to SHA1 initial values 0032 /// \details Hashes which derive from IteratedHashWithStaticTransform provide static 0033 /// member functions InitState and Transform. External classes, like SEAL and MDC, 0034 /// can initialize state with a user provided key and operate the hash on the data 0035 /// with the user supplied state. 0036 /// \note On Intel platforms the state array must be 16-byte aligned for SSE2. 0037 static void CRYPTOPP_API InitState(HashWordType *state); 0038 /// \brief Operate the hash 0039 /// \param digest the state of the hash 0040 /// \param data the data to be digested 0041 /// \details Transform operates the hash on <tt>data</tt>. When the call is invoked 0042 /// <tt>digest</tt> holds initial state. Upon return <tt>digest</tt> holds the hash 0043 /// or updated state. 0044 /// \details Hashes which derive from IteratedHashWithStaticTransform provide static 0045 /// member functions InitState and Transform. External classes, like SEAL and MDC, 0046 /// can initialize state with a user provided key and operate the hash on the data 0047 /// with the user supplied state. 0048 /// \note On Intel platforms the state array and data must be 16-byte aligned for SSE2. 0049 static void CRYPTOPP_API Transform(HashWordType *digest, const HashWordType *data); 0050 /// \brief The algorithm name 0051 /// \return C-style string "SHA-1" 0052 CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-1";} 0053 // Algorithm class 0054 std::string AlgorithmProvider() const; 0055 0056 protected: 0057 size_t HashMultipleBlocks(const HashWordType *input, size_t length); 0058 }; 0059 0060 /// \brief SHA-256 message digest 0061 /// \sa <a href="http://www.weidai.com/scan-mirror/md.html#SHA-256">SHA-256</a> 0062 /// \since SHA2 since Crypto++ 4.0, ARMv8 SHA since Crypto++ 6.0, 0063 /// Intel SHA since Crypto++ 6.0, Power8 SHA since Crypto++ 6.1 0064 class CRYPTOPP_DLL SHA256 : public IteratedHashWithStaticTransform<word32, BigEndian, 64, 32, SHA256, 32, true> 0065 { 0066 public: 0067 /// \brief Initialize state array 0068 /// \param state the state of the hash 0069 /// \details InitState sets a state array to SHA256 initial values 0070 /// \details Hashes which derive from IteratedHashWithStaticTransform provide static 0071 /// member functions InitState and Transform. External classes, like SEAL and MDC, 0072 /// can initialize state with a user provided key and operate the hash on the data 0073 /// with the user supplied state. 0074 /// \note On Intel platforms the state array must be 16-byte aligned for SSE2. 0075 static void CRYPTOPP_API InitState(HashWordType *state); 0076 /// \brief Operate the hash 0077 /// \param digest the state of the hash 0078 /// \param data the data to be digested 0079 /// \details Transform operates the hash on <tt>data</tt>. When the call is invoked 0080 /// <tt>digest</tt> holds initial state. Upon return <tt>digest</tt> holds the hash 0081 /// or updated state. 0082 /// \details Hashes which derive from IteratedHashWithStaticTransform provide static 0083 /// member functions InitState and Transform. External classes, like SEAL and MDC, 0084 /// can initialize state with a user provided key and operate the hash on the data 0085 /// with the user supplied state. 0086 /// \note On Intel platforms the state array and data must be 16-byte aligned for SSE2. 0087 static void CRYPTOPP_API Transform(HashWordType *digest, const HashWordType *data); 0088 /// \brief The algorithm name 0089 /// \return C-style string "SHA-256" 0090 CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-256";} 0091 0092 // Algorithm class 0093 std::string AlgorithmProvider() const; 0094 0095 protected: 0096 size_t HashMultipleBlocks(const HashWordType *input, size_t length); 0097 }; 0098 0099 /// \brief SHA-224 message digest 0100 /// \sa <a href="http://www.weidai.com/scan-mirror/md.html#SHA-224">SHA-224</a> 0101 /// \since SHA2 since Crypto++ 4.0, ARMv8 SHA since Crypto++ 6.0, 0102 /// Intel SHA since Crypto++ 6.0, Power8 SHA since Crypto++ 6.1 0103 class CRYPTOPP_DLL SHA224 : public IteratedHashWithStaticTransform<word32, BigEndian, 64, 32, SHA224, 28, true> 0104 { 0105 public: 0106 /// \brief Initialize state array 0107 /// \param state the state of the hash 0108 /// \details InitState sets a state array to SHA224 initial values 0109 /// \details Hashes which derive from IteratedHashWithStaticTransform provide static 0110 /// member functions InitState and Transform. External classes, like SEAL and MDC, 0111 /// can initialize state with a user provided key and operate the hash on the data 0112 /// with the user supplied state. 0113 /// \note On Intel platforms the state array must be 16-byte aligned for SSE2. 0114 static void CRYPTOPP_API InitState(HashWordType *state); 0115 /// \brief Operate the hash 0116 /// \param digest the state of the hash 0117 /// \param data the data to be digested 0118 /// \details Transform operates the hash on <tt>data</tt>. When the call is invoked 0119 /// <tt>digest</tt> holds initial state. Upon return <tt>digest</tt> holds the hash 0120 /// or updated state. 0121 /// \details Hashes which derive from IteratedHashWithStaticTransform provide static 0122 /// member functions InitState and Transform. External classes, like SEAL and MDC, 0123 /// can initialize state with a user provided key and operate the hash on the data 0124 /// with the user supplied state. 0125 /// \note On Intel platforms the state array and data must be 16-byte aligned for SSE2. 0126 static void CRYPTOPP_API Transform(HashWordType *digest, const HashWordType *data) {SHA256::Transform(digest, data);} 0127 /// \brief The algorithm name 0128 /// \return C-style string "SHA-224" 0129 CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-224";} 0130 0131 // Algorithm class 0132 std::string AlgorithmProvider() const; 0133 0134 protected: 0135 size_t HashMultipleBlocks(const HashWordType *input, size_t length); 0136 }; 0137 0138 /// \brief SHA-512 message digest 0139 /// \sa <a href="http://www.weidai.com/scan-mirror/md.html#SHA-512">SHA-512</a> 0140 /// \since SHA2 since Crypto++ 4.0, Power8 SHA since Crypto++ 6.1 0141 class CRYPTOPP_DLL SHA512 : public IteratedHashWithStaticTransform<word64, BigEndian, 128, 64, SHA512, 64, true> 0142 { 0143 public: 0144 /// \brief Initialize state array 0145 /// \param state the state of the hash 0146 /// \details InitState sets a state array to SHA512 initial values 0147 /// \details Hashes which derive from IteratedHashWithStaticTransform provide static 0148 /// member functions InitState and Transform. External classes, like SEAL and MDC, 0149 /// can initialize state with a user provided key and operate the hash on the data 0150 /// with the user supplied state. 0151 /// \note On Intel platforms the state array must be 16-byte aligned for SSE2. 0152 static void CRYPTOPP_API InitState(HashWordType *state); 0153 /// \brief Operate the hash 0154 /// \param digest the state of the hash 0155 /// \param data the data to be digested 0156 /// \details Transform operates the hash on <tt>data</tt>. When the call is invoked 0157 /// <tt>digest</tt> holds initial state. Upon return <tt>digest</tt> holds the hash 0158 /// or updated state. 0159 /// \details Hashes which derive from IteratedHashWithStaticTransform provide static 0160 /// member functions InitState and Transform. External classes, like SEAL and MDC, 0161 /// can initialize state with a user provided key and operate the hash on the data 0162 /// with the user supplied state. 0163 /// \note On Intel platforms the state array and data must be 16-byte aligned for SSE2. 0164 static void CRYPTOPP_API Transform(HashWordType *digest, const HashWordType *data); 0165 /// \brief The algorithm name 0166 /// \return C-style string "SHA-512" 0167 CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-512";} 0168 0169 // Algorithm class 0170 std::string AlgorithmProvider() const; 0171 }; 0172 0173 /// \brief SHA-384 message digest 0174 /// \sa <a href="http://www.weidai.com/scan-mirror/md.html#SHA-384">SHA-384</a> 0175 /// \since SHA2 since Crypto++ 4.0, Power8 SHA since Crypto++ 6.1 0176 class CRYPTOPP_DLL SHA384 : public IteratedHashWithStaticTransform<word64, BigEndian, 128, 64, SHA384, 48, true> 0177 { 0178 public: 0179 /// \brief Initialize state array 0180 /// \param state the state of the hash 0181 /// \details InitState sets a state array to SHA384 initial values 0182 /// \details Hashes which derive from IteratedHashWithStaticTransform provide static 0183 /// member functions InitState and Transform. External classes, like SEAL and MDC, 0184 /// can initialize state with a user provided key and operate the hash on the data 0185 /// with the user supplied state. 0186 /// \note On Intel platforms the state array must be 16-byte aligned for SSE2. 0187 static void CRYPTOPP_API InitState(HashWordType *state); 0188 /// \brief Operate the hash 0189 /// \param digest the state of the hash 0190 /// \param data the data to be digested 0191 /// \details Transform operates the hash on <tt>data</tt>. When the call is invoked 0192 /// <tt>digest</tt> holds initial state. Upon return <tt>digest</tt> holds the hash 0193 /// or updated state. 0194 /// \details Hashes which derive from IteratedHashWithStaticTransform provide static 0195 /// member functions InitState and Transform. External classes, like SEAL and MDC, 0196 /// can initialize state with a user provided key and operate the hash on the data 0197 /// with the user supplied state. 0198 /// \note On Intel platforms the state array and data must be 16-byte aligned for SSE2. 0199 static void CRYPTOPP_API Transform(HashWordType *digest, const HashWordType *data) {SHA512::Transform(digest, data);} 0200 /// \brief The algorithm name 0201 /// \return C-style string "SHA-384" 0202 CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-384";} 0203 0204 // Algorithm class 0205 std::string AlgorithmProvider() const; 0206 }; 0207 0208 NAMESPACE_END 0209 0210 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |