Windows平台 VS2019 编译 openssl1.1.1以及gmssl

2024-02-07 23:58

本文主要是介绍Windows平台 VS2019 编译 openssl1.1.1以及gmssl,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

前序:总结一下openssl源码在windows平台编译的问题。linux平台上相对比较简单,和其他源码编译方式一样,基本都是./configure --prefix="path" -> make ->make install完成。windows其实和linux大致是一个思路,只不过windows需要一些辅助工具,所以直观感觉就比较麻烦一点,因此做下记录,仅供大家一起学习。

openssl在版本1.1以后,编译后的库的名称都变了,和linux下保持一致了。从原来的libeay32.dll -> libcrypto.dll, ssleay32.dll -> libssl.dll。

前期的准备工作:

1:需要安装perl脚本工具(这个可以自行在网上查询相关的安装资料)

2:需要安装vs2019开发工具,这个可以直接上官网,目前vs最新版本是vs2019,首页就是了Visual Studio 2019 IDE - 适用于 Windows 的编程软件 (microsoft.com)

3:需要下载openssl源码,这个可以直接上官网,目前最新版本已经是3开头了,但是鉴于稳定性和兼容性考虑,并没有考虑去尝试它。/source/old/index.html (openssl.org)

正式开始:

1:需要打开命令行 windows+r键,敲命令cmd

2:开打vs2019开发工具的环境初始化脚本,并执行这个脚本

3:切换到openssl源码的路径

4:执行命令生成makefile文件(可以参考安装目录下的INSTALL文件)

4.1生成32位库文件

perl Configure VC-WIN32 -no-asm --prefix="D:\Program Files (x86)\openssl-1.1.1"

4.2生成64位库文件

perl Configure VC-WIN64A -no-asm --prefix="D:\Program Files (x86)\openssl-1.1.1"

5:执行makefile 文件

命令:nmake

6:执行命令测试程序

命令:nmake test

7:安装

命令:nmake install

8:如果要继续编译64位库,建议安装目录重新指定,然后记得清理编译后的目标文件

命令:nmake clean

9:编译64位(-no-shared)这个静态库编译之后不能用

二、编译gmssl版本

编译之前,先介绍下出处,这是北大的GM实验室创造,一直在维护这个版本,源码地址github.comicon-default.png?t=LA92https://github.com/guanzhi/GmSSL/archive/master.zip编译之前需要修改两处,否则后面编译会报错。

1:Configure文件,

use if $^O ne "VMS", 'File::Glob' => qw/glob/;

修改为

use if $^O ne "VMS", 'File::Glob' => qw/:glob/;

2:crypto\evp\names2.c

/** Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.** Licensed under the OpenSSL license (the "License").  You may not use* this file except in compliance with the License.  You can obtain a copy* in the file LICENSE in the source distribution or at* https://www.openssl.org/source/license.html*/#include <stdio.h>
#include "internal/cryptlib.h"
#include <openssl/evp.h>
#include <internal/objects.h>
#include <openssl/x509.h>
#include "internal/evp_int.h"/** use MD5 as default:*	X509_REQ_to_X509		x509_r2x.c*	X509_issuer_and_serial_hash	x509_cmp.c*	X509_NAME_hash_old		x509_cmp.c*	PEM_ASN1_write_bio		pem_lib.c*/
const EVP_MD *EVP_get_default_digest(void)
{
#if !defined(OPENSSL_NO_MD5)return EVP_md5();
#elif !defined(OPENSSL_NO_SHA)return EVP_sha1();
#elif !defined(OPENSSL_NO_SM3)return EVP_sm3();
#elif !defined(OPENSSL_NO_RIPEMD)return EVP_rmd160();
#elsereturn NULL;
#endif
}

修改为:

/*Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the OpenSSL license (the "License"). You may not use
this file except in compliance with the License. You can obtain a copy
in the file LICENSE in the source distribution or at
https://www.openssl.org/source/license.html
*/
#include <stdio.h>
#include "internal/cryptlib.h"
#include <openssl/evp.h>
#include <internal/objects.h>
#include <openssl/x509.h>
#include "internal/evp_int.h"const EVP_CIPHER *EVP_get_default_cipher(void)
{
return NULL;
}/*use MD5 as default:
X509_REQ_to_X509 x509_r2x.c
X509_issuer_and_serial_hash x509_cmp.c
X509_NAME_hash_old x509_cmp.c
PEM_ASN1_write_bio pem_lib.c
*/
const EVP_MD *EVP_get_default_digest(void)
{
#if !defined(OPENSSL_NO_MD5)
return EVP_md5();
#elif !defined(OPENSSL_NO_SHA)
return EVP_sha1();
#elif !defined(OPENSSL_NO_SM3)
return EVP_sm3();
#elif !defined(OPENSSL_NO_RIPEMD)
return EVP_rmd160();
#else
return NULL;
#endif
}
static void cipher_name_len(const EVP_CIPHER *cipher, const char *from,
const char *to, void *x)
{
*((int *)x) += strlen(EVP_CIPHER_name(cipher));
}static void cipher_name(const EVP_CIPHER *cipher, const char *from,
const char *to, void *x)
{
strcat((char *)x, EVP_CIPHER_name(cipher));
}char *EVP_get_ciphernames(int aliases)
{
char *ret = NULL;
int len = 0;
EVP_CIPHER_do_all_sorted(cipher_name_len, &len);ret = OPENSSL_zalloc(len);
if (!ret) {return NULL;
}EVP_CIPHER_do_all_sorted(cipher_name, ret);
return ret;
}char *EVP_get_digestnames(int aliases)
{
return "sm3:sha1:sha256";
}

接下来就可以编译了,编译方式和上述的openssl一样

perl Configure VC-WIN32 -no-asm --prefix="C:\Program Files (x86)\GmSSL-master\build"

nmake install

安装到最后,会报错perl拷贝,这个不会影响gmssl的使用,大家不要担心。

 

这篇关于Windows平台 VS2019 编译 openssl1.1.1以及gmssl的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/689322

相关文章

java使用protobuf-maven-plugin的插件编译proto文件详解

《java使用protobuf-maven-plugin的插件编译proto文件详解》:本文主要介绍java使用protobuf-maven-plugin的插件编译proto文件,具有很好的参考价... 目录protobuf文件作为数据传输和存储的协议主要介绍在Java使用maven编译proto文件的插件

Visual Studio 2022 编译C++20代码的图文步骤

《VisualStudio2022编译C++20代码的图文步骤》在VisualStudio中启用C++20import功能,需设置语言标准为ISOC++20,开启扫描源查找模块依赖及实验性标... 默认创建Visual Studio桌面控制台项目代码包含C++20的import方法。右键项目的属性:

基于Python开发Windows屏幕控制工具

《基于Python开发Windows屏幕控制工具》在数字化办公时代,屏幕管理已成为提升工作效率和保护眼睛健康的重要环节,本文将分享一个基于Python和PySide6开发的Windows屏幕控制工具,... 目录概述功能亮点界面展示实现步骤详解1. 环境准备2. 亮度控制模块3. 息屏功能实现4. 息屏时间

在Windows上使用qemu安装ubuntu24.04服务器的详细指南

《在Windows上使用qemu安装ubuntu24.04服务器的详细指南》本文介绍了在Windows上使用QEMU安装Ubuntu24.04的全流程:安装QEMU、准备ISO镜像、创建虚拟磁盘、配置... 目录1. 安装QEMU环境2. 准备Ubuntu 24.04镜像3. 启动QEMU安装Ubuntu4

Windows下C++使用SQLitede的操作过程

《Windows下C++使用SQLitede的操作过程》本文介绍了Windows下C++使用SQLite的安装配置、CppSQLite库封装优势、核心功能(如数据库连接、事务管理)、跨平台支持及性能优... 目录Windows下C++使用SQLite1、安装2、代码示例CppSQLite:C++轻松操作SQ

基于Python实现一个Windows Tree命令工具

《基于Python实现一个WindowsTree命令工具》今天想要在Windows平台的CMD命令终端窗口中使用像Linux下的tree命令,打印一下目录结构层级树,然而还真有tree命令,但是发现... 目录引言实现代码使用说明可用选项示例用法功能特点添加到环境变量方法一:创建批处理文件并添加到PATH1

Windows的CMD窗口如何查看并杀死nginx进程

《Windows的CMD窗口如何查看并杀死nginx进程》:本文主要介绍Windows的CMD窗口如何查看并杀死nginx进程问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录Windows的CMD窗口查看并杀死nginx进程开启nginx查看nginx进程停止nginx服务

Windows 系统下 Nginx 的配置步骤详解

《Windows系统下Nginx的配置步骤详解》Nginx是一款功能强大的软件,在互联网领域有广泛应用,简单来说,它就像一个聪明的交通指挥员,能让网站运行得更高效、更稳定,:本文主要介绍W... 目录一、为什么要用 Nginx二、Windows 系统下 Nginx 的配置步骤1. 下载 Nginx2. 解压

windows系统上如何进行maven安装和配置方式

《windows系统上如何进行maven安装和配置方式》:本文主要介绍windows系统上如何进行maven安装和配置方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不... 目录1. Maven 简介2. maven的下载与安装2.1 下载 Maven2.2 Maven安装2.

使用Python实现Windows系统垃圾清理

《使用Python实现Windows系统垃圾清理》Windows自带的磁盘清理工具功能有限,无法深度清理各类垃圾文件,所以本文为大家介绍了如何使用Python+PyQt5开发一个Windows系统垃圾... 目录一、开发背景与工具概述1.1 为什么需要专业清理工具1.2 工具设计理念二、工具核心功能解析2.