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 diff --git a/misc.h b/misc.h index e3980441..71e1cb51 100644 --- a/misc.h +++ b/misc.h @@ -425,6 +425,21 @@ inline void memmove_s(void *dest, size_t sizeInBytes, const void *src, size_t co #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. +//! \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; +} + //! \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 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