diff --git a/sha.cpp b/sha.cpp index cc0213fc..7142b03a 100644 --- a/sha.cpp +++ b/sha.cpp @@ -360,8 +360,8 @@ static void CRYPTOPP_FASTCALL SHA256_HashBlocks_SSE2(word32 *state, const word32 ASJ( jnz, 2, f) AS1( dec DWORD PTR K_END) #endif - AS2( movdqa xmm0, XMMWORD_PTR [WORD_REG(cx)+0*16]) - AS2( movdqa xmm1, XMMWORD_PTR [WORD_REG(cx)+1*16]) + AS2( movdqu xmm0, XMMWORD_PTR [WORD_REG(cx)+0*16]) + AS2( movdqu xmm1, XMMWORD_PTR [WORD_REG(cx)+1*16]) #endif #if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 @@ -381,8 +381,8 @@ INTEL_NOPREFIX #if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE ASL(0) - AS2( movdqa E(0), xmm1) - AS2( movdqa A(0), xmm0) + AS2( movdqu E(0), xmm1) + AS2( movdqu A(0), xmm0) #endif #if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 ASL(3) @@ -449,12 +449,12 @@ INTEL_NOPREFIX AS2( test DWORD PTR K_END, 1) ASJ( jz, 4, f) #endif - AS2( movdqa xmm1, XMMWORD_PTR [AS_REG_7+1*16]) - AS2( movdqa xmm0, XMMWORD_PTR [AS_REG_7+0*16]) + AS2( movdqu xmm1, XMMWORD_PTR [AS_REG_7+1*16]) + AS2( movdqu xmm0, XMMWORD_PTR [AS_REG_7+0*16]) AS2( paddd xmm1, E(0)) AS2( paddd xmm0, A(0)) - AS2( movdqa [AS_REG_7+1*16], xmm1) - AS2( movdqa [AS_REG_7+0*16], xmm0) + AS2( movdqu [AS_REG_7+1*16], xmm1) + AS2( movdqu [AS_REG_7+0*16], xmm0) AS2( cmp WORD_REG(dx), DATA_END) ATT_NOPREFIX ASJ( jb, 0, b) @@ -845,16 +845,16 @@ CRYPTOPP_NAKED static void CRYPTOPP_FASTCALL SHA512_SSE2_Transform(word64 *state AS2( lea esi, [esp+4+20*8+8]) // 16-byte alignment, then add 8 #endif - AS2( movdqa xmm0, [ecx+0*16]) + AS2( movdqu xmm0, [ecx+0*16]) AS2( movdq2q mm4, xmm0) - AS2( movdqa [edi+0*16], xmm0) - AS2( movdqa xmm0, [ecx+1*16]) - AS2( movdqa [edi+1*16], xmm0) - AS2( movdqa xmm0, [ecx+2*16]) + AS2( movdqu [edi+0*16], xmm0) + AS2( movdqu xmm0, [ecx+1*16]) + AS2( movdqu [edi+1*16], xmm0) + AS2( movdqu xmm0, [ecx+2*16]) AS2( movdq2q mm5, xmm0) - AS2( movdqa [edi+2*16], xmm0) - AS2( movdqa xmm0, [ecx+3*16]) - AS2( movdqa [edi+3*16], xmm0) + AS2( movdqu [edi+2*16], xmm0) + AS2( movdqu xmm0, [ecx+3*16]) + AS2( movdqu [edi+3*16], xmm0) ASJ( jmp, 0, f) #define SSE2_S0_S1(r, a, b, c) \ @@ -873,9 +873,9 @@ CRYPTOPP_NAKED static void CRYPTOPP_FASTCALL SHA512_SSE2_Transform(word64 *state AS2( pxor r, mm6) #define SSE2_s0(r, a, b, c) \ - AS2( movdqa xmm6, r)\ + AS2( movdqu xmm6, r)\ AS2( psrlq r, a)\ - AS2( movdqa xmm7, r)\ + AS2( movdqu xmm7, r)\ AS2( psllq xmm6, 64-c)\ AS2( pxor xmm7, xmm6)\ AS2( psrlq r, b-a)\ @@ -886,9 +886,9 @@ CRYPTOPP_NAKED static void CRYPTOPP_FASTCALL SHA512_SSE2_Transform(word64 *state AS2( pxor r, xmm6) #define SSE2_s1(r, a, b, c) \ - AS2( movdqa xmm6, r)\ + AS2( movdqu xmm6, r)\ AS2( psrlq r, a)\ - AS2( movdqa xmm7, r)\ + AS2( movdqu xmm7, r)\ AS2( psllq xmm6, 64-c)\ AS2( pxor xmm7, xmm6)\ AS2( psrlq r, b-a)\ @@ -946,7 +946,7 @@ CRYPTOPP_NAKED static void CRYPTOPP_FASTCALL SHA512_SSE2_Transform(word64 *state // data expansion, W[i-2] already in xmm0 AS2( movdqu xmm3, [esi]) AS2( paddq xmm3, [esi+(16-7)*8]) - AS2( movdqa xmm2, [esi+(16-15)*8]) + AS2( movdqu xmm2, [esi+(16-15)*8]) SSE2_s1(xmm0, 6, 19, 61) AS2( paddq xmm0, xmm3) SSE2_s0(xmm2, 1, 7, 8) @@ -983,9 +983,9 @@ CRYPTOPP_NAKED static void CRYPTOPP_FASTCALL SHA512_SSE2_Transform(word64 *state ASJ( jne, 1, b) #define SSE2_CombineState(i) \ - AS2( movdqa xmm0, [edi+i*16])\ + AS2( movdqu xmm0, [edi+i*16])\ AS2( paddq xmm0, [ecx+i*16])\ - AS2( movdqa [ecx+i*16], xmm0) + AS2( movdqu [ecx+i*16], xmm0) SSE2_CombineState(0) SSE2_CombineState(1) diff --git a/sha.h b/sha.h index f3c3f423..1f6041d5 100644 --- a/sha.h +++ b/sha.h @@ -29,8 +29,25 @@ public: size_t HashMultipleBlocks(const word32 *input, size_t length); #endif static void CRYPTOPP_API InitState(HashWordType *state); + //! \brief Operate the hash + //! \param digest the state of the hash + //! \param data the data to be digested + //! \details Transform operates the hash on data. When the call is invoked + //! data holds initial state. Upon return data holds the hash or + //! updated state. + //! \details Hashes which derive from IteratedHashWithStaticTransform provide static + //! member functions InitState and Transform. External classes, like SEAL and MDC, + //! can initialize state with a user provided key and operate the hash on the data + //! with the used supplied initial state. + //! \note On Intel platforms the state array and data must be 16-byte aligned for SSE2. static void CRYPTOPP_API Transform(word32 *digest, const word32 *data); + //! \brief The algorithm name + //! \returns C-style string "SHA-1" CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-1";} + +#if CRYPTOPP_BOOL_SSE_SHA_INTRINSICS_AVAILABLE + size_t HashMultipleBlocks(const word32 *input, size_t length); +#endif }; //! \class SHA256 @@ -40,12 +57,34 @@ public: class CRYPTOPP_DLL SHA256 : public IteratedHashWithStaticTransform { public: + //! \brief Initialize state array + //! \param state the state of the hash + //! \details InitState sets a state array to SHA256 initial values + //! \details Hashes which derive from IteratedHashWithStaticTransform provide static + //! member functions InitState and Transform. External classes, like SEAL and MDC, + //! can initialize state with a user provided key and operate the hash on the data + //! with the used supplied initial state. + //! \note On Intel platforms the state array must be 16-byte aligned for SSE2. + static void CRYPTOPP_API InitState(HashWordType *state); + //! \brief Operate the hash + //! \param digest the state of the hash + //! \param data the data to be digested + //! \details Transform operates the hash on data. When the call is invoked + //! data holds initial state. Upon return data holds the hash or + //! updated state. + //! \details Hashes which derive from IteratedHashWithStaticTransform provide static + //! member functions InitState and Transform. External classes, like SEAL and MDC, + //! can initialize state with a user provided key and operate the hash on the data + //! with the used supplied initial state. + //! \note On Intel platforms the state array and data must be 16-byte aligned for SSE2. + static void CRYPTOPP_API Transform(word32 *digest, const word32 *data); + //! \brief The algorithm name + //! \returns C-style string "SHA-256" + CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-256";} + #if (defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_X32_ASM_AVAILABLE) || defined(CRYPTOPP_X64_MASM_AVAILABLE)) && !defined(CRYPTOPP_DISABLE_SHA_ASM) size_t HashMultipleBlocks(const word32 *input, size_t length); #endif - static void CRYPTOPP_API InitState(HashWordType *state); - static void CRYPTOPP_API Transform(word32 *digest, const word32 *data); - CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-256";} }; //! \class SHA224 @@ -55,12 +94,34 @@ public: class CRYPTOPP_DLL SHA224 : public IteratedHashWithStaticTransform { public: + //! \brief Initialize state array + //! \param state the state of the hash + //! \details InitState sets a state array to SHA224 initial values + //! \details Hashes which derive from IteratedHashWithStaticTransform provide static + //! member functions InitState and Transform. External classes, like SEAL and MDC, + //! can initialize state with a user provided key and operate the hash on the data + //! with the used supplied initial state. + //! \note On Intel platforms the state array must be 16-byte aligned for SSE2. + static void CRYPTOPP_API InitState(HashWordType *state); + //! \brief Operate the hash + //! \param digest the state of the hash + //! \param data the data to be digested + //! \details Transform operates the hash on data. When the call is invoked + //! data holds initial state. Upon return data holds the hash or + //! updated state. + //! \details Hashes which derive from IteratedHashWithStaticTransform provide static + //! member functions InitState and Transform. External classes, like SEAL and MDC, + //! can initialize state with a user provided key and operate the hash on the data + //! with the used supplied initial state. + //! \note On Intel platforms the state array and data must be 16-byte aligned for SSE2. + static void CRYPTOPP_API Transform(word32 *digest, const word32 *data) {SHA256::Transform(digest, data);} + //! \brief The algorithm name + //! \returns C-style string "SHA-224" + CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-224";} + #if (defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_X32_ASM_AVAILABLE) || defined(CRYPTOPP_X64_MASM_AVAILABLE)) && !defined(CRYPTOPP_DISABLE_SHA_ASM) size_t HashMultipleBlocks(const word32 *input, size_t length); #endif - static void CRYPTOPP_API InitState(HashWordType *state); - static void CRYPTOPP_API Transform(word32 *digest, const word32 *data) {SHA256::Transform(digest, data);} - CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-224";} }; //! \class SHA512 @@ -70,8 +131,29 @@ public: class CRYPTOPP_DLL SHA512 : public IteratedHashWithStaticTransform { public: + //! \brief Initialize state array + //! \param state the state of the hash + //! \details InitState sets a state array to SHA512 initial values + //! \details Hashes which derive from IteratedHashWithStaticTransform provide static + //! member functions InitState and Transform. External classes, like SEAL and MDC, + //! can initialize state with a user provided key and operate the hash on the data + //! with the used supplied initial state. + //! \note On Intel platforms the state array must be 16-byte aligned for SSE2. static void CRYPTOPP_API InitState(HashWordType *state); + //! \brief Operate the hash + //! \param digest the state of the hash + //! \param data the data to be digested + //! \details Transform operates the hash on data. When the call is invoked + //! data holds initial state. Upon return data holds the hash or + //! updated state. + //! \details Hashes which derive from IteratedHashWithStaticTransform provide static + //! member functions InitState and Transform. External classes, like SEAL and MDC, + //! can initialize state with a user provided key and operate the hash on the data + //! with the used supplied initial state. + //! \note On Intel platforms the state array and data must be 16-byte aligned for SSE2. static void CRYPTOPP_API Transform(word64 *digest, const word64 *data); + //! \brief The algorithm name + //! \returns C-style string "SHA-512" CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-512";} }; @@ -82,8 +164,29 @@ public: class CRYPTOPP_DLL SHA384 : public IteratedHashWithStaticTransform { public: + //! \brief Initialize state array + //! \param state the state of the hash + //! \details InitState sets a state array to SHA384 initial values + //! \details Hashes which derive from IteratedHashWithStaticTransform provide static + //! member functions InitState and Transform. External classes, like SEAL and MDC, + //! can initialize state with a user provided key and operate the hash on the data + //! with the used supplied initial state. + //! \note On Intel platforms the state array must be 16-byte aligned for SSE2. static void CRYPTOPP_API InitState(HashWordType *state); + //! \brief Operate the hash + //! \param digest the state of the hash + //! \param data the data to be digested + //! \details Transform operates the hash on data. When the call is invoked + //! data holds initial state. Upon return data holds the hash or + //! updated state. + //! \details Hashes which derive from IteratedHashWithStaticTransform provide static + //! member functions InitState and Transform. External classes, like SEAL and MDC, + //! can initialize state with a user provided key and operate the hash on the data + //! with the used supplied initial state. + //! \note On Intel platforms the state array and data must be 16-byte aligned for SSE2. static void CRYPTOPP_API Transform(word64 *digest, const word64 *data) {SHA512::Transform(digest, data);} + //! \brief The algorithm name + //! \returns C-style string "SHA-384" CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "SHA-384";} };