ANSI C Based OPC UA Client/Server SDK  1.8.3.398
Compiling OpenSSL for Windows CE

The following sections descibe how to compile OpenSSL for Windows CE without patented algorithms.

Requirements

You will need tar to unpack the OpenSSL source package. Download and install Cygwin from https://cygwin.com/install.html. The default installation includes tar.

Additionally, Perl is required. You can use the package provided by Cygwin. Note that Perl is not part of a standard Cygwin installation but has to be selected manually.

To use Perl in a Visual Studio Command Prompt, it is necessary to add the directory <cygwin_install_dir>\bin (e.g. c:\cygwin64\bin) to the PATH environment variable.

A Windows CE SDK is required to build OpenSSL for Windows CE. The following example uses our Windows CE SDK, you’ll have to change some pathes to match your own toolchain.

Furthermore, wcecompat compatibility library is required. It can be downloaded from https://github.com/mauricek/wcecompat.

Compile wcecompat

You may have to fix some issues before being able to compile wcecompat.

Most probably, there’s a bug in the file src/time.c Check the following lines:

struct tm* localtime(const time_t* clock)
st_tm.tm_mon = stLocal.wMonth - 1;
st_tm.tm_year = stLocal.wYear - 1900;
struct tm* gmtime(const time_t* clock)
st_tm.tm_mon = stUtc.wMonth - 1;
st_tm.tm_year = stUtc.wYear - 1900;

Then make sure that the file include/io.h includes all of the following defines:

#define access _wceaccess
#define open _wceopen
#define _open _wceopen
#define close _wceclose
#define read _wceread
#define write _wcewrite
#define lseek _wcelseek
#define _lseek _wcelseek
#define unlink _wceunlink
#ifdef rename
#undef rename
#endif
#define rename _wcerename
#define _rename _wcerename
#define fdopen _wcefdopen
#define _fdopen _wcefdopen
#define _stat stat
#define _read read
#define _write write
#define _close close

Now open a a Visual Studio 2008 command prompt and set up your toolchain. Below you can find our toolchain for Windows CE 7, you’ll need to change it to match your environment.

For x86:

set LIB=C:\Program Files (x86)\Windows CE Tools\SDKs\Unified_Automation_WCE_700\Lib\X86;C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\ce\lib\X86;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\lib
set INCLUDE=C:\Program Files (x86)\Windows CE Tools\SDKs\Unified_Automation_WCE_700\Include\X86
set OSVERSION=WCE700
set PLATFORM=VC-CE
set TARGETCPU=x86
set Path=C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin;%Path%
set LIBPATH="C:\Program Files (x86)\Windows CE Tools\SDKs\Unified_Automation_WCE_700\Lib\X86";C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\lib;

For ARMV4I:

set LIB=C:\Program Files (x86)\Windows CE Tools\SDKs\Unified_Automation_WCE_700\Lib\ARMV4I;C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\ce\lib\ARMV4I;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\lib
set INCLUDE=C:\Program Files (x86)\Windows CE Tools\SDKs\Unified_Automation_WCE_700\Include\ARMV4I
set OSVERSION=WCE700
set PLATFORM=VC-CE
set TARGETCPU=ARMV4I
set Path=C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\ce\bin\x86_arm;%Path%
set LIBPATH="C:\Program Files (x86)\Windows CE Tools\SDKs\Unified_Automation_WCE_700\Lib\ARMV4I";C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\lib;

Change to the folder containing the wcecompat sources and run the configure script:

perl config.pl

For a debug build, set the following compiler flags:

/W3 /WX /Zi /GF /Gy /GR- /Gm /EHsc /MTd /fp:fast /nologo

and add the following preprocessor definitions:

-DDEBUG -D_DEBUG_ -D_DEBUG

Finally, compile wcecompat:

nmake -f makefile

Debug and Release

The actions described in the following steps may differ depending on the libraries to be compiled for debug or release mode. This will be noted in each step below if applicable.

Furthermore, it is described what files to modify to append a “d” to the filename for debug mode if you inted to use debug and release libraries side by side.

Patch OpenSSL

!!!NOTE: This describes how to patch OpenSSL version 1.0.2p!!! Download the most recent version of OpenSSL from http://www.openssl.org/source/. Start a cygwin terminal, navigate to the folder containing the downloaded archive and unpack it:

tar –xvzf openssl-<version>.tar.gz

It’s necessary to patch some files in the OpenSSL source distribution. Edit the following files:

File e_os.h:

Line 350: Replace "# ifdef OPENSSL_SYS_WINCE"
with
"# if defined(OPENSSL_SYS_WINCE) && !defined(open)"
Line 523: Replace "# include <winsock.h>"
with
"# include <winsock2.h>"
Line 524: Add "# include <ws2tcpip.h>"

File apps/apps.c:

Line 148: Replace "#ifdef _WIN32"
with
"#if defined(OPENSSL_SYS_WIN32) && !defined(rename)"

File crypto/rand/randfile.c:

Line 103: Replace "#ifdef _WIN32" with "#ifdef OPENSSL_SYS_WIN32
#ifndef stat
# define stat _stat
#endif
#ifndef chmod
# define chmod _chmod
#endif
#ifndef open
# define open _open
#endif
#ifndef fdopen
# define fdopen _fdopen
#endif
#endif"

File crypto/o_time.c:

Line 112: Replace "#elif defined (OPENSSL_SYS_WINDOWS) && defined(_MSC_VER) && _MSC_VER >= 1400"
with
"#elif defined (OPENSSL_SYS_WINDOWS) && defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(_WIN32_WCE)"

File util/pl/VC32.pl/VC32:

Line 117: Replace "$base_cflags=' /W3 /WX /GF /Gy /nologo -DUNICODE -D_UNICODE -DOPENSSL_SYSNAME_WINCE -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DDSO_WIN32 -DNO_CHMOD -DOPENSSL_SMALL_FOOTPRINT';"
with
"$base_cflags=' /W3 /WX /wd4748 /wd4101 /GF /Gy /nologo -DUNICODE -D_UNICODE -DOPENSSL_SYSNAME_WINCE -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DDSO_WIN32 -DNO_CHMOD -DOPENSSL_SMALL_FOOTPRINT -DOPENSSL_NO_CAPIENG';"
Line 191: Replace "$ex_libs.=' /nodefaultlib coredll.lib corelibc.lib' if ($ENV{'TARGETCPU'} eq "X86");"
with
"$ex_libs.=' /nodefaultlib:oldnames.lib coredll.lib corelibc.lib';"
Line 292: Remove "$lflags.=' /entry:mainCRTstartup' if(defined($ENV{'PORTSDK_LIBPATH'}));"
Line 293: Add "}
if ($FLAVOR =~ /CE/)
{
$lflags.=' /entry:mainCRTstartup' if(defined($ENV{'PORTSDK_LIBPATH'}));
$lflags.=' /entry:mainACRTStartup' if(defined($ENV{'WCECOMPAT'}));"
}"

Configure

First we have to set the correct environment variables (this example is for Visual Studio 2008 and perl installed with cygwin).

For X86:

set INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\atlmfc\include;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\INCLUDE;C:\Program Files\Microsoft SDKs\Windows\v6.0A\include;
set LIB=C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\ATLMFC\LIB;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\LIB;C:\Program Files\Microsoft SDKs\Windows\v6.0A\lib;
set LIBPATH=C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\ATLMFC\LIB;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\LIB;
set Path=C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN;C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\VCPackages;C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin;C:\cygwin64\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;

For ARM:

set INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\atlmfc\include;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\INCLUDE;C:\Program Files\Microsoft SDKs\Windows\v6.0A\include;
set LIB=C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\ATLMFC\LIB;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\LIB;C:\Program Files\Microsoft SDKs\Windows\v6.0A\lib;
set LIBPATH=C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\ATLMFC\LIB;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\LIB;
set Path=C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN;C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\VCPackages;C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin;C:\cygwin64\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;

Then we configure the makefiles for Windows CE. Apart from that, we’re disabling algorithms that are patented and those that are no longer considered as secure.

perl Configure no-idea no-mdc2 no-rc5 no-asm no-ssl2 no-ssl3 VC-CE

Create Makefiles

Before creating the makefiles, we have to set up our compiler toolchain for Windows CE. Remember to set the correct paths matching your own build environment.

For X86:

set OSVERSION=WCE700
set PLATFORM=VC-CE
set TARGETCPU=x86
set WCECOMPAT="C:\wcecompat-master"
set LIB=c:\Program Files (x86)\Windows CE Tools\SDKs\Unified_Automation_WCE_700\Lib\x86;C:\Program Files (x86)\Microsoft SDKs\Windows\v6.0A\lib;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\CE\LIB\x86;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\LIB
set INCLUDE=C:\Program Files (x86)\Windows CE Tools\SDKs\Unified_Automation_WCE_700\Include\X86;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\atlmfc\include;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\INCLUDE;C:\Program Files (x86)\Microsoft SDKs\Windows\v6.0A\include;
set LIBPATH="C:\Program Files (x86)\Windows CE Tools\SDKs\Unified_Automation_WCE_700\Lib\x86";C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\LIB;

For ARM:

set OSVERSION=WCE700
set PLATFORM=VC-CE
set TARGETCPU=ARMV4I
set WCECOMPAT="C:\wcecompat-master"
set LIB=C:\Program Files (x86)\Windows CE Tools\SDKs\Unified_Automation_WCE_700\Lib\ARMV4I;C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\ce\lib\ARMV4I;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\lib
set INCLUDE=C:\Program Files (x86)\Windows CE Tools\SDKs\Unified_Automation_WCE_700\Include\ARMV4I;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\atlmfc\include;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\INCLUDE;C:\Program Files\Microsoft SDKs\Windows\v6.0A\include;
set Path=C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\ce\bin\x86_arm;%Path%
set LIBPATH="C:\Program Files (x86)\Windows CE Tools\SDKs\Unified_Automation_WCE_700\Lib\ARMV4I";C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\lib;C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\ce\lib\ARMV4I;

Then run the batch file to create makefiles:

ms\do_ms.bat

Then open the makefile ms\cedll.mak and remove the compiler flag /WX.

For building in release mode, remove the following compiler options as well:

/wd4748 /wd4101

For debug mode, set the following compiler flags:

/Od /W3 /wd4748 /wd4101 /GF /Zi /Gy /GR- /Gm /EHsc /MD /fp:fast /nologo

Edit the variables CRYPTO and SSL as shown below to add a “d” at the end of the filenames:

SSL=ssleay32d
CRYPTO=libeay32d

Then open the file libeay32.def and replace the line

LIBRARY LIBEAY32

with

LIBRARY LIBEAY32d

and in the file ssleay32.def the line

LIBRARY SSLEAY32

with

LIBRARY SSLEAY32d

Compile

Now we are ready to compile the libraries. For dynamically linked libraries, enter

nmake -f ms\cedll.mak

Probably you will get errors. This is ok as long as the libraries have been built successfully.

Copy the Libraries to the SDK Folder Structure

Finally, it is necessary to copy the files to the SDK folder structure. Create a folder named
<SDK Installation Directory>\third-party\wince<6/7>\vs<version>\openssl

A similarly named folder, containing the precompiled OpenSSL binaries shipped with the SDK, should already exist below third-party.

  • Copy the complete inc32 directory to the newly created folder.
  • Copy the following files (preserving the folder structure):
    • out32dll_<x86/ARM>\libeay32.dll
      out32dll_<x86/ARM>\libeay32.lib
      out32dll_<x86/ARM>\ssleay32.dll
      out32dll_<x86/ARM>\ssleay32.lib
    • out32dll_<x86/ARM>.dbg\libeay32d.dll
      out32dll_<x86/ARM>.dbg\libeay32d.lib
      out32dll_<x86/ARM>.dbg\libeay32d.pdb
      out32dll_<x86/ARM>.dbg\ssleay32d.dll
      out32dll_<x86/ARM>.dbg\ssleay32d.lib
      out32dll_<x86/ARM>.dbg\ssleay32d.pdb