Building an OpenSSL Static Binary with the Borland 32-bit C++ Compiler v5.5
A Little Background
Long, long ago, in a galaxy far, far away lived a cool tool called Turbo C++. Sometime in the early '90s Turbo C++ acquired a new sibling called Borland C++. Then about the mid-90s this thang called the Internet started gaining steam, and some of us moved on to creating constructs called web pages using tools classified as dynamic languages, and we lost touch with an old venerable friend...
When I need to create native, C-based tools on the Windows environment these days, I tend to use MinGW typically, either the from the distribution itself or more often as a subcomponent of the Strawberry Perl distribution assuming MSYS or the automake functionality is not required. Recently, I was curious about the Borland tools and found out that Embarcadero makes the command line version of the compiler available for a registration and download at this web address.
For a BCC32 test project, I wanted to create an OpenSSL static binary to keep on a pen drive for quick and easy access when I'm on other WinTel boxen. There were several hiccups along the way but nothing too major. Here are the general steps I took to build it.
Prerequisites
Tools
- Borland 32-bit Command Line Compiler v5.5
- Perl
- OpenSSL version 1.0.0e source code.
Note/Warning: OpenSSL uses cryptology and may not be legal to build, export, or use in certain countries.
Environment Settings
The Borland tools and Perl should be the environmental path. I also needed to create a bcc32.cfg and ilink32.cfg.
First things first. Open up that console, or DOS Prompt if you prefer, and set the environment variables for the Borland compiler and Perl.
- set path=%path%;c:\Borland\BCC55\Bin;c:\perl\bin
Here We Go
Navigate to the top of the OpenSSL source tree, for this release the default directory from the gzipped tarball was openssl-1.0.0.e.
Run the following commands and/or perform the following edits...
- perl Configure BC-32 no-asm
- ms\do_nasm.bat
- Edit ms\bcb.mak to add one additional import library. Find the EX_LIBS lines. Two lines of accompanying comments are show for location purposes.
# add extra libraries to this define, for solaris -lsocket -lnsl would
# be added
EX_LIBS=cw32mt.lib import32.lib
# add extra libraries to this define, for solaris -lsocket -lnsl would
# be added
EX_LIBS=cw32mt.lib import32.lib crypt32.lib
- Edit crypto\bio\bss_dgram.c (around line 822) and edit ssl\d1_lib.c (around line 417)
struct _timeb tb;
_ftime(&tb);
struct timeb tb;
ftime(&tb);
- Edit crypto\rand\randfile.c (around line 210)
int fd = open(file, O_WRONLY|O_CREAT|O_BINARY, 0600);
/*
int fd = open(file, O_WRONLY|O_CREAT|O_BINARY, 0600);
*/
int fd = open(file, O_WRONLY|O_CREAT|O_BINARY);
In the following steps we'll need to create a C header file for the IPv6 data type declarations.
- Create a new header file in the apps directory. I called mine _in6addr.h. Hence, apps/_in6addr.h
#ifndef _A_SCARY_HACK_FOR_IN6_ADDR_H
#define _A_SCARY_HACK_FOR_IN6_ADDR_H
/*
* Source code obtained from
* http://msdn.microsoft.com/en-us/library/windows/desktop/ms738560%28v=vs.85%29.aspx
*
* and modified...
*
*/
typedef struct in6_addr {
union {
u_char Byte[16];
u_short Word[8];
} u;
/*} IN6_ADDR, *PIN6_ADDR, FAR *LPIN6_ADDR;*/
};
#endif
- Edit apps\s_cb.c and add the include for the new header file _in6addr.h.
- [Optional] My personal preference since I'm not using any of the Certificate Authority functionality. Edit apps\openssl.c (around line 331) and comment out the warning.
BIO_printf(bio_err,
"WARNING: can't open config file: %sn",p);
/*
BIO_printf(bio_err,
"WARNING: can't open config file: %sn",p);
*/
Finally. We get to the good part.
- make -f msbcb.mak
- cd out32
- openssl.exe
You should have a static openssl.exe binary and which weighs in at about 1.8MB. I ran UPX on the binary and squeezed it down to around 600-700 KB.
Cheers
| The Matrix Management |
| Computer Dating |
| Pachyderm Phobias |
| Hackathon |
| MVC Architecture |
| Pair Programming |
| Bugs |