Hi Wei,

Below (and attached) is a patch for the latest Crypto++ under the
latest Xcode/iOS SDK. It was vetted against is an iOS 4.2 iPhone
project.

Most is low hanging fruit, such as stray/unguarded "#pragma
warning(disable: XXX)". The change around
__IPHONE_OS_VERSION_MIN_REQUIRED was required so I could subsequently
#define CRYPTOPP_BOOL_ALIGN16_ENABLED 0. Otherwise, Crypto++ would
define CRYPTOPP_BOOL_ALIGN16_ENABLED to 1, and under certain
circumstances use the fallback allocator. The fallback allocator does
nothing (except assert), so a crash ensued.

__IPHONE_OS_VERSION_MIN_REQUIRED is somewhat undocumented, but it was
more granular than using __APPLE__. Since building from the command
line for the desktop worked fine, I thought it might be best to leave
the desktop settings alone. Note that __IPHONE_OS_VERSION_MIN_REQUIRED
currently is defined for both iPhone and iPad - there does not appear
to be a companion __IPAD_OS_VERSION_MIN_REQUIRED.

Finally, anyone stumbling across the patch in the future might be
interested in reading http://www.cryptopp.com/wiki/IOS.

Jeff

$ cat cryptopp-525-iphone.patch
Index: algparam.h
===================================================================
--- algparam.h  (revision 525)
+++ algparam.h  (working copy)
@@ -320,6 +320,7 @@
        void MoveInto(void *buffer) const
        {
                AlgorithmParametersTemplate<T>* p = new(buffer)
AlgorithmParametersTemplate<T>(*this);
+               ((void)p);
        }

 protected:
Index: gcm.cpp
===================================================================
--- gcm.cpp     (revision 525)
+++ gcm.cpp     (working copy)
@@ -334,7 +334,9 @@
                GetBlockCipher().OptimalDataAlignment();
 }

-#pragma warning(disable: 4731) // frame pointer register 'ebp'
modified by inline assembly code
+#if defined(CRYPTOPP_WIN32_AVAILABLE)
+# pragma warning(disable: 4731)        // frame pointer register 'ebp'
modified by inline assembly code
+#endif

 #endif // #ifndef CRYPTOPP_GENERATE_X64_MASM

Index: asn.cpp
===================================================================
--- asn.cpp     (revision 525)
+++ asn.cpp     (working copy)
@@ -348,6 +348,12 @@

                        if (m_lengthRemaining == 0)
                                m_state = IDENTIFIER;
+                               
+                       break;
+                               
+               case TAIL:
+               case ALL_DONE:
+                       assert(false);
                }

                if (m_state == IDENTIFIER && m_level == 0)
Index: misc.h
===================================================================
--- misc.h      (revision 525)
+++ misc.h      (working copy)
@@ -545,7 +545,7 @@
 }

 // this function uses wcstombs(), which assumes that setlocale() has
been called
-static std::string StringNarrow(const wchar_t *str, bool throwOnError = true)
+inline static std::string StringNarrow(const wchar_t *str, bool
throwOnError = true)
 {
 #ifdef _MSC_VER
 #pragma warning(push)
Index: salsa.cpp
===================================================================
--- salsa.cpp   (revision 525)
+++ salsa.cpp   (working copy)
@@ -80,7 +80,9 @@
 }
 #endif

-#pragma warning(disable: 4731) // frame pointer register 'ebp'
modified by inline assembly code
+#if defined(CRYPTOPP_WIN32_AVAILABLE)
+# pragma warning(disable: 4731)        // frame pointer register 'ebp'
modified by inline assembly code
+#endif

 void Salsa20_Policy::OperateKeystream(KeystreamOperation operation,
byte *output, const byte *input, size_t iterationCount)
 {
Index: sosemanuk.cpp
===================================================================
--- sosemanuk.cpp       (revision 525)
+++ sosemanuk.cpp       (working copy)
@@ -317,7 +317,9 @@
 }
 #endif

-#pragma warning(disable: 4731) // frame pointer register 'ebp'
modified by inline assembly code
+#if defined(CRYPTOPP_WIN32_AVAILABLE)
+# pragma warning(disable: 4731)        // frame pointer register 'ebp'
modified by inline assembly code
+#endif

 void SosemanukPolicy::OperateKeystream(KeystreamOperation operation,
byte *output, const byte *input, size_t iterationCount)
 {
Index: dll.cpp
===================================================================
--- dll.cpp     (revision 525)
+++ dll.cpp     (working copy)
@@ -4,8 +4,11 @@
 #define CRYPTOPP_DEFAULT_NO_DLL

 #include "dll.h"
-#pragma warning(default: 4660)

+#if defined(CRYPTOPP_WIN32_AVAILABLE)
+# pragma warning(default: 4660)
+#endif
+
 #if defined(CRYPTOPP_EXPORTS) && defined(CRYPTOPP_WIN32_AVAILABLE)
 #include <windows.h>
 #endif
Index: socketft.cpp
===================================================================
--- socketft.cpp        (revision 525)
+++ socketft.cpp        (working copy)
@@ -476,7 +476,7 @@
 #ifdef USE_BERKELEY_STYLE_SOCKETS

 SocketReceiver::SocketReceiver(Socket &s)
-       : m_s(s), m_lastResult(0), m_eofReceived(false)
+       : m_s(s), m_eofReceived(false), m_lastResult(0)
 {
 }

Index: rijndael.cpp
===================================================================
--- rijndael.cpp        (revision 525)
+++ rijndael.cpp        (working copy)
@@ -515,7 +515,9 @@

 // ************************* Assembly Code ************************************

-#pragma warning(disable: 4731) // frame pointer register 'ebp'
modified by inline assembly code
+#if defined(CRYPTOPP_WIN32_AVAILABLE)
+# pragma warning(disable: 4731)        // frame pointer register 'ebp'
modified by inline assembly code
+#endif

 #endif // #ifndef CRYPTOPP_GENERATE_X64_MASM

Index: config.h
===================================================================
--- config.h    (revision 525)
+++ config.h    (working copy)
@@ -301,6 +301,11 @@
        #define CRYPTOPP_BOOL_ALIGN16_ENABLED 0
 #endif

+#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
+#  undef CRYPTOPP_BOOL_ALIGN16_ENABLED
+#  define CRYPTOPP_BOOL_ALIGN16_ENABLED 0
+#endif
+
 // how to allocate 16-byte aligned memory (for SSE2)
 #if defined(CRYPTOPP_MSVC6PP_OR_LATER)
        #define CRYPTOPP_MM_MALLOC_AVAILABLE
Index: network.cpp
===================================================================
--- network.cpp (revision 525)
+++ network.cpp (working copy)
@@ -227,8 +227,8 @@

 NetworkSource::NetworkSource(BufferedTransformation *attachment)
        : NonblockingSource(attachment), m_buf(1024*16)
+       , m_dataBegin(0), m_dataEnd(0)
        , m_waitingForResult(false), m_outputBlocked(false)
-       , m_dataBegin(0), m_dataEnd(0)
 {
 }

-- 
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.

Attachment: cryptopp-525-iphone.patch
Description: Binary data

Reply via email to