From 5ad7bbd0c78d06b66b43503c6f173299a8d5fd47 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Sun, 17 Jul 2016 20:20:36 -0400 Subject: [PATCH 1/3] Guard CRYPTOPP_CXX11 for STLport On Android, the compiler will define __cplusplus=201103L when using -std=c++11 even with STLport. STLport appears to be abandoned sometime around 2008. --- config.h | 4 +++- config.recommend | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/config.h b/config.h index 098fe39b..6059777d 100644 --- a/config.h +++ b/config.h @@ -405,6 +405,8 @@ NAMESPACE_END # pragma GCC diagnostic ignored "-Wunused-function" #endif +// You may need to force include a C++ header on Android when using STLPort to ensure +// _STLPORT_VERSION is defined: CXXFLAGS="-DNDEBUG -g2 -O2 -std=c++11 -include iosfwd" // TODO: Figure out C++17 and lack of std::uncaught_exception #if (defined(_MSC_VER) && _MSC_VER <= 1300) || defined(__MWERKS__) || (defined(_STLPORT_VERSION) && ((_STLPORT_VERSION < 0x450) || defined(_STLP_NO_UNCAUGHT_EXCEPT_SUPPORT))) #define CRYPTOPP_DISABLE_UNCAUGHT_EXCEPTION @@ -756,7 +758,7 @@ NAMESPACE_END // Intel and C++11 language features, http://software.intel.com/en-us/articles/c0x-features-supported-by-intel-c-compiler // GCC and C++11 language features, http://gcc.gnu.org/projects/cxx0x.html // Clang and C++11 language features, http://clang.llvm.org/cxx_status.html -#if (_MSC_VER >= 1600) || (__cplusplus >= 201103L) +#if ((_MSC_VER >= 1600) || (__cplusplus >= 201103L)) && !defined(_STLPORT_VERSION) # define CRYPTOPP_CXX11 1 #endif diff --git a/config.recommend b/config.recommend index 8c67202e..1ff4e7ea 100644 --- a/config.recommend +++ b/config.recommend @@ -756,7 +756,7 @@ NAMESPACE_END // Intel and C++11 language features, http://software.intel.com/en-us/articles/c0x-features-supported-by-intel-c-compiler // GCC and C++11 language features, http://gcc.gnu.org/projects/cxx0x.html // Clang and C++11 language features, http://clang.llvm.org/cxx_status.html -#if (_MSC_VER >= 1600) || (__cplusplus >= 201103L) +#if ((_MSC_VER >= 1600) || (__cplusplus >= 201103L)) && !defined(_STLPORT_VERSION) # define CRYPTOPP_CXX11 1 #endif From 4fd51eb06c903045db80253b95e2b6348ae2aaad Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Sun, 17 Jul 2016 21:25:55 -0400 Subject: [PATCH 2/3] Add vec_swap for compilers which do not support std::swap'ing SSE and NEON types --- misc.h | 13 +++++++++++++ rijndael.cpp | 6 ++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/misc.h b/misc.h index e3980441..f846e72a 100644 --- a/misc.h +++ b/misc.h @@ -423,6 +423,19 @@ inline void memmove_s(void *dest, size_t sizeInBytes, const void *src, size_t co # define memmove_s CryptoPP::memmove_s #endif +//! \brief Swaps two variables which are arrays +//! \details C++03 does not provide support for std::swap(__m128i a, __m128i b) +//! because __m128i is an unsigned long long[2]. Most compilers +//! support it out of the box, but Sun Studio C++ compilers 12.2 and 12.3 do not. +//! \sa How to swap two __m128i variables +//! in C++03 given its an opaque type and an array? on Stack Overflow. +template +inline void vec_swap(T& a, T& b) +{ + T t; + t=a, a=b, b=t; +} + #endif // __STDC_WANT_SECURE_LIB__ //! \brief Memory block initializer and eraser that attempts to survive optimizations diff --git a/rijndael.cpp b/rijndael.cpp index 9139c227..05ba5d57 100644 --- a/rijndael.cpp +++ b/rijndael.cpp @@ -275,11 +275,9 @@ void Rijndael::Base::UncheckedSetKey(const byte *userKey, unsigned int keylen, c unsigned int i, j; #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x5120) - // __m128i is an unsigned long long[2], and support for swapping it was not formally added until C++11. + // __m128i is an unsigned long long[2], and support for swapping it was not added until C++11. // SunCC 12.1 - 12.3 fail to consume the swap; while SunCC 12.4 consumes it without -std=c++11. - __m128i t = *(__m128i *)(rk); - *(__m128i *)(rk) = *(__m128i *)(rk+4*m_rounds); - *(__m128i *)(rk+4*m_rounds) = t; + vec_swap(*(__m128i *)(rk), *(__m128i *)(rk+4*m_rounds)); #else std::swap(*(__m128i *)(void *)(rk), *(__m128i *)(void *)(rk+4*m_rounds)); #endif From 9154975b1a54927189d4e0614b3d357ea65157c8 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Sun, 17 Jul 2016 22:16:30 -0400 Subject: [PATCH 3/3] Updated documentation --- misc.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/misc.h b/misc.h index f846e72a..71e1cb51 100644 --- a/misc.h +++ b/misc.h @@ -423,7 +423,11 @@ inline void memmove_s(void *dest, size_t sizeInBytes, const void *src, size_t co # define memmove_s CryptoPP::memmove_s #endif +#endif // __STDC_WANT_SECURE_LIB__ + //! \brief Swaps two variables which are arrays +//! \param a the first value +//! \param b the second value //! \details C++03 does not provide support for std::swap(__m128i a, __m128i b) //! because __m128i is an unsigned long long[2]. Most compilers //! support it out of the box, but Sun Studio C++ compilers 12.2 and 12.3 do not. @@ -436,8 +440,6 @@ inline void vec_swap(T& a, T& b) t=a, a=b, b=t; } -#endif // __STDC_WANT_SECURE_LIB__ - //! \brief Memory block initializer and eraser that attempts to survive optimizations //! \param ptr pointer to the memory block being written //! \param value the integer value to write for each byte