diff options
author | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2010-07-05 01:15:14 +0000 |
---|---|---|
committer | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2010-07-05 01:15:14 +0000 |
commit | 55a8ab1c8b2d3ff2ad7b3325f87e78b8976a6169 (patch) | |
tree | bdfe463fd8b180c37b65007e19a29aa915fff3b3 | |
parent | 32a4a9f72510c22a1c4ef7b73b0496ea031a090b (diff) | |
download | cryptopp-55a8ab1c8b2d3ff2ad7b3325f87e78b8976a6169.tar.gz |
port to Sun Studio 12u1 Sun C++ 5.10 SunOS_i386 128229-02 2009/09/21
change makefile to compile for both i386 and x86_64 on Darwin/Mac OS X
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@499 57ff6487-cd31-0410-9ec3-f628ee90f5f0
-rw-r--r-- | GNUmakefile | 7 | ||||
-rw-r--r-- | idea.cpp | 2 | ||||
-rw-r--r-- | integer.cpp | 2 | ||||
-rw-r--r-- | stdcpp.h | 5 | ||||
-rw-r--r-- | tea.cpp | 12 | ||||
-rw-r--r-- | validat1.cpp | 7 | ||||
-rw-r--r-- | wake.cpp | 36 |
7 files changed, 49 insertions, 22 deletions
diff --git a/GNUmakefile b/GNUmakefile index 5bf68b8..b32392b 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -31,7 +31,9 @@ GAS217_OR_LATER = $(shell echo "" | $(AS) -v 2>&1 | $(EGREP) -c "GNU assembler v ISMINGW = $(shell $(CXX) --version 2>&1 | $(EGREP) -c "mingw") ifneq ($(GCC42_OR_LATER),0) -ifneq ($(UNAME),Darwin) +ifeq ($(UNAME),Darwin) +CXXFLAGS += -arch x86_64 -arch i386 +else CXXFLAGS += -march=native -mtune=native endif endif @@ -86,6 +88,9 @@ LDLIBS += -lnsl -lsocket ifeq ($(CXX),CC) # override flags for CC (Solaris native C++ compiler) CXXFLAGS = -DNDEBUG -O -g0 -native -template=no%extdef -m$(shell isainfo -b) LDFLAGS = +AR = CC +ARFLAGS = -xar -o +RANLIB = true ifeq ($(ISX86),1) # SSE2 intrinsics should work in Sun Studio 12, but we're not using SSE2 intrinsics anymore # CXXFLAGS += -xarch=sse2 -D__SSE2__ @@ -129,7 +129,7 @@ static inline IDEA::Word AddInv(IDEA::Word x) void IDEA::Base::DeKey() { FixedSizeSecBlock<IDEA::Word, 6*ROUNDS+4> tempkey; - unsigned int i; + size_t i; for (i=0; i<ROUNDS; i++) { diff --git a/integer.cpp b/integer.cpp index fc5ba2d..f07cce8 100644 --- a/integer.cpp +++ b/integer.cpp @@ -115,7 +115,7 @@ static word AtomicInverseModPower2(word A) #elif defined(__DECCXX) #define MultiplyWordsLoHi(p0, p1, a, b) p0 = a*b; p1 = asm("umulh %a0, %a1, %v0", a, b); #elif defined(__x86_64__) - #ifdef __SUNPRO_CC + #if defined(__SUNPRO_CC) && __SUNPRO_CC < 0x5100 // Sun Studio's gcc-style inline assembly is heavily bugged as of version 5.9 Patch 124864-09 2008/12/16, but this one works #define MultiplyWordsLoHi(p0, p1, a, b) asm ("mulq %3" : "=a"(p0), "=d"(p1) : "a"(a), "r"(b) : "cc"); #else @@ -14,6 +14,11 @@ #include <map> #include <vector> +#ifdef __SUNPRO_CC +// workaround needed on Sun Studio 12u1 Sun C++ 5.10 SunOS_i386 128229-02 2009/09/21 +#include <vector.cc> +#endif + // for alloca #ifdef __sun #include <alloca.h> @@ -62,8 +62,14 @@ void XTEA::Enc::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, by word32 y, z; Block::Get(inBlock)(y)(z); +#ifdef __SUNPRO_CC + // workaround needed on Sun Studio 12u1 Sun C++ 5.10 SunOS_i386 128229-02 2009/09/21 + size_t sum = 0; + while ((sum&0xffffffff) != m_limit) +#else word32 sum = 0; while (sum != m_limit) +#endif { y += (z<<4 ^ z>>5) + z ^ sum + m_k[sum&3]; sum += DELTA; @@ -78,8 +84,14 @@ void XTEA::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, by word32 y, z; Block::Get(inBlock)(y)(z); +#ifdef __SUNPRO_CC + // workaround needed on Sun Studio 12u1 Sun C++ 5.10 SunOS_i386 128229-02 2009/09/21 + size_t sum = m_limit; + while ((sum&0xffffffff) != 0) +#else word32 sum = m_limit; while (sum != 0) +#endif { z -= (y<<4 ^ y>>5) + y ^ sum + m_k[sum>>11 & 3]; sum -= DELTA; diff --git a/validat1.cpp b/validat1.cpp index 9935bbd..680314c 100644 --- a/validat1.cpp +++ b/validat1.cpp @@ -130,7 +130,10 @@ bool TestSettings() cout << "\nTesting Settings...\n\n"; - if (*(word32 *)"\x01\x02\x03\x04" == 0x04030201L) + word32 w; + memcpy_s(&w, sizeof(w), "\x01\x02\x03\x04", 4); + + if (w == 0x04030201L) { #ifdef IS_LITTLE_ENDIAN cout << "passed: "; @@ -140,7 +143,7 @@ bool TestSettings() #endif cout << "Your machine is little endian.\n"; } - else if (*(word32 *)"\x01\x02\x03\x04" == 0x01020304L) + else if (w == 0x01020304L) { #ifndef IS_LITTLE_ENDIAN cout << "passed: "; @@ -16,22 +16,24 @@ void WAKE_TestInstantiations() inline word32 WAKE_Base::M(word32 x, word32 y) { word32 w = x+y; - return (w>>8) ^ t[(byte)w]; + return (w>>8) ^ t[w & 0xff]; } void WAKE_Base::GenKey(word32 k0, word32 k1, word32 k2, word32 k3) { - long x, z; - int p ; - static long tt[10]= { - 0x726a8f3bL, // table - 0xe69a3b5cL, - 0xd3c71fe5L, - 0xab3c73d2L, - 0x4d3a8eb3L, - 0x0396d6e8L, - 0x3d4c2f7aL, - 0x9ee27cf3L, } ; + // this code is mostly copied from David Wheeler's paper "A Bulk Data Encryption Algorithm" + signed int x, z, p; + // x and z were declared as "long" in Wheeler's paper, which is a signed type. I don't know if that was intentional, but it's too late to change it now. -- Wei 7/4/2010 + CRYPTOPP_COMPILE_ASSERT(sizeof(x) == 4); + static int tt[10]= { + 0x726a8f3b, // table + 0xe69a3b5c, + 0xd3c71fe5, + 0xab3c73d2, + 0x4d3a8eb3, + 0x0396d6e8, + 0x3d4c2f7a, + 0x9ee27cf3, } ; t[0] = k0; t[1] = k1; t[2] = k2; @@ -39,16 +41,16 @@ void WAKE_Base::GenKey(word32 k0, word32 k1, word32 k2, word32 k3) for (p=4 ; p<256 ; p++) { x=t[p-4]+t[p-1] ; // fill t - t[p]= (x>>3) ^ tt[byte(x&7)] ; + t[p]= (x>>3) ^ tt[x&7] ; } for (p=0 ; p<23 ; p++) t[p]+=t[p+89] ; // mix first entries - x=t[33] ; z=t[59] | 0x01000001L ; - z=z&0xff7fffffL ; + x=t[33] ; z=t[59] | 0x01000001 ; + z=z&0xff7fffff ; for (p=0 ; p<256 ; p++) { //change top byte to - x=(x&0xff7fffffL)+z ; // a permutation etc - t[p]=(t[p] & 0x00ffffffL) ^ x ; } + x=(x&0xff7fffff)+z ; // a permutation etc + t[p]=(t[p] & 0x00ffffff) ^ x ; } t[256]=t[0] ; byte y=byte(x); |