Merge remote-tracking branch 'refs/remotes/weidai11/master' into Keccak-Typedef
commit
ee194ed19e
|
|
@ -119,6 +119,21 @@
|
|||
// set the name of Rijndael cipher, was "Rijndael" before version 5.3
|
||||
#define CRYPTOPP_RIJNDAEL_NAME "AES"
|
||||
|
||||
// CRYPTOPP_DEBUG enables the library's CRYPTOPP_ASSERT. CRYPTOPP_ASSERT
|
||||
// raises a SIGTRAP (Unix) or calls DebugBreak() (Windows). CRYPTOPP_ASSERT
|
||||
// is only in effect when CRYPTOPP_DEBUG, DEBUG or _DEBUG is defined. Unlike
|
||||
// Posix assert, CRYPTOPP_ASSERT is not affected by NDEBUG (or failure to
|
||||
// define it).
|
||||
// Also see http://github.com/weidai11/cryptopp/issues/277, CVE-2016-7420
|
||||
#if (defined(DEBUG) || defined(_DEBUG)) && !defined(CRYPTOPP_DEBUG)
|
||||
# define CRYPTOPP_DEBUG 1
|
||||
#endif
|
||||
|
||||
// ***************** Initialization and Constructor priorities ********************
|
||||
|
||||
// MacPorts/GCC and Solaris/GCC does not provide constructor(priority). Apple/GCC and Fink/GCC do provide it.
|
||||
// See http://cryptopp.com/wiki/Static_Initialization_Order_Fiasco
|
||||
|
||||
// CRYPTOPP_INIT_PRIORITY attempts to manage initialization of C++ static objects.
|
||||
// Under GCC, the library uses init_priority attribute in the range
|
||||
// [CRYPTOPP_INIT_PRIORITY, CRYPTOPP_INIT_PRIORITY+100]. Under Windows,
|
||||
|
|
@ -136,14 +151,18 @@
|
|||
# define CRYPTOPP_USER_PRIORITY 350
|
||||
#endif
|
||||
|
||||
// CRYPTOPP_DEBUG enables the library's CRYPTOPP_ASSERT. CRYPTOPP_ASSERT
|
||||
// raises a SIGTRAP (Unix) or calls DebugBreak() (Windows). CRYPTOPP_ASSERT
|
||||
// is only in effect when CRYPTOPP_DEBUG, DEBUG or _DEBUG is defined. Unlike
|
||||
// Posix assert, CRYPTOPP_ASSERT is not affected by NDEBUG (or failure to
|
||||
// define it).
|
||||
// Also see http://github.com/weidai11/cryptopp/issues/277, CVE-2016-7420
|
||||
#if (defined(DEBUG) || defined(_DEBUG)) && !defined(CRYPTOPP_DEBUG)
|
||||
# define CRYPTOPP_DEBUG 1
|
||||
// __attribute__(init_priority(250)) is supported
|
||||
#if (__GNUC__ && (CRYPTOPP_INIT_PRIORITY > 0) && ((CRYPTOPP_GCC_VERSION >= 40300) || (CRYPTOPP_LLVM_CLANG_VERSION >= 20900) || (_INTEL_COMPILER >= 300)) && !(MACPORTS_GCC_COMPILER > 0) && !defined(__sun__))
|
||||
# define HAVE_GCC_CONSTRUCTOR1 1
|
||||
#endif
|
||||
|
||||
// __attribute__(init_priority()) is supported
|
||||
#if (__GNUC__ && (CRYPTOPP_INIT_PRIORITY > 0) && !HAVE_GCC_CONSTRUCTOR1 && !(MACPORTS_GCC_COMPILER > 0) && !defined(__sun__))
|
||||
# define HAVE_GCC_CONSTRUCTOR0 1
|
||||
#endif
|
||||
|
||||
#if (_MSC_VER && (CRYPTOPP_INIT_PRIORITY > 0))
|
||||
# define HAVE_MSC_INIT_PRIORITY 1
|
||||
#endif
|
||||
|
||||
// ***************** Important Settings Again ********************
|
||||
|
|
@ -454,7 +473,7 @@ NAMESPACE_END
|
|||
#define CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE 0
|
||||
#endif
|
||||
|
||||
#if !defined(CRYPTOPP_DISABLE_SSE3) && (_MSC_VER >= 1400 || CRYPTOPP_GCC_VERSION >= 40102 || defined(__SSSE3__))
|
||||
#if !defined(CRYPTOPP_DISABLE_SSE3) && (_MSC_VER >= 1400 || (defined(__SSE3__) && defined(__SSSE3__)))
|
||||
#define CRYPTOPP_BOOL_SSSE3_ASM_AVAILABLE 1
|
||||
#else
|
||||
#define CRYPTOPP_BOOL_SSSE3_ASM_AVAILABLE 0
|
||||
|
|
@ -491,6 +510,13 @@ NAMESPACE_END
|
|||
#define CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE 0
|
||||
#endif
|
||||
|
||||
// AVX2 in MSC 18.00
|
||||
#if !defined(CRYPTOPP_DISABLE_ASM) && !defined(CRYPTOPP_DISABLE_AVX) && (((_MSC_VER >= 1600) && !defined(_M_ARM)) || (defined(__RDRND__) || defined(__RDSEED__) || defined(__AVX__)))
|
||||
#define CRYPTOPP_BOOL_AVX_AVAILABLE 1
|
||||
#else
|
||||
#define CRYPTOPP_BOOL_AVX_AVAILABLE 0
|
||||
#endif
|
||||
|
||||
// Requires ARMv7 and ACLE 1.0. Testing shows ARMv7 is really ARMv7a under most toolchains.
|
||||
#if !defined(CRYPTOPP_BOOL_NEON_INTRINSICS_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ASM)
|
||||
# if defined(__ARM_NEON__) || defined(__ARM_NEON) || defined(_M_ARM)
|
||||
|
|
|
|||
46
config.h
46
config.h
|
|
@ -119,6 +119,21 @@
|
|||
// set the name of Rijndael cipher, was "Rijndael" before version 5.3
|
||||
#define CRYPTOPP_RIJNDAEL_NAME "AES"
|
||||
|
||||
// CRYPTOPP_DEBUG enables the library's CRYPTOPP_ASSERT. CRYPTOPP_ASSERT
|
||||
// raises a SIGTRAP (Unix) or calls DebugBreak() (Windows). CRYPTOPP_ASSERT
|
||||
// is only in effect when CRYPTOPP_DEBUG, DEBUG or _DEBUG is defined. Unlike
|
||||
// Posix assert, CRYPTOPP_ASSERT is not affected by NDEBUG (or failure to
|
||||
// define it).
|
||||
// Also see http://github.com/weidai11/cryptopp/issues/277, CVE-2016-7420
|
||||
#if (defined(DEBUG) || defined(_DEBUG)) && !defined(CRYPTOPP_DEBUG)
|
||||
# define CRYPTOPP_DEBUG 1
|
||||
#endif
|
||||
|
||||
// ***************** Initialization and Constructor priorities ********************
|
||||
|
||||
// MacPorts/GCC and Solaris/GCC does not provide constructor(priority). Apple/GCC and Fink/GCC do provide it.
|
||||
// See http://cryptopp.com/wiki/Static_Initialization_Order_Fiasco
|
||||
|
||||
// CRYPTOPP_INIT_PRIORITY attempts to manage initialization of C++ static objects.
|
||||
// Under GCC, the library uses init_priority attribute in the range
|
||||
// [CRYPTOPP_INIT_PRIORITY, CRYPTOPP_INIT_PRIORITY+100]. Under Windows,
|
||||
|
|
@ -136,14 +151,18 @@
|
|||
# define CRYPTOPP_USER_PRIORITY 350
|
||||
#endif
|
||||
|
||||
// CRYPTOPP_DEBUG enables the library's CRYPTOPP_ASSERT. CRYPTOPP_ASSERT
|
||||
// raises a SIGTRAP (Unix) or calls DebugBreak() (Windows). CRYPTOPP_ASSERT
|
||||
// is only in effect when CRYPTOPP_DEBUG, DEBUG or _DEBUG is defined. Unlike
|
||||
// Posix assert, CRYPTOPP_ASSERT is not affected by NDEBUG (or failure to
|
||||
// define it).
|
||||
// Also see http://github.com/weidai11/cryptopp/issues/277, CVE-2016-7420
|
||||
#if (defined(DEBUG) || defined(_DEBUG)) && !defined(CRYPTOPP_DEBUG)
|
||||
# define CRYPTOPP_DEBUG 1
|
||||
// __attribute__(init_priority(250)) is supported
|
||||
#if (__GNUC__ && (CRYPTOPP_INIT_PRIORITY > 0) && ((CRYPTOPP_GCC_VERSION >= 40300) || (CRYPTOPP_LLVM_CLANG_VERSION >= 20900) || (_INTEL_COMPILER >= 300)) && !(MACPORTS_GCC_COMPILER > 0) && !defined(__sun__))
|
||||
# define HAVE_GCC_CONSTRUCTOR1 1
|
||||
#endif
|
||||
|
||||
// __attribute__(init_priority()) is supported
|
||||
#if (__GNUC__ && (CRYPTOPP_INIT_PRIORITY > 0) && !HAVE_GCC_CONSTRUCTOR1 && !(MACPORTS_GCC_COMPILER > 0) && !defined(__sun__))
|
||||
# define HAVE_GCC_CONSTRUCTOR0 1
|
||||
#endif
|
||||
|
||||
#if (_MSC_VER && (CRYPTOPP_INIT_PRIORITY > 0))
|
||||
# define HAVE_MSC_INIT_PRIORITY 1
|
||||
#endif
|
||||
|
||||
// ***************** Important Settings Again ********************
|
||||
|
|
@ -218,7 +237,7 @@ typedef unsigned int word32;
|
|||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
typedef unsigned __int64 word64;
|
||||
#define W64LIT(x) x##ui64
|
||||
#elif (_LP64 || __LP64__) && ((__arm64__ || __aarch64__) || !defined(CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562))
|
||||
#elif (_LP64 || __LP64__)
|
||||
typedef unsigned long word64;
|
||||
#define W64LIT(x) x##UL
|
||||
#else
|
||||
|
|
@ -454,7 +473,7 @@ NAMESPACE_END
|
|||
#define CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE 0
|
||||
#endif
|
||||
|
||||
#if !defined(CRYPTOPP_DISABLE_SSE3) && (_MSC_VER >= 1400 || CRYPTOPP_GCC_VERSION >= 40102 || defined(__SSSE3__))
|
||||
#if !defined(CRYPTOPP_DISABLE_SSE3) && (_MSC_VER >= 1400 || (defined(__SSE3__) && defined(__SSSE3__)))
|
||||
#define CRYPTOPP_BOOL_SSSE3_ASM_AVAILABLE 1
|
||||
#else
|
||||
#define CRYPTOPP_BOOL_SSSE3_ASM_AVAILABLE 0
|
||||
|
|
@ -491,6 +510,13 @@ NAMESPACE_END
|
|||
#define CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE 0
|
||||
#endif
|
||||
|
||||
// AVX2 in MSC 18.00
|
||||
#if !defined(CRYPTOPP_DISABLE_ASM) && !defined(CRYPTOPP_DISABLE_AVX) && (((_MSC_VER >= 1600) && !defined(_M_ARM)) || (defined(__RDRND__) || defined(__RDSEED__) || defined(__AVX__)))
|
||||
#define CRYPTOPP_BOOL_AVX_AVAILABLE 1
|
||||
#else
|
||||
#define CRYPTOPP_BOOL_AVX_AVAILABLE 0
|
||||
#endif
|
||||
|
||||
// Requires ARMv7 and ACLE 1.0. Testing shows ARMv7 is really ARMv7a under most toolchains.
|
||||
#if !defined(CRYPTOPP_BOOL_NEON_INTRINSICS_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ASM)
|
||||
# if defined(__ARM_NEON__) || defined(__ARM_NEON) || defined(_M_ARM)
|
||||
|
|
|
|||
5
cpu.cpp
5
cpu.cpp
|
|
@ -25,11 +25,6 @@
|
|||
NAMESPACE_BEGIN(CryptoPP)
|
||||
|
||||
#ifndef CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY
|
||||
|
||||
// MacPorts/GCC does not provide constructor(priority). Apple/GCC and Fink/GCC do provide it.
|
||||
#define HAVE_GCC_CONSTRUCTOR1 (__GNUC__ && (CRYPTOPP_INIT_PRIORITY > 0) && ((CRYPTOPP_GCC_VERSION >= 40300) || (CRYPTOPP_LLVM_CLANG_VERSION >= 20900) || (_INTEL_COMPILER >= 300)) && !(MACPORTS_GCC_COMPILER > 0))
|
||||
#define HAVE_GCC_CONSTRUCTOR0 (__GNUC__ && (CRYPTOPP_INIT_PRIORITY > 0) && !(MACPORTS_GCC_COMPILER > 0))
|
||||
|
||||
extern "C" {
|
||||
typedef void (*SigHandler)(int);
|
||||
};
|
||||
|
|
|
|||
23
cpu.h
23
cpu.h
|
|
@ -29,31 +29,30 @@
|
|||
#if (CRYPTOPP_GCC_VERSION >= 40800)
|
||||
# include <x86intrin.h>
|
||||
#endif
|
||||
#if (CRYPTOPP_MSC_VERSION >= 1400)
|
||||
# include <intrin.h>
|
||||
#endif
|
||||
|
||||
// Baseline include
|
||||
#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE || CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE
|
||||
# include <emmintrin.h> // __m64, __m128i, _mm_set_epi64x
|
||||
#endif
|
||||
|
||||
// PUSHFB needs Clang 3.3 and Apple Clang 5.0.
|
||||
// #if (defined(__SSE3__) || defined(__SSSE3__)) || defined(__INTEL_COMPILER) || (CRYPTOPP_LLVM_CLANG_VERSION >= 30300) || (CRYPTOPP_APPLE_CLANG_VERSION >= 50000)
|
||||
#if CRYPTOPP_BOOL_SSSE3_ASM_AVAILABLE
|
||||
# include <tmmintrin.h> // _mm_shuffle_epi16
|
||||
# include <tmmintrin.h> // _mm_shuffle_pi8, _mm_shuffle_epi8
|
||||
#endif // tmmintrin.h
|
||||
|
||||
// PEXTRD needs Clang 3.3 and Apple Clang 5.0.
|
||||
// #if (defined(__SSE4_1__) || defined(__SSE4_1__)) || defined(__INTEL_COMPILER) || (CRYPTOPP_LLVM_CLANG_VERSION >= 30300) || (CRYPTOPP_APPLE_CLANG_VERSION >= 50000)
|
||||
#if CRYPTOPP_BOOL_SSE4_INTRINSICS_AVAILABLE
|
||||
# include <smmintrin.h> // _mm_blend_epi16
|
||||
# include <nmmintrin.h> // _mm_crc32_u{8|16|32}
|
||||
#endif // smmintrin.h
|
||||
|
||||
// AES and CLMUL need Clang 2.8 and Apple Clang 4.6. CLMUL needs Clang 3.4 and Apple Clang 6.0
|
||||
// #if (defined(__AES__) || defined(__PCLMUL__)) || defined(__INTEL_COMPILER) || (CRYPTOPP_LLVM_CLANG_VERSION >= 30400) || (CRYPTOPP_APPLE_CLANG_VERSION >= 60000)
|
||||
#if CRYPTOPP_BOOL_AESNI_INTRINSICS_AVAILABLE
|
||||
# include <wmmintrin.h>
|
||||
# include <wmmintrin.h> // aesenc, aesdec, etc
|
||||
#endif // wmmintrin.h
|
||||
|
||||
#if CRYPTOPP_BOOL_AVX_INTRINSICS_AVAILABLE
|
||||
# include <immintrin.h> // RDRAND, RDSEED and AVX
|
||||
#endif
|
||||
#if CRYPTOPP_BOOL_AVX2_INTRINSICS_AVAILABLE
|
||||
# include <zmmintrin.h> // AVX 512-bit extensions
|
||||
#endif
|
||||
#endif // X86/X64/X32 Headers
|
||||
|
||||
// Applies to both X86/X32/X64 and ARM32/ARM64. And we've got MIPS devices on the way.
|
||||
|
|
|
|||
|
|
@ -906,4 +906,4 @@ IF %ERRORLEVEL% EQU 0 (echo mac done > "$(OutDir)"\cryptopp.mac.done)
|
|||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -673,4 +673,4 @@ echo unless it undergoes FIPS validation.
|
|||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -32,10 +32,6 @@
|
|||
# error Cygwin does not support Windows style sockets. See http://www.cygwin.com/faq.html#faq.api.winsock
|
||||
#endif
|
||||
|
||||
// MacPorts/GCC does not provide init_priority(priority). Apple/GCC and Fink/GCC do provide it.
|
||||
#define HAVE_GCC_INIT_PRIORITY (__GNUC__ && (CRYPTOPP_INIT_PRIORITY > 0) && !(MACPORTS_GCC_COMPILER > 0))
|
||||
#define HAVE_MSC_INIT_PRIORITY (_MSC_VER && (CRYPTOPP_INIT_PRIORITY > 0))
|
||||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
|
||||
CRYPTOPP_COMPILE_ASSERT(sizeof(byte) == 1);
|
||||
|
|
|
|||
|
|
@ -723,4 +723,4 @@ echo: >> adhoc.cpp.copied
|
|||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -204,4 +204,4 @@
|
|||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
|
|||
22
keccak.h
22
keccak.h
|
|
@ -56,6 +56,8 @@ public:
|
|||
void Restart();
|
||||
void TruncatedFinal(byte *hash, size_t size);
|
||||
|
||||
//unsigned int BlockSize() const { return r(); } // that's the idea behind it
|
||||
|
||||
protected:
|
||||
inline unsigned int r() const {return 200 - 2 * m_digestSize;}
|
||||
|
||||
|
|
@ -70,10 +72,15 @@ class Keccak_224 : public Keccak
|
|||
{
|
||||
public:
|
||||
CRYPTOPP_CONSTANT(DIGESTSIZE = 28)
|
||||
CRYPTOPP_CONSTANT(BLOCKSIZE = 200 - 2 * DIGESTSIZE)
|
||||
|
||||
//! \brief Construct a Keccak-224 message digest
|
||||
Keccak_224() : Keccak(DIGESTSIZE) {}
|
||||
CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Keccak-224";}
|
||||
unsigned int BlockSize() const { return BLOCKSIZE; }
|
||||
private:
|
||||
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math
|
||||
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > DIGESTSIZE); // this is a general expectation by HMAC
|
||||
};
|
||||
|
||||
//! \class Keccak_256
|
||||
|
|
@ -83,10 +90,15 @@ class Keccak_256 : public Keccak
|
|||
{
|
||||
public:
|
||||
CRYPTOPP_CONSTANT(DIGESTSIZE = 32)
|
||||
CRYPTOPP_CONSTANT(BLOCKSIZE = 200 - 2 * DIGESTSIZE)
|
||||
|
||||
//! \brief Construct a Keccak-256 message digest
|
||||
Keccak_256() : Keccak(DIGESTSIZE) {}
|
||||
CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Keccak-256";}
|
||||
unsigned int BlockSize() const { return BLOCKSIZE; }
|
||||
private:
|
||||
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math
|
||||
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > DIGESTSIZE); // this is a general expectation by HMAC
|
||||
};
|
||||
|
||||
//! \class Keccak_384
|
||||
|
|
@ -96,10 +108,15 @@ class Keccak_384 : public Keccak
|
|||
{
|
||||
public:
|
||||
CRYPTOPP_CONSTANT(DIGESTSIZE = 48)
|
||||
CRYPTOPP_CONSTANT(BLOCKSIZE = 200 - 2 * DIGESTSIZE)
|
||||
|
||||
//! \brief Construct a Keccak-384 message digest
|
||||
Keccak_384() : Keccak(DIGESTSIZE) {}
|
||||
CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Keccak-384";}
|
||||
unsigned int BlockSize() const { return BLOCKSIZE; }
|
||||
private:
|
||||
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math
|
||||
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > DIGESTSIZE); // this is a general expectation by HMAC
|
||||
};
|
||||
|
||||
//! \class Keccak_512
|
||||
|
|
@ -109,10 +126,15 @@ class Keccak_512 : public Keccak
|
|||
{
|
||||
public:
|
||||
CRYPTOPP_CONSTANT(DIGESTSIZE = 64)
|
||||
CRYPTOPP_CONSTANT(BLOCKSIZE = 200 - 2 * DIGESTSIZE)
|
||||
|
||||
//! \brief Construct a Keccak-512 message digest
|
||||
Keccak_512() : Keccak(DIGESTSIZE) {}
|
||||
CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "Keccak-512";}
|
||||
unsigned int BlockSize() const { return BLOCKSIZE; }
|
||||
private:
|
||||
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math
|
||||
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > DIGESTSIZE); // this is a general expectation by HMAC
|
||||
};
|
||||
|
||||
NAMESPACE_END
|
||||
|
|
|
|||
34
misc.h
34
misc.h
|
|
@ -1194,17 +1194,17 @@ inline void SecureWipeArray(T *buf, size_t n)
|
|||
}
|
||||
|
||||
//! \brief Converts a wide character C-string to a multibyte string
|
||||
//! \param str C-string consiting of wide characters
|
||||
//! \param throwOnError specifies the function should throw an InvalidArgument exception on error
|
||||
//! \param str C-string consisting of wide characters
|
||||
//! \param throwOnError flag indication the function should throw on error
|
||||
//! \returns str converted to a multibyte string or an empty string.
|
||||
//! \details StringNarrow converts a wide string to a narrow string using C++ std::wcstombs under the executing
|
||||
//! thread's locale. A locale must be set before using this function, and it can be set with std::setlocale.
|
||||
//! Upon success, the converted string is returned.
|
||||
//! \details Upon failure with throwOnError as false, the function returns an empty string. Upon failure with
|
||||
//! throwOnError as true, the function throws InvalidArgument exception.
|
||||
//! \details StringNarrow converts a wide string to a narrow string using C++ std::wcstombs() under
|
||||
//! the executing thread's locale. A locale must be set before using this function, and it can be
|
||||
//! set with std::setlocale() if needed. Upon success, the converted string is returned.
|
||||
//! \details Upon failure with throwOnError as false, the function returns an empty string. If
|
||||
//! throwOnError as true, the function throws an InvalidArgument() exception.
|
||||
//! \note If you try to convert, say, the Chinese character for "bone" from UTF-16 (0x9AA8) to UTF-8
|
||||
//! (0xE9 0xAA 0xA8), then you must ensure the locale is available. If the locale is not available,
|
||||
//! then a 0x21 error is returned on Windows which eventually results in an InvalidArgument exception.
|
||||
//! then a 0x21 error is returned on Windows which eventually results in an InvalidArgument() exception.
|
||||
#ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
|
||||
std::string StringNarrow(const wchar_t *str, bool throwOnError = true);
|
||||
#else
|
||||
|
|
@ -1269,10 +1269,10 @@ CONVERSION_ERROR:
|
|||
|
||||
//! \brief Allocates a buffer on 16-byte boundary
|
||||
//! \param size the size of the buffer
|
||||
//! \details AlignedAllocate is primarily used when the data will be proccessed by MMX and SSE2
|
||||
//! \details AlignedAllocate is primarily used when the data will be proccessed by MMX, SSE2 and NEON
|
||||
//! instructions. The assembly language routines rely on the alignment. If the alignment is not
|
||||
//! respected, then a SIGBUS is generated under Unix and an EXCEPTION_DATATYPE_MISALIGNMENT
|
||||
//! is generated under Windows.
|
||||
//! respected, then a SIGBUS could be generated on Unix and Linux, and an
|
||||
//! EXCEPTION_DATATYPE_MISALIGNMENT could be generated on Windows.
|
||||
//! \note AlignedAllocate and AlignedDeallocate are available when CRYPTOPP_BOOL_ALIGN16 is
|
||||
//! defined. CRYPTOPP_BOOL_ALIGN16 is defined in config.h
|
||||
CRYPTOPP_DLL void* CRYPTOPP_API AlignedAllocate(size_t size);
|
||||
|
|
@ -1304,7 +1304,7 @@ CRYPTOPP_DLL void CRYPTOPP_API UnalignedDeallocate(void *ptr);
|
|||
//! \tparam T the word type
|
||||
//! \param x the value to rotate
|
||||
//! \param y the number of bit positions to rotate the value
|
||||
//! \details This is a portable C/C++ implementation. The value x to be rotated can be 8 to 64-bits.
|
||||
//! \details This is a portable C/C++ implementation. The value x to be rotated can be 8 to 64-bits wide.
|
||||
//! \details y must be in the range <tt>[0, sizeof(T)*8 - 1]</tt> to avoid undefined behavior.
|
||||
//! Use rotlMod if the rotate amount y is outside the range.
|
||||
//! \note rotlFixed attempts to enlist a <tt>rotate IMM</tt> instruction because its often faster
|
||||
|
|
@ -1326,7 +1326,7 @@ template <class T> inline T rotlFixed(T x, unsigned int y)
|
|||
//! \tparam T the word type
|
||||
//! \param x the value to rotate
|
||||
//! \param y the number of bit positions to rotate the value
|
||||
//! \details This is a portable C/C++ implementation. The value x to be rotated can be 8 to 64-bits.
|
||||
//! \details This is a portable C/C++ implementation. The value x to be rotated can be 8 to 64-bits wide.
|
||||
//! \details y must be in the range <tt>[0, sizeof(T)*8 - 1]</tt> to avoid undefined behavior.
|
||||
//! Use rotrMod if the rotate amount y is outside the range.
|
||||
//! \note rotrFixed attempts to enlist a <tt>rotate IMM</tt> instruction because its often faster
|
||||
|
|
@ -1348,7 +1348,7 @@ template <class T> inline T rotrFixed(T x, unsigned int y)
|
|||
//! \tparam T the word type
|
||||
//! \param x the value to rotate
|
||||
//! \param y the number of bit positions to rotate the value
|
||||
//! \details This is a portable C/C++ implementation. The value x to be rotated can be 8 to 64-bits.
|
||||
//! \details This is a portable C/C++ implementation. The value x to be rotated can be 8 to 64-bits wide.
|
||||
//! \details y must be in the range <tt>[0, sizeof(T)*8 - 1]</tt> to avoid undefined behavior.
|
||||
//! Use rotlMod if the rotate amount y is outside the range.
|
||||
//! \note rotlVariable attempts to enlist a <tt>rotate IMM</tt> instruction because its often faster
|
||||
|
|
@ -1366,7 +1366,7 @@ template <class T> inline T rotlVariable(T x, unsigned int y)
|
|||
//! \tparam T the word type
|
||||
//! \param x the value to rotate
|
||||
//! \param y the number of bit positions to rotate the value
|
||||
//! \details This is a portable C/C++ implementation. The value x to be rotated can be 8 to 64-bits.
|
||||
//! \details This is a portable C/C++ implementation. The value x to be rotated can be 8 to 64-bits wide.
|
||||
//! \details y must be in the range <tt>[0, sizeof(T)*8 - 1]</tt> to avoid undefined behavior.
|
||||
//! Use rotrMod if the rotate amount y is outside the range.
|
||||
//! \note rotrVariable attempts to enlist a <tt>rotate IMM</tt> instruction because its often faster
|
||||
|
|
@ -1384,7 +1384,7 @@ template <class T> inline T rotrVariable(T x, unsigned int y)
|
|||
//! \tparam T the word type
|
||||
//! \param x the value to rotate
|
||||
//! \param y the number of bit positions to rotate the value
|
||||
//! \details This is a portable C/C++ implementation. The value x to be rotated can be 8 to 64-bits.
|
||||
//! \details This is a portable C/C++ implementation. The value x to be rotated can be 8 to 64-bits wide.
|
||||
//! \details y is reduced to the range <tt>[0, sizeof(T)*8 - 1]</tt> to avoid undefined behavior.
|
||||
//! \note rotrVariable will use either <tt>rotate IMM</tt> or <tt>rotate REG</tt>.
|
||||
template <class T> inline T rotlMod(T x, unsigned int y)
|
||||
|
|
@ -1398,7 +1398,7 @@ template <class T> inline T rotlMod(T x, unsigned int y)
|
|||
//! \tparam T the word type
|
||||
//! \param x the value to rotate
|
||||
//! \param y the number of bit positions to rotate the value
|
||||
//! \details This is a portable C/C++ implementation. The value x to be rotated can be 8 to 64-bits.
|
||||
//! \details This is a portable C/C++ implementation. The value x to be rotated can be 8 to 64-bits wide.
|
||||
//! \details y is reduced to the range <tt>[0, sizeof(T)*8 - 1]</tt> to avoid undefined behavior.
|
||||
//! \note rotrVariable will use either <tt>rotate IMM</tt> or <tt>rotate REG</tt>.
|
||||
template <class T> inline T rotrMod(T x, unsigned int y)
|
||||
|
|
|
|||
19
ossig.h
19
ossig.h
|
|
@ -20,11 +20,22 @@ NAMESPACE_BEGIN(CryptoPP)
|
|||
#if defined(CRYPTOPP_BSD_AVAILABLE) || defined(CRYPTOPP_UNIX_AVAILABLE) || defined(CRYPTOPP_DOXYGEN_PROCESSING)
|
||||
|
||||
//! \brief Signal handler function pointer
|
||||
//! \sa SignalHandler
|
||||
//! \details SignalHandlerFn is provided as a stand alone function pointer with external "C" linkage
|
||||
//! \sa SignalHandler, NullSignalHandler
|
||||
extern "C" {
|
||||
typedef void (*SignalHandlerFn) (int);
|
||||
};
|
||||
|
||||
//! \brief Null signal handler function
|
||||
//! \param unused the signal number
|
||||
//! \details NullSignalHandler is provided as a stand alone function with external "C" linkage
|
||||
//! and not a static member function due to the the member function's implicit
|
||||
//! external "C++" linkage.
|
||||
//! \sa SignalHandler, SignalHandlerFn
|
||||
extern "C" {
|
||||
inline void NullSignalHandler(int unused) {CRYPTOPP_UNUSED(unused);}
|
||||
};
|
||||
|
||||
//! Signal handler for Linux and Unix compatibles
|
||||
//! \tparam S Signal number
|
||||
//! \tparam O Flag indicating exsting handler should be overwriiten
|
||||
|
|
@ -38,7 +49,7 @@ extern "C" {
|
|||
//! \warning Do not use SignalHandler in a code block that uses <tt>setjmp</tt> or <tt>longjmp</tt>
|
||||
//! because the destructor may not run.
|
||||
//! \since Crypto++ 5.6.5
|
||||
//! \sa SignalHandlerFn, \ref CRYPTOPP_ASSERT "CRYPTOPP_ASSERT", DebugTrapHandler
|
||||
//! \sa NullSignalHandler, SignalHandlerFn, \ref CRYPTOPP_ASSERT "CRYPTOPP_ASSERT", DebugTrapHandler
|
||||
template <int S, bool O=false>
|
||||
struct SignalHandler
|
||||
{
|
||||
|
|
@ -72,7 +83,7 @@ struct SignalHandler
|
|||
if (m_old.sa_handler != 0 && !O) break;
|
||||
|
||||
// Sun Studio 12.2-12.4 needs the two casts, and they must be C-style casts
|
||||
new_handler.sa_handler = (SignalHandlerFn)(pfn ? pfn : (SignalHandlerFn)&SignalHandler::NullHandler);
|
||||
new_handler.sa_handler = (pfn ? pfn : &NullSignalHandler);
|
||||
new_handler.sa_flags = (pfn ? flags : 0);
|
||||
|
||||
ret = sigemptyset (&new_handler.sa_mask);
|
||||
|
|
@ -97,8 +108,6 @@ private:
|
|||
struct sigaction m_old;
|
||||
bool m_installed;
|
||||
|
||||
static void NullHandler(int /*unused*/) { /* continue*/ }
|
||||
|
||||
private:
|
||||
// Not copyable
|
||||
SignalHandler(const SignalHandler &);
|
||||
|
|
|
|||
21
sha3.h
21
sha3.h
|
|
@ -42,6 +42,7 @@ public:
|
|||
void Restart();
|
||||
void TruncatedFinal(byte *hash, size_t size);
|
||||
|
||||
// unsigned int BlockSize() const { return r(); } // that's the idea behind it
|
||||
protected:
|
||||
inline unsigned int r() const {return 200 - 2 * m_digestSize;}
|
||||
|
||||
|
|
@ -56,10 +57,15 @@ class SHA3_224 : public SHA3
|
|||
{
|
||||
public:
|
||||
CRYPTOPP_CONSTANT(DIGESTSIZE = 28)
|
||||
CRYPTOPP_CONSTANT(BLOCKSIZE = 200 - 2 * DIGESTSIZE)
|
||||
|
||||
//! \brief Construct a SHA3-224 message digest
|
||||
SHA3_224() : SHA3(DIGESTSIZE) {}
|
||||
CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SHA3-224";}
|
||||
unsigned int BlockSize() const { return BLOCKSIZE; }
|
||||
private:
|
||||
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math
|
||||
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > DIGESTSIZE); // this is a general expectation by HMAC
|
||||
};
|
||||
|
||||
//! \class SHA3_256
|
||||
|
|
@ -69,10 +75,15 @@ class SHA3_256 : public SHA3
|
|||
{
|
||||
public:
|
||||
CRYPTOPP_CONSTANT(DIGESTSIZE = 32)
|
||||
CRYPTOPP_CONSTANT(BLOCKSIZE = 200 - 2 * DIGESTSIZE)
|
||||
|
||||
//! \brief Construct a SHA3-256 message digest
|
||||
SHA3_256() : SHA3(DIGESTSIZE) {}
|
||||
CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SHA3-256";}
|
||||
unsigned int BlockSize() const { return BLOCKSIZE; }
|
||||
private:
|
||||
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math
|
||||
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > DIGESTSIZE); // this is a general expectation by HMAC
|
||||
};
|
||||
|
||||
//! \class SHA3_384
|
||||
|
|
@ -82,10 +93,15 @@ class SHA3_384 : public SHA3
|
|||
{
|
||||
public:
|
||||
CRYPTOPP_CONSTANT(DIGESTSIZE = 48)
|
||||
CRYPTOPP_CONSTANT(BLOCKSIZE = 200 - 2 * DIGESTSIZE)
|
||||
|
||||
//! \brief Construct a SHA3-384 message digest
|
||||
SHA3_384() : SHA3(DIGESTSIZE) {}
|
||||
CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SHA3-384";}
|
||||
unsigned int BlockSize() const { return BLOCKSIZE; }
|
||||
private:
|
||||
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math
|
||||
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > DIGESTSIZE); // this is a general expectation by HMAC
|
||||
};
|
||||
|
||||
//! \class SHA3_512
|
||||
|
|
@ -95,10 +111,15 @@ class SHA3_512 : public SHA3
|
|||
{
|
||||
public:
|
||||
CRYPTOPP_CONSTANT(DIGESTSIZE = 64)
|
||||
CRYPTOPP_CONSTANT(BLOCKSIZE = 200 - 2 * DIGESTSIZE)
|
||||
|
||||
//! \brief Construct a SHA3-512 message digest
|
||||
SHA3_512() : SHA3(DIGESTSIZE) {}
|
||||
CRYPTOPP_CONSTEXPR static const char *StaticAlgorithmName() {return "SHA3-512";}
|
||||
unsigned int BlockSize() const { return BLOCKSIZE; }
|
||||
private:
|
||||
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200); // ensure there was no underflow in the math
|
||||
CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE > DIGESTSIZE); // this is a general expectation by HMAC
|
||||
};
|
||||
|
||||
NAMESPACE_END
|
||||
|
|
|
|||
Loading…
Reference in New Issue