Hi All,

Below (and attached) is a patch for the latest Crypto++ (5.6.1) under
the Windows Mobile 5, 6, and 6.5 (the latest mobile operating system,
Windows Phone, is not covered). It was vetted against is SmartPhone
and PocketPC projects.

The biggest point is detecting Windows Mobile and taking appropriate
actions via WIN32_PLATFORM_WFSP (SmartPhone), WIN32_PLATFORM_PSPC
(PocketPC), or UNDER_CE; and replacing the missing time() and clock()
functions for the X917RNG class.

The path of least resistance included dropping Crypto++ support for
Windows Threads, Sockets, Pipes, and the high resolution timer. There
was some cross pollination because the DISABLE_* prerpocessor macros
did not cleanly handle conditional compilation of the feature
(understandable due to Windows Mobile). If you need a socket, thread,
or pipe, then use it directly.

In addition, an executable *must* enable RTTI under Windows Mobile,
since Crypto++ uses dynamic_cast. Failure to do so results in
intermittent device hangs and access violations at run time.

Finally, anyone stumbling across the patch in the future might be
interested in reading http://www.cryptopp.com/wiki/Windows_Mobile.
This patch should not be much different than Ugo Chirico's Crypto++
5.5.2 patch.

Jeff

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: 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: config.h
===================================================================
--- config.h    (revision 525)
+++ config.h    (working copy)
@@ -14,6 +14,13 @@
 #      define IS_LITTLE_ENDIAN
 #endif

+#if defined(WIN32_PLATFORM_WFSP) || defined(WIN32_PLATFORM_PSPC) ||
defined(UNDER_CE)
+# define CRYPTOPP_WINMOBILE 1
+# define CRYPTOPP_DISABLE_ASM 1
+# define CRYPTOPP_DISABLE_SSE2 1
+# define NOMINMAX      // clash with std::min() and std::max()
+#endif
+
 // define this if you want to disable all OS-dependent features,
 // such as sockets and OS-provided random number generators
 // #define NO_OS_DEPENDENCE
@@ -301,6 +308,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
@@ -408,6 +420,23 @@

 #endif // NO_OS_DEPENDENCE

+// Threads, Sockets, and Pipes are more trouble than they are worth
+// under Windows Mobile. Use the primitives manually.
+#if defined(CRYPTOPP_WINMOBILE)
+# if defined(SOCKETS_AVAILABLE)
+#  undef SOCKETS_AVAILABLE
+# endif
+# if defined(WINDOWS_PIPES_AVAILABLE)
+#  undef WINDOWS_PIPES_AVAILABLE
+# endif
+# if defined(THREADS_AVAILABLE)
+#  undef THREADS_AVAILABLE
+# endif
+# if defined(HIGHRES_TIMER_AVAILABLE)
+#  undef HIGHRES_TIMER_AVAILABLE
+# endif
+#endif
+
 // ***************** DLL related ********************

 #if defined(CRYPTOPP_WIN32_AVAILABLE) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
Index: fipstest.cpp
===================================================================
--- fipstest.cpp        (revision 525)
+++ fipstest.cpp        (working copy)
@@ -294,7 +294,7 @@
        if (!moduleStream)
        {
 #ifdef CRYPTOPP_WIN32_AVAILABLE
-               OutputDebugString("Crypto++ DLL integrity check failed. Cannot 
open
file for reading.");
+               OutputDebugStringA("Crypto++ DLL integrity check failed. Cannot
open file for reading.");
 #endif
                return false;
        }
@@ -388,7 +388,7 @@
        // hash from disk instead
        if (!VerifyBufsEqual(expectedModuleMac, actualMac, macSize))
        {
-               OutputDebugString("In memory integrity check failed. This may be
caused by debug breakpoints or DLL relocation.\n");
+               OutputDebugStringA("In memory integrity check failed. This may 
be
caused by debug breakpoints or DLL relocation.\n");
                moduleStream.clear();
                moduleStream.seekg(0);
                verifier.Initialize(MakeParameters(Name::OutputBuffer(),
ByteArrayParameter(actualMac, (unsigned int)actualMac.size())));
@@ -407,7 +407,7 @@
 #ifdef CRYPTOPP_WIN32_AVAILABLE
        std::string hexMac;
        HexEncoder(new StringSink(hexMac)).PutMessageEnd(actualMac, 
actualMac.size());
-       OutputDebugString((("Crypto++ DLL integrity check failed. Actual MAC
is: " + hexMac) + "\n").c_str());
+       OutputDebugStringA((("Crypto++ DLL integrity check failed. Actual
MAC is: " + hexMac) + "\n").c_str());
 #endif
        return false;
 }
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: hrtimer.h
===================================================================
--- hrtimer.h   (revision 525)
+++ hrtimer.h   (working copy)
@@ -8,7 +8,7 @@

 NAMESPACE_BEGIN(CryptoPP)

-#ifdef HIGHRES_TIMER_AVAILABLE
+#if defined(HIGHRES_TIMER_AVAILABLE) || defined(CRYPTOPP_WINMOBILE)
        typedef word64 TimerWord;
 #else
        typedef clock_t TimerWord;
Index: integer.cpp
===================================================================
--- integer.cpp (revision 525)
+++ integer.cpp (working copy)
@@ -18,7 +18,7 @@

 #include <iostream>

-#if _MSC_VER >= 1400
+#if _MSC_VER >= 1400 && !defined(CRYPTOPP_WINMOBILE)
        #include <intrin.h>
 #endif

@@ -140,7 +140,7 @@
        #define GetBorrow(u)                            u##1
 #else
        #define Declare2Words(x)                        dword x;
-       #if _MSC_VER >= 1400 && !defined(__INTEL_COMPILER)
+       #if _MSC_VER >= 1400 && !defined(__INTEL_COMPILER) &&
!defined(CRYPTOPP_WINMOBILE)
                #define MultiplyWords(p, a, b)          p = __emulu(a, b);
        #else
                #define MultiplyWords(p, a, b)          p = (dword)a*b;
Index: misc.h
===================================================================
--- misc.h      (revision 525)
+++ misc.h      (working copy)
@@ -12,7 +12,9 @@
                #define _interlockedbittestandreset 
CRYPTOPP_DISABLED_INTRINSIC_2
                #define _interlockedbittestandset64 
CRYPTOPP_DISABLED_INTRINSIC_3
                #define _interlockedbittestandreset64 
CRYPTOPP_DISABLED_INTRINSIC_4
-               #include <intrin.h>
+               #if !defined(CRYPTOPP_WINMOBILE)
+                       #include <intrin.h>
+               #endif
                #undef _interlockedbittestandset
                #undef _interlockedbittestandreset
                #undef _interlockedbittestandset64
@@ -258,7 +260,7 @@
 {
 #if defined(__GNUC__) && CRYPTOPP_GCC_VERSION >= 30400
        return __builtin_ctz(v);
-#elif defined(_MSC_VER) && _MSC_VER >= 1400
+#elif defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(CRYPTOPP_WINMOBILE)
        unsigned long result;
        _BitScanForward(&result, v);
        return result;
@@ -690,7 +692,7 @@

 #endif // #if _MSC_VER >= 1310

-#if _MSC_VER >= 1400 && !defined(__INTEL_COMPILER)
+#if _MSC_VER >= 1400 && !defined(__INTEL_COMPILER) &&
!defined(CRYPTOPP_WINMOBILE)
 // Intel C++ Compiler 10.0 gives undefined externals with these

 template<> inline word16 rotlFixed<word16>(word16 x, unsigned int y)
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)
 {
 }

Index: osrng.h
===================================================================
--- osrng.h     (revision 525)
+++ osrng.h     (working copy)
@@ -40,9 +40,12 @@
        ProviderHandle m_hProvider;
 };

-#pragma comment(lib, "advapi32.lib")
+#if !defined(CRYPTOPP_WINMOBILE)
+# pragma comment(lib, "advapi32.lib")
 #endif

+#endif
+
 //! encapsulate CryptoAPI's CryptGenRandom or /dev/urandom
 class CRYPTOPP_DLL NonblockingRng : public RandomNumberGenerator
 {
Index: pch.h
===================================================================
--- pch.h       (revision 525)
+++ pch.h       (working copy)
@@ -1,6 +1,10 @@
 #ifndef CRYPTOPP_PCH_H
 #define CRYPTOPP_PCH_H

+#ifdef _MSC_VER
+# pragma warning(disable: 4068 4100 4127 4146 4231 4512 6237 6326)
+#endif
+
 #ifdef CRYPTOPP_GENERATE_X64_MASM

        #include "cpu.h"
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: 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: 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: stdcpp.h
===================================================================
--- stdcpp.h    (revision 525)
+++ stdcpp.h    (working copy)
@@ -2,9 +2,11 @@
 #define CRYPTOPP_STDCPP_H

 #if _MSC_VER >= 1500
-#define _DO_NOT_DECLARE_INTERLOCKED_INTRINSICS_IN_MEMORY
-#include <intrin.h>
+# if !defined(CRYPTOPP_WINMOBILE)
+#  define _DO_NOT_DECLARE_INTERLOCKED_INTRINSICS_IN_MEMORY
+#  include <intrin.h>
 #endif
+#endif

 #include <stddef.h>
 #include <assert.h>
Index: vmac.cpp
===================================================================
--- vmac.cpp    (revision 525)
+++ vmac.cpp    (working copy)
@@ -8,7 +8,7 @@

 NAMESPACE_BEGIN(CryptoPP)

-#if defined(_MSC_VER) && !CRYPTOPP_BOOL_SLOW_WORD64
+#if defined(_MSC_VER) && !CRYPTOPP_BOOL_SLOW_WORD64 &&
!defined(CRYPTOPP_WINMOBILE)
 #include <intrin.h>
 #endif

@@ -389,7 +389,7 @@
        #define AccumulateNH(a, b, c) a += word128(b)*(c)
        #define Multiply128(r, i1, i2) r = word128(word64(i1)) * word64(i2)
 #else
-       #if _MSC_VER >= 1400 && !defined(__INTEL_COMPILER)
+       #if _MSC_VER >= 1400 && !defined(__INTEL_COMPILER) &&
!defined(CRYPTOPP_WINMOBILE)
                #define MUL32(a, b) __emulu(word32(a), word32(b))
        #else
                #define MUL32(a, b) ((word64)((word32)(a)) * (word32)(b))

-- 
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-winmobile.patch
Description: Binary data

Reply via email to