Prefix IS_LITTLE_ENDIAN and IS_BIG_ENDIAN with CRYPTOPP

pull/548/head
Jeffrey Walton 2017-11-10 14:15:30 -05:00
parent 8e06391ad3
commit 69c8a4f9c6
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
14 changed files with 43 additions and 43 deletions

View File

@ -269,7 +269,7 @@ void ARIA::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, b
ARIA_KXL; rk+= 16; ARIA_FO; ARIA_KXL; rk+= 16; ARIA_FE;
ARIA_KXL; rk+= 16; ARIA_FO; ARIA_KXL; rk+= 16;
#ifdef IS_LITTLE_ENDIAN
#ifdef CRYPTOPP_LITTLE_ENDIAN
# if CRYPTOPP_ENABLE_ARIA_SSSE3_INTRINSICS
if (HasSSSE3())
{

View File

@ -60,7 +60,7 @@ NAMESPACE_BEGIN(CryptoPP)
ROUND(lh, ll, rh, rl, k0, k1) \
ROUND(rh, rl, lh, ll, k2, k3)
#ifdef IS_LITTLE_ENDIAN
#ifdef CRYPTOPP_LITTLE_ENDIAN
#define EFI(i) (1-(i))
#else
#define EFI(i) (i)

View File

@ -9,23 +9,23 @@
// ***************** Important Settings ********************
// define this if running on a big-endian CPU
#if !defined(IS_LITTLE_ENDIAN) && !defined(IS_BIG_ENDIAN) && (defined(__BIG_ENDIAN__) || (defined(__s390__) || defined(__s390x__) || defined(__zarch__)) || (defined(__m68k__) || defined(__MC68K__)) || defined(__sparc) || defined(__sparc__) || defined(__hppa__) || defined(__MIPSEB__) || defined(__ARMEB__) || (defined(__MWERKS__) && !defined(__INTEL__)))
# define IS_BIG_ENDIAN 1
#if !defined(CRYPTOPP_LITTLE_ENDIAN) && !defined(CRYPTOPP_BIG_ENDIAN) && (defined(__BIG_ENDIAN__) || (defined(__s390__) || defined(__s390x__) || defined(__zarch__)) || (defined(__m68k__) || defined(__MC68K__)) || defined(__sparc) || defined(__sparc__) || defined(__hppa__) || defined(__MIPSEB__) || defined(__ARMEB__) || (defined(__MWERKS__) && !defined(__INTEL__)))
# define CRYPTOPP_BIG_ENDIAN 1
#endif
// define this if running on a little-endian CPU
// big endian will be assumed if IS_LITTLE_ENDIAN is not defined
#if !defined(IS_BIG_ENDIAN) && !defined(IS_LITTLE_ENDIAN)
# define IS_LITTLE_ENDIAN 1
// big endian will be assumed if CRYPTOPP_LITTLE_ENDIAN is not defined
#if !defined(CRYPTOPP_BIG_ENDIAN) && !defined(CRYPTOPP_LITTLE_ENDIAN)
# define CRYPTOPP_LITTLE_ENDIAN 1
#endif
// Sanity checks. Some processors have more than big, little and bi-endian modes. PDP mode, where order results in "4312", should
// raise red flags immediately. Additionally, mis-classified machines, like (previosuly) S/390, should raise red flags immediately.
#if defined(IS_BIG_ENDIAN) && defined(__GNUC__) && defined(__BYTE_ORDER__) && (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__)
# error "IS_BIG_ENDIAN is set, but __BYTE_ORDER__ is not __ORDER_BIG_ENDIAN__"
#if defined(CRYPTOPP_BIG_ENDIAN) && defined(__GNUC__) && defined(__BYTE_ORDER__) && (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__)
# error "CRYPTOPP_BIG_ENDIAN is set, but __BYTE_ORDER__ is not __ORDER_BIG_ENDIAN__"
#endif
#if defined(IS_LITTLE_ENDIAN) && defined(__GNUC__) && defined(__BYTE_ORDER__) && (__BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__)
# error "IS_LITTLE_ENDIAN is set, but __BYTE_ORDER__ is not __ORDER_LITTLE_ENDIAN__"
#if defined(CRYPTOPP_LITTLE_ENDIAN) && defined(__GNUC__) && defined(__BYTE_ORDER__) && (__BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__)
# error "CRYPTOPP_LITTLE_ENDIAN is set, but __BYTE_ORDER__ is not __ORDER_LITTLE_ENDIAN__"
#endif
// Define this if you want to disable all OS-dependent features,

View File

@ -28,7 +28,7 @@ extern void CRC32C_Update_SSE42(const byte *s, size_t n, word32& c);
/* Table of CRC-32's of all single byte values (made by makecrc.c) */
const word32 CRC32::m_tab[] = {
#ifdef IS_LITTLE_ENDIAN
#ifdef CRYPTOPP_LITTLE_ENDIAN
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
@ -188,7 +188,7 @@ void CRC32::TruncatedFinal(byte *hash, size_t size)
// Castagnoli CRC32C (iSCSI)
const word32 CRC32C::m_tab[] = {
#ifdef IS_LITTLE_ENDIAN
#ifdef CRYPTOPP_LITTLE_ENDIAN
0x00000000L, 0xf26b8303L, 0xe13b70f7L, 0x1350f3f4L, 0xc79a971fL,
0x35f1141cL, 0x26a1e7e8L, 0xd4ca64ebL, 0x8ad958cfL, 0x78b2dbccL,
0x6be22838L, 0x9989ab3bL, 0x4d43cfd0L, 0xbf284cd3L, 0xac78bf27L,

2
crc.h
View File

@ -13,7 +13,7 @@ NAMESPACE_BEGIN(CryptoPP)
const word32 CRC32_NEGL = 0xffffffffL;
#ifdef IS_LITTLE_ENDIAN
#ifdef CRYPTOPP_LITTLE_ENDIAN
#define CRC32_INDEX(c) (c & 0xff)
#define CRC32_SHIFTED(c) (c >> 8)
#else

View File

@ -407,7 +407,7 @@ size_t GCM_Base::AuthenticateBlocks(const byte *data, size_t len)
#define READ_TABLE_WORD64_COMMON(a, b, c, d) *(word64 *)(void *)(mulTable+(a*1024)+(b*256)+c+d*8)
#ifdef IS_LITTLE_ENDIAN
#ifdef CRYPTOPP_LITTLE_ENDIAN
#if CRYPTOPP_BOOL_SLOW_WORD64
word32 z0 = (word32)x0;
word32 z1 = (word32)(x0>>32);
@ -478,7 +478,7 @@ size_t GCM_Base::AuthenticateBlocks(const byte *data, size_t len)
#define READ_TABLE_WORD64_COMMON(a, c, d) *(word64 *)(void *)(mulTable+(a)*256*16+(c)+(d)*8)
#ifdef IS_LITTLE_ENDIAN
#ifdef CRYPTOPP_LITTLE_ENDIAN
#if CRYPTOPP_BOOL_SLOW_WORD64
word32 z0 = (word32)x0;
word32 z1 = (word32)(x0>>32);

View File

@ -318,7 +318,7 @@ public:
#endif
{
#if defined(CRYPTOPP_NATIVE_DWORD_AVAILABLE)
# if defined(IS_LITTLE_ENDIAN)
# if defined(CRYPTOPP_LITTLE_ENDIAN)
const word t[2] = {low,high};
memcpy(&m_whole, &t, sizeof(m_whole));
# else
@ -423,7 +423,7 @@ private:
// Thanks to Martin Bonner at http://stackoverflow.com/a/39507183
struct half_words
{
#ifdef IS_LITTLE_ENDIAN
#ifdef CRYPTOPP_LITTLE_ENDIAN
word low;
word high;
#else

View File

@ -43,7 +43,7 @@ using CryptoPP::KalynaTab::IS;
template <unsigned int NB>
inline void MakeOddKey(const word64 evenkey[NB], word64 oddkey[NB])
{
#if defined(IS_BIG_ENDIAN)
#if defined(CRYPTOPP_BIG_ENDIAN)
if (NB == 2)
{
oddkey[0] = (evenkey[1] << 8) | (evenkey[0] >> 56);

8
misc.h
View File

@ -1034,9 +1034,9 @@ inline bool IsAligned(const void *ptr)
return IsAlignedOn(ptr, GetAlignmentOf<T>());
}
#if defined(IS_LITTLE_ENDIAN)
#if defined(CRYPTOPP_LITTLE_ENDIAN)
typedef LittleEndian NativeByteOrder;
#elif defined(IS_BIG_ENDIAN)
#elif defined(CRYPTOPP_BIG_ENDIAN)
typedef BigEndian NativeByteOrder;
#else
# error "Unable to determine endian-ness"
@ -1045,9 +1045,9 @@ inline bool IsAligned(const void *ptr)
//! \brief Returns NativeByteOrder as an enumerated ByteOrder value
//! \returns LittleEndian if the native byte order is little-endian, and BigEndian if the
//! native byte order is big-endian
//! \details NativeByteOrder is a typedef depending on the platform. If IS_LITTLE_ENDIAN is
//! \details NativeByteOrder is a typedef depending on the platform. If CRYPTOPP_LITTLE_ENDIAN is
//! set in config.h, then GetNativeByteOrder returns LittleEndian. If
//! IS_BIG_ENDIAN is set, then GetNativeByteOrder returns BigEndian.
//! CRYPTOPP_BIG_ENDIAN is set, then GetNativeByteOrder returns BigEndian.
//! \note There are other byte orders besides little- and big-endian, and they include bi-endian
//! and PDP-endian. If a system is neither little-endian nor big-endian, then a compile time
//! error occurs.

View File

@ -56,9 +56,9 @@ typedef uint64x2_p8 VectorType;
//! \since Crypto++ 6.0
inline void ReverseByteArrayLE(byte src[16])
{
#if defined(CRYPTOPP_XLC_VERSION) && defined(IS_LITTLE_ENDIAN)
#if defined(CRYPTOPP_XLC_VERSION) && defined(CRYPTOPP_LITTLE_ENDIAN)
vec_st(vec_reve(vec_ld(0, src)), 0, src);
#elif defined(IS_LITTLE_ENDIAN)
#elif defined(CRYPTOPP_LITTLE_ENDIAN)
const uint8x16_p8 mask = {15,14,13,12, 11,10,9,8, 7,6,5,4, 3,2,1,0};
const uint8x16_p8 zero = {0};
vec_vsx_st(vec_perm(vec_vsx_ld(0, src), zero, mask), 0, src);
@ -91,7 +91,7 @@ inline VectorType VectorLoadBE(const uint8_t src[16])
#if defined(CRYPTOPP_XLC_VERSION)
return (VectorType)vec_xl_be(0, (uint8_t*)src);
#else
# if defined(IS_LITTLE_ENDIAN)
# if defined(CRYPTOPP_LITTLE_ENDIAN)
return (VectorType)Reverse(vec_vsx_ld(0, (uint8_t*)src));
# else
return (VectorType)vec_vsx_ld(0, (uint8_t*)src);
@ -112,7 +112,7 @@ inline VectorType VectorLoadBE(int off, const uint8_t src[16])
#if defined(CRYPTOPP_XLC_VERSION)
return (VectorType)vec_xl_be(off, (uint8_t*)src);
#else
# if defined(IS_LITTLE_ENDIAN)
# if defined(CRYPTOPP_LITTLE_ENDIAN)
return (VectorType)Reverse(vec_vsx_ld(off, (uint8_t*)src));
# else
return (VectorType)vec_vsx_ld(off, (uint8_t*)src);
@ -211,7 +211,7 @@ inline void VectorStoreBE(const T& src, uint8_t dest[16])
#if defined(CRYPTOPP_XLC_VERSION)
vec_xst_be((uint8x16_p8)src, 0, (uint8_t*)dest);
#else
# if defined(IS_LITTLE_ENDIAN)
# if defined(CRYPTOPP_LITTLE_ENDIAN)
vec_vsx_st(Reverse((uint8x16_p8)src), 0, (uint8_t*)dest);
# else
vec_vsx_st((uint8x16_p8)src, 0, (uint8_t*)dest);
@ -234,7 +234,7 @@ inline void VectorStoreBE(const T& src, int off, uint8_t dest[16])
#if defined(CRYPTOPP_XLC_VERSION)
vec_xst_be((uint8x16_p8)src, off, (uint8_t*)dest);
#else
# if defined(IS_LITTLE_ENDIAN)
# if defined(CRYPTOPP_LITTLE_ENDIAN)
vec_vsx_st(Reverse((uint8x16_p8)src), off, (uint8_t*)dest);
# else
vec_vsx_st((uint8x16_p8)src, off, (uint8_t*)dest);
@ -257,7 +257,7 @@ inline void VectorStore(const T& src, byte dest[16])
#if defined(CRYPTOPP_XLC_VERSION)
vec_xst_be((uint8x16_p8)src, 0, (uint8_t*)dest);
#else
# if defined(IS_LITTLE_ENDIAN)
# if defined(CRYPTOPP_LITTLE_ENDIAN)
vec_vsx_st(Reverse((uint8x16_p8)src), 0, (uint8_t*)dest);
# else
vec_vsx_st((uint8x16_p8)src, 0, (uint8_t*)dest);
@ -281,7 +281,7 @@ inline void VectorStore(const T& src, int off, byte dest[16])
#if defined(CRYPTOPP_XLC_VERSION)
vec_xst_be((uint8x16_p8)src, off, (uint8_t*)dest);
#else
# if defined(IS_LITTLE_ENDIAN)
# if defined(CRYPTOPP_LITTLE_ENDIAN)
vec_vsx_st(Reverse((uint8x16_p8)src), off, (uint8_t*)dest);
# else
vec_vsx_st((uint8x16_p8)src, off, (uint8_t*)dest);
@ -359,7 +359,7 @@ inline T1 VectorAdd(const T1& vec1, const T2& vec2)
template <unsigned int C, class T1, class T2>
inline T1 VectorShiftLeft(const T1& vec1, const T2& vec2)
{
#if defined(IS_LITTLE_ENDIAN)
#if defined(CRYPTOPP_LITTLE_ENDIAN)
return (T1)vec_sld((uint8x16_p8)vec2, (uint8x16_p8)vec1, 16-C);
#else
return (T1)vec_sld((uint8x16_p8)vec1, (uint8x16_p8)vec2, C);

View File

@ -161,7 +161,7 @@ bool CPU_ProbeAES()
ANONYMOUS_NAMESPACE_BEGIN
#if defined(IS_LITTLE_ENDIAN)
#if defined(CRYPTOPP_LITTLE_ENDIAN)
const word32 s_one[] = {0, 0, 0, 1<<24}; // uint32x4_t
#else
const word32 s_one[] = {0, 0, 0, 1}; // uint32x4_t
@ -775,7 +775,7 @@ ANONYMOUS_NAMESPACE_BEGIN
/* Round constants */
static const uint32_t s_rcon[3][4] = {
#if defined(IS_LITTLE_ENDIAN)
#if defined(CRYPTOPP_LITTLE_ENDIAN)
{0x01,0x01,0x01,0x01}, /* 1 */
{0x1b,0x1b,0x1b,0x1b}, /* 9 */
{0x36,0x36,0x36,0x36} /* 10 */
@ -788,7 +788,7 @@ static const uint32_t s_rcon[3][4] = {
/* Permute mask */
static const uint32_t s_mask[4] = {
#if defined(IS_LITTLE_ENDIAN)
#if defined(CRYPTOPP_LITTLE_ENDIAN)
0x0c0f0e0d,0x0c0f0e0d,0x0c0f0e0d,0x0c0f0e0d
#else
0x0d0e0f0c,0x0d0e0f0c,0x0d0e0f0c,0x0d0e0f0c
@ -963,7 +963,7 @@ size_t Rijndael_AdvancedProcessBlocks_POWER8(F1 func1, F6 func6, const word32 *s
{
while (length >= 6*blockSize)
{
#if defined(IS_LITTLE_ENDIAN)
#if defined(CRYPTOPP_LITTLE_ENDIAN)
const VectorType one = (VectorType)((uint64x2_p8){1,0});
#else
const VectorType one = (VectorType)((uint64x2_p8){0,1});
@ -1075,7 +1075,7 @@ void Rijndael_UncheckedSetKey_POWER8(const byte* userKey, size_t keyLen, word32*
uint8x16_p8 r4 = (uint8x16_p8)VectorLoadKey(s_rcon[0]);
uint8x16_p8 r5 = (uint8x16_p8)VectorLoadKey(s_mask);
#if defined(IS_LITTLE_ENDIAN)
#if defined(CRYPTOPP_LITTLE_ENDIAN)
// Only the user key requires byte reversing.
// The subkeys are stored in proper endianess.
ReverseByteArrayLE(skptr);
@ -1136,7 +1136,7 @@ void Rijndael_UncheckedSetKey_POWER8(const byte* userKey, size_t keyLen, word32*
rk += keyLen/4;
}
#if defined(IS_LITTLE_ENDIAN)
#if defined(CRYPTOPP_LITTLE_ENDIAN)
rk = rk_saved;
const uint8x16_p8 mask = ((uint8x16_p8){12,13,14,15, 8,9,10,11, 4,5,6,7, 0,1,2,3});
const uint8x16_p8 zero = {0};

View File

@ -207,7 +207,7 @@ ANONYMOUS_NAMESPACE_END
#define QUARTER_ROUND_E(t, a, b, c, d) QUARTER_ROUND(TL_M, Te, t, a, b, c, d)
#define QUARTER_ROUND_D(t, a, b, c, d) QUARTER_ROUND(TL_M, Td, t, a, b, c, d)
#ifdef IS_LITTLE_ENDIAN
#ifdef CRYPTOPP_LITTLE_ENDIAN
#define QUARTER_ROUND_FE(t, a, b, c, d) QUARTER_ROUND(TL_F, Te, t, d, c, b, a)
#define QUARTER_ROUND_FD(t, a, b, c, d) QUARTER_ROUND(TL_F, Td, t, d, c, b, a)
#if defined(CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS) || defined(CRYPTOPP_ALLOW_RIJNDAEL_UNALIGNED_DATA_ACCESS)

View File

@ -67,7 +67,7 @@ void SHARK::Base::UncheckedSetKey(const byte *key, unsigned int keyLen, const Na
m_roundKeys[i] = SHARKTransform(m_roundKeys[i]);
}
#ifdef IS_LITTLE_ENDIAN
#ifdef CRYPTOPP_LITTLE_ENDIAN
m_roundKeys[0] = ByteReverse(m_roundKeys[0]);
m_roundKeys[m_rounds] = ByteReverse(m_roundKeys[m_rounds]);
#endif
@ -84,7 +84,7 @@ void SHARK::Enc::InitForKeySetup()
m_roundKeys[DEFAULT_ROUNDS] = SHARKTransform(cbox[0][DEFAULT_ROUNDS]);
#ifdef IS_LITTLE_ENDIAN
#ifdef CRYPTOPP_LITTLE_ENDIAN
m_roundKeys[0] = ByteReverse(m_roundKeys[0]);
m_roundKeys[m_rounds] = ByteReverse(m_roundKeys[m_rounds]);
#endif

View File

@ -226,7 +226,7 @@ bool TestSettings()
if (w == 0x04030201L)
{
#ifdef IS_LITTLE_ENDIAN
#ifdef CRYPTOPP_LITTLE_ENDIAN
std::cout << "passed: ";
#else
std::cout << "FAILED: ";
@ -236,7 +236,7 @@ bool TestSettings()
}
else if (w == 0x01020304L)
{
#ifndef IS_LITTLE_ENDIAN
#ifndef CRYPTOPP_LITTLE_ENDIAN
std::cout << "passed: ";
#else
std::cout << "FAILED: ";