OpenSSL for Windows

In earlier articles, we have looked at how to create a gcc build environment on Windows, and also how tocompile binaries for Windows on Linux, using the MinGW-w64 suite to be able to support native 64-bit Windows builds.

But in order to build useful applications in these environments, we often need some common libraries. In this article, we will have a look at how to compile the OpenSSL library and make a small application that uses it. Compiled OpenSSL libraries are available for download (see the link at the bottom), in case you don’t want to do the compilation yourself.

prerequisites

We will be cross-compiling from Linux. If you want to use Windows only, please consider downloading the compiled OpenSSL binaries near the bottom of the page, or adjust the paths accordingly when building the library.

I have my 64-bit Windows build environment installed in /opt/mingw64, and the cross-compiler prefix is x86_64-w64-mingw32. I will target (build binaries for) 64-bit Windows in this article. Please adjust these variables according to your own build environment. i686-w64-mingw32 is the prefix for the 32-bit Windows cross-compiler.

compiling openssl

  1. Follow the simple instructions on how to set up a Windows build environment on Linux. It is also possible to do this on Windows, but it is simpler and faster using Linux. Please leave a comment if you would like me to describe how to build on Windows.
  2. Grab the desired OpenSSL source tarball. Use OpenSSL version 1.0.0 or newer; OpenSSL versions older than v1.0.0 are a bit harder to build on Windows, but let me know if you want to see how to do this.  I’ll use OpenSSL version 1.0.0e in the following, but the steps should be identical for any version newer than 1.0.0.
  3. Put your tarball in a temporary directory, e.g. /tmp and unpack it:
    $ tar zxvf openssl-1.0.0e.tar.gz
  4. Run the configure script to use the 64-bit Windows compiler.
    $ cd openssl-1.0.0e
    $ CROSS_COMPILE="x86_64-w64-mingw32-" ./Configure mingw64 no-asm shared --prefix=/opt/mingw64


    Configured for mingw64.
  5. Compile. Make sure the the cross-compiler is in your path, or add it explicitly as show below.
    $ PATH=$PATH:/opt/mingw64/bin make
  6. Install it.
    $ sudo PATH=$PATH:/opt/mingw64/bin make install

We now have the OpenSSL libraries and headers for 64-bit Windows installed. Repeat the steps above with CROSS_COMPILE="i686-w64-mingw32-" and prefix /opt/mingw32 to build and install the 32-bit libraries for Windows.

a simple application

To confirm OpenSSL is working correctly, let’s create  a small C application that generates a SHA-256 digest of a character string. It reads a string given as the argument, generates the digest and shows the computed digest. The digest-generating code is shown below, while the complete code is available for download.

void SHA256Hash(unsigned char digest[EVP_MAX_MD_SIZE], char *stringToHash)
{
OpenSSL_add_all_digests();

const EVP_MD *md = EVP_get_digestbyname(“sha256”);

EVP_MD_CTX context;
EVP_MD_CTX_init(&context);
EVP_DigestInit_ex(&context, md, NULL);
EVP_DigestUpdate(&context, (unsigned char *)stringToHash, strlen(stringToHash));

unsigned int digestSz;
EVP_DigestFinal_ex(&context, digest, &digestSz);
EVP_MD_CTX_cleanup(&context);

EVP_cleanup();
}

  1. Save the file sha256.cin a working directory.
  2. Compile it.
    $ /opt/mingw64/bin/x86_64-w64-mingw32-gcc -I/opt/mingw64/include -L/opt/mingw64/lib -Wall sha256.c -lcrypto -o sha256.exe
  3. Check that the executable has the correct binary format (PE32+ is 64-bit).
    $ file sha256.exe
    sha256.exe: PE32+ executable for MS Windows (console) Mono/.Net assembly
  4. Copy our new program to a 64-bit Windows machine, and run it in the Windows Command Prompt.
    > sha256.exe 12345

The last step should generate the following dialog box, which contains the SHA-256 digest of the string “12345”.

openssl windows binaries

In case you don’t want to compile the OpenSSL library yourself, I have compiled version 1.0.0e and made it available for download below.

Just unpack each tarball to your respective MinGW-w64 installation directory. They should work both if you are running the gcc compiler on Windows, as well as cross-compiling for Windows like we have done above.

Please leave a comment if you found this interesting or have suggestions for improvements!

http://www.blogcompiler.com/2011/12/21/openssl-for-windows/

http://www.blogcompiler.com/2010/07/11/compile-for-windows-on-linux/

Compile for Windows on Linux(交叉编译,在Linux下编译Windows程序),以OpenSSL为例的更多相关文章

  1. 如何在Kali Linux下编译Windows Exploit

    前言 微软的Windows在企业或是个人应用领域占据着最大的市场份额,在渗透测试过程中你会经常遇到很多Windows的工作站和服务器.另一方面,大多数渗透测试人员主要使用基于Linux的发行版渗透测试 ...

  2. Fedora 11中用MinGW编译Windows的Qt4程序(在Linux系统下编译Windows的程序)

    Ubuntu下可以直接安装: sudo apt-get install mingw32 mingw32-binutils mingw32-runtime 安装后编译程序可以: i586-mingw32 ...

  3. 在虚拟机linux环境下编译windows版adb fastboot

    原文出自:http://blog.chinaunix.net/uid-20546441-id-1746200.html 我根据虚拟机编译遇到的问题进行一些添加 [前提条件] Linux Android ...

  4. Mingw:在Linux系统下编译Windows的程序

    Ubuntu下可以直接安装: sudo apt-get install mingw32 mingw32-binutils mingw32-runtime 安装后编译程序可以: i586-mingw32 ...

  5. [原创] linux deepin 2014.1下编译putty

    在网上找了很久,都没有找到linux下直接可以用的putty程序,最终在putty官网找到了源代码 点击下载 把源代码下载回来. 1.下载源代码 2.安装依赖库 如果系统中没有安装过libgtk2.0 ...

  6. [C++]Linux之Ubuntu下编译C程序出现错误:“ stray ‘\302'或者'\240' in program”的解决方案

    参考文献:[error: stray ‘\240’ in program或 error: stray ‘\302’ in program](http://blog.csdn.net/u01299585 ...

  7. linux环境下编译C++ 程序

    GCC(GNU Compiler Collection)是Linux下最主要的编译工具,GCC不仅功能非常强大,结构也异常灵活.它可以通过不同的前端模块来支持各种语言,如:Java.Fortran.P ...

  8. 在linux下编译线程程序undefined reference to `pthread_create'

    由于是Linux新手,所以现在才开始接触线程编程,照着GUN/Linux编程指南中的一个例子输入编译,结果出现如下错误:undefined reference to 'pthread_create'u ...

  9. Ubantu Linux 环境下编译c++程序

    先在文件中新建一个a.cpp文件,在里面编写程序, 然后打开终端输入下面命令即可; $ g++ a.cpp -o b ///编译a.cpp 然后把编译之后的.exe文件存入b中 $ ./b ///执行 ...

随机推荐

  1. NOIP模拟 拆网线 - 贪心策略+dp

    题目大意: 给一颗n个节点的树,保留最少的边,使得每个连通块的大小都大于等于2,并且连通块的点数和等于k. 题目分析: 要想留下的边数最少,就要尽量多的选择单独的边,这里就要贪心:尽可能多的选择单独的 ...

  2. NOIP模拟 cube - 数学

    题目原文: 豆豆还是觉得自己智商太低了,就又去做数学题了.一看到题,他就觉得自己可能真的一点智商都没有.便哭着跑来像 dalao 求教:如果存在正整数 A,B ,满足 A3 - B3 = x ,则称质 ...

  3. Kail Linux渗透测试培训手册3第二章信息采集

    Kail Linux渗透测试培训手册3第二章信息采集 信息收集是网络攻击中最重要的步骤之一.渗透攻击.我们需要收集各种信息目标.该信息收集.攻击成功的概率越大.介绍信息收集的相关工具.本文选自< ...

  4. win32命令行小程序获取指定文件夹或者目录下面的所有文件大小,文件数量,目录数量

    #include <Windows.h> #include <stdio.h> #include <tchar.h> LARGE_INTEGER       lgA ...

  5. 【45.61%】【codeforces 701D】As Fast As Possible

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. C# 创建文件释放 Dispose()

    System.IO.File.Create("文件路径") 前提确保有此路径, 否则会报错 本以为创建文件是会自动释放的, 结果没有自动释放 , fs.Write(response ...

  7. vue 遇到的问题

    1.v-show与v-if 在对数据进行显示的时候尽量选择用v-if,v-if对应的则是由生命周期,而对于v-show没有生命周期的切换,大多数使用在ui层的切换,display:none 2.com ...

  8. 关闭Wind XP/Vista/Win7的DEP数据执行保护汇总(转)

    数据执行保护 (DEP) 是一种Windows安全机制,从Windows版本顺序上看是从Windows XP SP2开始引入,通过监视程序以确保它们使用的系统内存是安全的,帮助防止操作系统受到病毒和其 ...

  9. 升级cocoapods 0.36.0之后,解决更新的部分依赖库,不是最新版本号的问题

    在升级到cocoapods 0.36.0之后,使用原本podfile配置,在又一次运行pod install之后,一些依赖库的版本号,低于github上的最新版本号.可依照下列配置.指定git,强制使 ...

  10. 动态加载Layout

    因为现在手头上做的需要显示很多不同布局,想着拆分开来不要全部都写到main.xml里,于是就想到动态加载Layout 目前试了下, LinearLayout page = (LinearLayout) ...