source: git/src-cryptopp/sha.h

Last change on this file was e230cb0, checked in by David Stainton <dstainton415@…>, at 2016-10-12T13:27:29Z

Add cryptopp from tag CRYPTOPP_5_6_5

  • Property mode set to 100644
File size: 3.1 KB
Line 
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//  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
19NAMESPACE_BEGIN(CryptoPP)
20
21/// <a href="http://www.weidai.com/scan-mirror/md.html#SHA-1">SHA-1</a>
22class CRYPTOPP_DLL SHA1 : public IteratedHashWithStaticTransform<word32, BigEndian, 64, 20, SHA1>
23{
24public:
25        static void CRYPTOPP_API InitState(HashWordType *state);
26        static void CRYPTOPP_API Transform(word32 *digest, const word32 *data);
27        CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-1";}
28};
29
30typedef SHA1 SHA;       // for backwards compatibility
31
32//! implements the SHA-256 standard
33class CRYPTOPP_DLL SHA256 : public IteratedHashWithStaticTransform<word32, BigEndian, 64, 32, SHA256, 32, true>
34{
35public:
36#if (defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_X32_ASM_AVAILABLE) || defined(CRYPTOPP_X64_MASM_AVAILABLE)) && !defined(CRYPTOPP_DISABLE_SHA_ASM)
37        size_t HashMultipleBlocks(const word32 *input, size_t length);
38#endif
39        static void CRYPTOPP_API InitState(HashWordType *state);
40        static void CRYPTOPP_API Transform(word32 *digest, const word32 *data);
41        CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-256";}
42};
43
44//! implements the SHA-224 standard
45class CRYPTOPP_DLL SHA224 : public IteratedHashWithStaticTransform<word32, BigEndian, 64, 32, SHA224, 28, true>
46{
47public:
48#if (defined(CRYPTOPP_X86_ASM_AVAILABLE) || defined(CRYPTOPP_X32_ASM_AVAILABLE) || defined(CRYPTOPP_X64_MASM_AVAILABLE)) && !defined(CRYPTOPP_DISABLE_SHA_ASM)
49        size_t HashMultipleBlocks(const word32 *input, size_t length);
50#endif
51        static void CRYPTOPP_API InitState(HashWordType *state);
52        static void CRYPTOPP_API Transform(word32 *digest, const word32 *data) {SHA256::Transform(digest, data);}
53        CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-224";}
54};
55
56//! implements the SHA-512 standard
57class CRYPTOPP_DLL SHA512 : public IteratedHashWithStaticTransform<word64, BigEndian, 128, 64, SHA512, 64, (CRYPTOPP_BOOL_X86|CRYPTOPP_BOOL_X32)>
58{
59public:
60        static void CRYPTOPP_API InitState(HashWordType *state);
61        static void CRYPTOPP_API Transform(word64 *digest, const word64 *data);
62        CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-512";}
63};
64
65//! implements the SHA-384 standard
66class CRYPTOPP_DLL SHA384 : public IteratedHashWithStaticTransform<word64, BigEndian, 128, 64, SHA384, 48, (CRYPTOPP_BOOL_X86|CRYPTOPP_BOOL_X32)>
67{
68public:
69        static void CRYPTOPP_API InitState(HashWordType *state);
70        static void CRYPTOPP_API Transform(word64 *digest, const word64 *data) {SHA512::Transform(digest, data);}
71        CRYPTOPP_CONSTEXPR static const char * CRYPTOPP_API StaticAlgorithmName() {return "SHA-384";}
72};
73
74NAMESPACE_END
75
76#endif
Note: See TracBrowser for help on using the repository browser.