OpenSSL Windows Build

Introduction

This tutorial shows how to build OpenSSL on Windows for Visual Studio.

After building the OpenSSL libraries we will also write a small program that uses them and show how we can step into the OpenSSL code with the debugger.

Getting the source code

Instructions on getting the OpenSSL source code can be found at https://www.openssl.org/source/gitrepo.html.

The source code is stored in a Git repository. The official repository is git://git.openssl.org/openssl.git but a copy that is constantly kept up-to-date is also available on GitHub at https://github.com/openssl/openssl.

Clone the repository from the location of your choice. For instance the command below clone the repository from git://git.openssl.org/openssl.git.

Cloning the OpenSSL Git repository

git clone git://git.openssl.org/openssl.git

If you are not familiar with using Git on Windows, you can read our Git Tutorial.

Required tools

In addition to a version of Visual Studio the following tools are required.

Perl

The OpenSSL build system uses Perl scripts so you need a Perl interpreter. A good option on Windows is to use ActivePerl from ActiveState. Make sure the interpreter is your path.

NASM

Some of the source files are written in assembly code for the NASM assembler. You can download it from http://www.nasm.us/. Make sure nasm.exe is in your path.

It is possible to avoid using NASM but installing it is trivial so there isn't necessarily a reason to try avoiding it.

32-bit static library build

Once the required tools described previously have been installed and the Git repository cloned we can start the build.

Note that the build process is rather fragile and it is important to start from a clean slate and execute the right commands. As a quick reminder here are a few Git commands that can be useful.

Useful Git commands

git status --ignored     // to see whether the local copy is in a clean state
git reset --hard         // to revert any changes made to files in the repository
git clean -fdx           // to remove any new files and directories

To perform a command-line build using Visual Studio the appropriate environment variables need to be set as explained in MSDN: Setting the Path and Environment Variables for Command-Line Builds [1].

In this case we are using Visual Studio 2013 and performing a 32-bit build so we can use the VS2013 x86 Native Tools Command Prompt shortcut in C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\Shortcuts to get a command prompt with the required environment variables set.

Now that we have a properly setup command prompt we go to the directory where we cloned the OpenSSL repository and execute the following commands.

C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC>cd c:\GitRepositories\openssl

c:\GitRepositories\openssl>perl Configure VC-WIN32 --prefix=C:\OpenSSL32Static
Configuring for VC-WIN32
    no-deprecated   [default]  OPENSSL_NO_DEPRECATED (skip dir)
    no-ec_nistp_64_gcc_128 [default]  OPENSSL_NO_EC_NISTP_64_GCC_128 (skip dir)
    no-jpake        [experimental] OPENSSL_NO_JPAKE (skip dir)
    no-md2          [default]  OPENSSL_NO_MD2 (skip dir)
    no-rc5          [default]  OPENSSL_NO_RC5 (skip dir)
    no-sctp         [default]  OPENSSL_NO_SCTP (skip dir)
    no-shared       [default]
    no-ssl-trace    [default]  OPENSSL_NO_SSL_TRACE (skip dir)
    no-store        [experimental] OPENSSL_NO_STORE (skip dir)
    no-unit-test    [default]  OPENSSL_NO_UNIT_TEST (skip dir)
    no-zlib         [default]
    no-zlib-dynamic [default]
IsMK1MF=1
CC            =cl
CFLAG         =-DOPENSSL_THREADS  -DDSO_WIN32 -W3 -wd4090 -Gs0 -GF -Gy -nologo -
DOPENSSL_SYS_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -D_CRT_SECURE_NO_DEPRECATE -
DOPENSSL_BN_ASM_PART_WORDS -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_B
N_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DRMD160_ASM -DAES_ASM
 -DVPAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM
EX_LIBS       =
CPUID_OBJ     =x86cpuid.o
BN_ASM        =bn-586.o co-586.o x86-mont.o x86-gf2m.o
EC_ASM        =ecp_nistz256.o ecp_nistz256-x86.o
DES_ENC       =des-586.o crypt586.o
AES_ENC       =aes-586.o vpaes-x86.o aesni-x86.o
BF_ENC        =bf-586.o
CAST_ENC      =c_enc.o
RC4_ENC       =rc4-586.o
RC5_ENC       =rc5-586.o
MD5_OBJ_ASM   =md5-586.o
SHA1_OBJ_ASM  =sha1-586.o sha256-586.o sha512-586.o
RMD160_OBJ_ASM=rmd-586.o
CMLL_ENC      =cmll-x86.o
MODES_OBJ     =ghash-x86.o
ENGINES_OBJ   =e_padlock-x86.o
CHACHA_ENC    =chacha_enc.o
POLY1305_OBJ  =
PROCESSOR     =
RANLIB        =true
ARFLAGS       =
PERL          =perl
THIRTY_TWO_BIT mode
BN_LLONG mode
RC4_INDEX mode
RC4_CHUNK is undefined

Configured for VC-WIN32.

c:\GitRepositories\openssl>ms\do_nasm.bat

c:\GitRepositories\openssl>perl util\mkfiles.pl  1>MINFO

c:\GitRepositories\openssl>perl util\mk1mf.pl nasm VC-WIN32  1>ms\nt.mak

c:\GitRepositories\openssl>perl util\mk1mf.pl dll nasm VC-WIN32  1>ms\ntdll.mak


c:\GitRepositories\openssl>perl util\mk1mf.pl nasm BC-NT  1>ms\bcb.mak

c:\GitRepositories\openssl>perl util\mkdef.pl 32 libeay  1>ms\libeay32.def

c:\GitRepositories\openssl>perl util\mkdef.pl 32 ssleay  1>ms\ssleay32.def

c:\GitRepositories\openssl>nmake -f ms\nt.mak
tmp32 object files out32 the newly built binaries
c:\GitRepositories\openssl>nmake -f ms\nt.mak install

Microsoft (R) Program Maintenance Utility Version 12.00.21005.1
Copyright (C) Microsoft Corporation.  All rights reserved.

Building OpenSSL
        perl util/mkdir-p.pl "C:\OpenSSL32Static"
created directory `C:/OpenSSL32Static'
        perl util/mkdir-p.pl "C:\OpenSSL32Static\bin"
created directory `C:/OpenSSL32Static/bin'
        perl util/mkdir-p.pl "C:\OpenSSL32Static\include"
created directory `C:/OpenSSL32Static/include'
        perl util/mkdir-p.pl "C:\OpenSSL32Static\include\openssl"
created directory `C:/OpenSSL32Static/include/openssl'
        perl util/mkdir-p.pl "C:\OpenSSL32Static\lib"
created directory `C:/OpenSSL32Static/lib'
        perl util/copy.pl "include\openssl\*.[ch]" "C:\OpenSSL32Static\include\o
penssl"
Copying: include/openssl/aes.h to C:/OpenSSL32Static/include/openssl/aes.h
Copying: include/openssl/asn1.h to C:/OpenSSL32Static/include/openssl/asn1.h
Copying: include/openssl/asn1t.h to C:/OpenSSL32Static/include/openssl/asn1t.h
Copying: include/openssl/async.h to C:/OpenSSL32Static/include/openssl/async.h
Copying: include/openssl/bio.h to C:/OpenSSL32Static/include/openssl/bio.h
Copying: include/openssl/blowfish.h to C:/OpenSSL32Static/include/openssl/blowfi
sh.h
Copying: include/openssl/bn.h to C:/OpenSSL32Static/include/openssl/bn.h
Copying: include/openssl/buffer.h to C:/OpenSSL32Static/include/openssl/buffer.h

Copying: include/openssl/camellia.h to C:/OpenSSL32Static/include/openssl/camell
ia.h
Copying: include/openssl/cast.h to C:/OpenSSL32Static/include/openssl/cast.h
Copying: include/openssl/cmac.h to C:/OpenSSL32Static/include/openssl/cmac.h
Copying: include/openssl/cms.h to C:/OpenSSL32Static/include/openssl/cms.h
Copying: include/openssl/comp.h to C:/OpenSSL32Static/include/openssl/comp.h
Copying: include/openssl/conf.h to C:/OpenSSL32Static/include/openssl/conf.h
Copying: include/openssl/conf_api.h to C:/OpenSSL32Static/include/openssl/conf_a
pi.h
Copying: include/openssl/crypto.h to C:/OpenSSL32Static/include/openssl/crypto.h

Copying: include/openssl/des.h to C:/OpenSSL32Static/include/openssl/des.h
Copying: include/openssl/dh.h to C:/OpenSSL32Static/include/openssl/dh.h
Copying: include/openssl/dsa.h to C:/OpenSSL32Static/include/openssl/dsa.h
Copying: include/openssl/dso.h to C:/OpenSSL32Static/include/openssl/dso.h
Copying: include/openssl/dtls1.h to C:/OpenSSL32Static/include/openssl/dtls1.h
Copying: include/openssl/e_os2.h to C:/OpenSSL32Static/include/openssl/e_os2.h
Copying: include/openssl/ebcdic.h to C:/OpenSSL32Static/include/openssl/ebcdic.h

Copying: include/openssl/ec.h to C:/OpenSSL32Static/include/openssl/ec.h
Copying: include/openssl/ecdh.h to C:/OpenSSL32Static/include/openssl/ecdh.h
Copying: include/openssl/ecdsa.h to C:/OpenSSL32Static/include/openssl/ecdsa.h
Copying: include/openssl/engine.h to C:/OpenSSL32Static/include/openssl/engine.h

Copying: include/openssl/err.h to C:/OpenSSL32Static/include/openssl/err.h
Copying: include/openssl/evp.h to C:/OpenSSL32Static/include/openssl/evp.h
Copying: include/openssl/hmac.h to C:/OpenSSL32Static/include/openssl/hmac.h
Copying: include/openssl/idea.h to C:/OpenSSL32Static/include/openssl/idea.h
Copying: include/openssl/jpake.h to C:/OpenSSL32Static/include/openssl/jpake.h
Copying: include/openssl/lhash.h to C:/OpenSSL32Static/include/openssl/lhash.h
Copying: include/openssl/md2.h to C:/OpenSSL32Static/include/openssl/md2.h
Copying: include/openssl/md4.h to C:/OpenSSL32Static/include/openssl/md4.h
Copying: include/openssl/md5.h to C:/OpenSSL32Static/include/openssl/md5.h
Copying: include/openssl/mdc2.h to C:/OpenSSL32Static/include/openssl/mdc2.h
Copying: include/openssl/modes.h to C:/OpenSSL32Static/include/openssl/modes.h
Copying: include/openssl/obj_mac.h to C:/OpenSSL32Static/include/openssl/obj_mac
.h
Copying: include/openssl/objects.h to C:/OpenSSL32Static/include/openssl/objects
.h
Copying: include/openssl/ocsp.h to C:/OpenSSL32Static/include/openssl/ocsp.h
Copying: include/openssl/opensslconf.h to C:/OpenSSL32Static/include/openssl/ope
nsslconf.h
Copying: include/openssl/opensslv.h to C:/OpenSSL32Static/include/openssl/openss
lv.h
Copying: include/openssl/ossl_typ.h to C:/OpenSSL32Static/include/openssl/ossl_t
yp.h
Copying: include/openssl/pem.h to C:/OpenSSL32Static/include/openssl/pem.h
Copying: include/openssl/pem2.h to C:/OpenSSL32Static/include/openssl/pem2.h
Copying: include/openssl/pkcs12.h to C:/OpenSSL32Static/include/openssl/pkcs12.h

Copying: include/openssl/pkcs7.h to C:/OpenSSL32Static/include/openssl/pkcs7.h
Copying: include/openssl/pqueue.h to C:/OpenSSL32Static/include/openssl/pqueue.h

Copying: include/openssl/rand.h to C:/OpenSSL32Static/include/openssl/rand.h
Copying: include/openssl/rc2.h to C:/OpenSSL32Static/include/openssl/rc2.h
Copying: include/openssl/rc4.h to C:/OpenSSL32Static/include/openssl/rc4.h
Copying: include/openssl/rc5.h to C:/OpenSSL32Static/include/openssl/rc5.h
Copying: include/openssl/ripemd.h to C:/OpenSSL32Static/include/openssl/ripemd.h

Copying: include/openssl/rsa.h to C:/OpenSSL32Static/include/openssl/rsa.h
Copying: include/openssl/safestack.h to C:/OpenSSL32Static/include/openssl/safes
tack.h
Copying: include/openssl/seed.h to C:/OpenSSL32Static/include/openssl/seed.h
Copying: include/openssl/sha.h to C:/OpenSSL32Static/include/openssl/sha.h
Copying: include/openssl/srp.h to C:/OpenSSL32Static/include/openssl/srp.h
Copying: include/openssl/srtp.h to C:/OpenSSL32Static/include/openssl/srtp.h
Copying: include/openssl/ssl.h to C:/OpenSSL32Static/include/openssl/ssl.h
Copying: include/openssl/ssl2.h to C:/OpenSSL32Static/include/openssl/ssl2.h
Copying: include/openssl/ssl3.h to C:/OpenSSL32Static/include/openssl/ssl3.h
Copying: include/openssl/stack.h to C:/OpenSSL32Static/include/openssl/stack.h
Copying: include/openssl/store.h to C:/OpenSSL32Static/include/openssl/store.h
Copying: include/openssl/symhacks.h to C:/OpenSSL32Static/include/openssl/symhac
ks.h
Copying: include/openssl/tls1.h to C:/OpenSSL32Static/include/openssl/tls1.h
Copying: include/openssl/ts.h to C:/OpenSSL32Static/include/openssl/ts.h
Copying: include/openssl/txt_db.h to C:/OpenSSL32Static/include/openssl/txt_db.h

Copying: include/openssl/ui.h to C:/OpenSSL32Static/include/openssl/ui.h
Copying: include/openssl/whrlpool.h to C:/OpenSSL32Static/include/openssl/whrlpo
ol.h
Copying: include/openssl/x509.h to C:/OpenSSL32Static/include/openssl/x509.h
Copying: include/openssl/x509_vfy.h to C:/OpenSSL32Static/include/openssl/x509_v
fy.h
Copying: include/openssl/x509v3.h to C:/OpenSSL32Static/include/openssl/x509v3.h

        perl util/copy.pl "out32\openssl.exe C:\OpenSSL32Static\bin"
Copying: out32/openssl.exe to C:/OpenSSL32Static/bin/openssl.exe
        perl util/mkdir-p.pl "C:\OpenSSL32Static\ssl"
created directory `C:/OpenSSL32Static/ssl'
        perl util/copy.pl apps\openssl.cnf "C:\OpenSSL32Static\ssl"
Copying: apps/openssl.cnf to C:/OpenSSL32Static/ssl/openssl.cnf
        perl util/copy.pl "out32\ssleay32.lib" "C:\OpenSSL32Static\lib"
Copying: out32/ssleay32.lib to C:/OpenSSL32Static/lib/ssleay32.lib
        perl util/copy.pl "out32\libeay32.lib" "C:\OpenSSL32Static\lib"
Copying: out32/libeay32.lib to C:/OpenSSL32Static/lib/libeay32.lib

c:\GitRepositories\openssl>

References

  1. MSDN: Setting the Path and Environment Variables for Command-Line Builds

Further Reading

  1. p-nand-q.com: Building OpenSSL with Visual Studio
  2. Covenant Eyes Developer Portal: Building OpenSSL for Visual Studio

Copyright(c) 2006-2017 Xavier Leclercq | Privacy policy

Home
Contact Us
Search