Make AlignedAllocate available in simulator debug builds (GH #779, PR #780)

* Make AlignedAllocate available in simulator debug builds (GH #779)

* Use CRYPTOPP_CONSTANT for rotate params
pull/784/head
Jeffrey Walton 2019-01-11 16:37:26 -05:00 committed by GitHub
parent 22a25c0e84
commit fdfcb2a172
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 36 deletions

View File

@ -280,8 +280,6 @@ void CallNewHandler()
throw std::bad_alloc();
}
#if CRYPTOPP_BOOL_ALIGN16
void * AlignedAllocate(size_t size)
{
byte *p;
@ -320,8 +318,6 @@ void AlignedDeallocate(void *p)
#endif
}
#endif // CRYPTOPP_BOOL_ALIGN16
void * UnalignedAllocate(size_t size)
{
void *p;

72
misc.h
View File

@ -632,7 +632,7 @@ template <class T>
std::string IntToString(T value, unsigned int base = 10)
{
// Hack... set the high bit for uppercase.
static const unsigned int HIGH_BIT = (1U << 31);
const unsigned int HIGH_BIT = (1U << 31);
const char CH = !!(base & HIGH_BIT) ? 'A' : 'a';
base &= ~HIGH_BIT;
@ -1156,6 +1156,7 @@ inline CipherDir GetCipherDir(const T &obj)
/// to free memory. There is no guarantee CallNewHandler will be able to procure more memory so
/// an allocation succeeds. If the call to set_new_handler fails, then CallNewHandler throws
/// a bad_alloc exception.
/// \sa AlignedAllocate, AlignedDeallocate, UnalignedAllocate, UnalignedDeallocate
CRYPTOPP_DLL void CRYPTOPP_API CallNewHandler();
/// \brief Performs an addition with carry on a block of bytes
@ -1380,37 +1381,44 @@ std::string StringNarrow(const wchar_t *str, bool throwOnError = true);
/// then a 0x21 error is returned on Windows which eventually results in an InvalidArgument() exception.
std::wstring StringWiden(const char *str, bool throwOnError = true);
#ifdef CRYPTOPP_DOXYGEN_PROCESSING
/// \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, SSE2 and NEON
/// instructions. The assembly language routines rely on the alignment. If the alignment is not
/// \details AlignedAllocate is primarily used when the data will be
/// proccessed by SSE, NEON, ARMv8 or PowerPC instructions. The assembly
/// language routines rely on the alignment. If the alignment is not
/// 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
/// \details Formerly, AlignedAllocate and AlignedDeallocate were only
/// available on certain platforms when CRYTPOPP_DISABLE_ASM was not in
/// effect. However, Android and iOS debug simulator builds got into a
/// state where the aligned allocator was not available and caused link
/// failures.
/// \since AlignedAllocate for SIMD since Crypto++ 1.0, AlignedAllocate
/// for all builds since Crypto++ 8.1
/// \sa AlignedDeallocate, UnalignedAllocate, UnalignedDeallocate, CallNewHandler,
/// <A HREF="http://github.com/weidai11/cryptopp/issues/779">Issue 779</A>
CRYPTOPP_DLL void* CRYPTOPP_API AlignedAllocate(size_t size);
/// \brief Frees a buffer allocated with AlignedAllocate
/// \param ptr the buffer to free
/// \note AlignedAllocate and AlignedDeallocate are available when CRYPTOPP_BOOL_ALIGN16 is
/// defined. CRYPTOPP_BOOL_ALIGN16 is defined in config.h
/// \since AlignedDeallocate for SIMD since Crypto++ 1.0, AlignedAllocate
/// for all builds since Crypto++ 8.1
/// \sa AlignedAllocate, UnalignedAllocate, UnalignedDeallocate, CallNewHandler,
/// <A HREF="http://github.com/weidai11/cryptopp/issues/779">Issue 779</A>
CRYPTOPP_DLL void CRYPTOPP_API AlignedDeallocate(void *ptr);
#endif // CRYPTOPP_DOXYGEN_PROCESSING
#if CRYPTOPP_BOOL_ALIGN16
CRYPTOPP_DLL void* CRYPTOPP_API AlignedAllocate(size_t size);
CRYPTOPP_DLL void CRYPTOPP_API AlignedDeallocate(void *ptr);
#endif // CRYPTOPP_BOOL_ALIGN16
/// \brief Allocates a buffer
/// \param size the size of the buffer
/// \since Crypto++ 1.0
/// \sa AlignedAllocate, AlignedDeallocate, UnalignedDeallocate, CallNewHandler,
/// <A HREF="http://github.com/weidai11/cryptopp/issues/779">Issue 779</A>
CRYPTOPP_DLL void * CRYPTOPP_API UnalignedAllocate(size_t size);
/// \brief Frees a buffer allocated with UnalignedAllocate
/// \param ptr the buffer to free
/// \since Crypto++ 1.0
/// \sa AlignedAllocate, AlignedDeallocate, UnalignedAllocate, CallNewHandler,
/// <A HREF="http://github.com/weidai11/cryptopp/issues/779">Issue 779</A>
CRYPTOPP_DLL void CRYPTOPP_API UnalignedDeallocate(void *ptr);
// ************** rotate functions ***************
@ -1436,8 +1444,8 @@ template <unsigned int R, class T> inline T rotlConstant(T x)
// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57157,
// http://software.intel.com/en-us/forums/topic/580884
// and http://llvm.org/bugs/show_bug.cgi?id=24226
static const unsigned int THIS_SIZE = sizeof(T)*8;
static const unsigned int MASK = THIS_SIZE-1;
CRYPTOPP_CONSTANT(THIS_SIZE = sizeof(T)*8)
CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1)
CRYPTOPP_ASSERT(R < THIS_SIZE);
return T((x<<R)|(x>>(-R&MASK)));
}
@ -1462,8 +1470,8 @@ template <unsigned int R, class T> inline T rotrConstant(T x)
// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57157,
// http://software.intel.com/en-us/forums/topic/580884
// and http://llvm.org/bugs/show_bug.cgi?id=24226
static const unsigned int THIS_SIZE = sizeof(T)*8;
static const unsigned int MASK = THIS_SIZE-1;
CRYPTOPP_CONSTANT(THIS_SIZE = sizeof(T)*8)
CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1)
CRYPTOPP_ASSERT(R < THIS_SIZE);
return T((x >> R)|(x<<(-R&MASK)));
}
@ -1487,8 +1495,8 @@ template <class T> inline T rotlFixed(T x, unsigned int y)
// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57157,
// http://software.intel.com/en-us/forums/topic/580884
// and http://llvm.org/bugs/show_bug.cgi?id=24226
static const unsigned int THIS_SIZE = sizeof(T)*8;
static const unsigned int MASK = THIS_SIZE-1;
CRYPTOPP_CONSTANT(THIS_SIZE = sizeof(T)*8)
CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1)
CRYPTOPP_ASSERT(y < THIS_SIZE);
return T((x<<y)|(x>>(-y&MASK)));
}
@ -1512,8 +1520,8 @@ template <class T> inline T rotrFixed(T x, unsigned int y)
// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57157,
// http://software.intel.com/en-us/forums/topic/580884
// and http://llvm.org/bugs/show_bug.cgi?id=24226
static const unsigned int THIS_SIZE = sizeof(T)*8;
static const unsigned int MASK = THIS_SIZE-1;
CRYPTOPP_CONSTANT(THIS_SIZE = sizeof(T)*8)
CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1)
CRYPTOPP_ASSERT(y < THIS_SIZE);
return T((x >> y)|(x<<(-y&MASK)));
}
@ -1532,8 +1540,8 @@ template <class T> inline T rotrFixed(T x, unsigned int y)
/// \since Crypto++ 3.0
template <class T> inline T rotlVariable(T x, unsigned int y)
{
static const unsigned int THIS_SIZE = sizeof(T)*8;
static const unsigned int MASK = THIS_SIZE-1;
CRYPTOPP_CONSTANT(THIS_SIZE = sizeof(T)*8)
CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1)
CRYPTOPP_ASSERT(y < THIS_SIZE);
return T((x<<y)|(x>>(-y&MASK)));
}
@ -1552,8 +1560,8 @@ template <class T> inline T rotlVariable(T x, unsigned int y)
/// \since Crypto++ 3.0
template <class T> inline T rotrVariable(T x, unsigned int y)
{
static const unsigned int THIS_SIZE = sizeof(T)*8;
static const unsigned int MASK = THIS_SIZE-1;
CRYPTOPP_CONSTANT(THIS_SIZE = sizeof(T)*8)
CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1)
CRYPTOPP_ASSERT(y < THIS_SIZE);
return T((x>>y)|(x<<(-y&MASK)));
}
@ -1569,8 +1577,8 @@ template <class T> inline T rotrVariable(T x, unsigned int y)
/// \since Crypto++ 3.0
template <class T> inline T rotlMod(T x, unsigned int y)
{
static const unsigned int THIS_SIZE = sizeof(T)*8;
static const unsigned int MASK = THIS_SIZE-1;
CRYPTOPP_CONSTANT(THIS_SIZE = sizeof(T)*8)
CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1)
return T((x<<(y&MASK))|(x>>(-y&MASK)));
}
@ -1585,8 +1593,8 @@ template <class T> inline T rotlMod(T x, unsigned int y)
/// \since Crypto++ 3.0
template <class T> inline T rotrMod(T x, unsigned int y)
{
static const unsigned int THIS_SIZE = sizeof(T)*8;
static const unsigned int MASK = THIS_SIZE-1;
CRYPTOPP_CONSTANT(THIS_SIZE = sizeof(T)*8)
CRYPTOPP_CONSTANT(MASK = THIS_SIZE-1)
return T((x>>(y&MASK))|(x<<(-y&MASK)));
}