Windows编译GmSSL库

编译过程
①首先下载GmSSL源码,GmSSL的基本信息可以在这里查看:http://gmssl.org/,下载地址为:https://github.com/guanzhi/GmSSL。
②准备编译环境,首先需要安装ActivePerl,下载地址为:https://www.activestate.com/products/perl/downloads/,安装时注意将环境变量勾上,这样可以避免安装完成后设置环境变量。然后需要安装NASM,下载地址为:https://www.nasm.us/pub/nasm/releasebuilds/?C=M;O=D,注意安装完成之后需要手动设置环境变量。
③开始编译。打开VS Tools中的命令提示符,切换到GmSSL目录下,如果是编译32位的库,则命令为perl Configure VC-WIN32,如果编译的是64位的库,则命令为perl Configure VC-WIN64A。执行完成之后,输入nmake编译,完成之后,输入nmake install运行,完成即可。

遇到的问题
①提示NASM未找到,这是因为安装nasm时默认并没有添加环境变量,需要手动添加环境变量。
②在执行nmake时遇到错误,如下所示:

libcrypto.* libcrypto-1_1.* && EXIT 1)
libcrypto-1_1.def : error LNK2001: 无法解析的外部符号 EVP_get_ciphernames
libcrypto-1_1.def : error LNK2001: 无法解析的外部符号 EVP_get_digestnames
libcrypto.lib : fatal error LNK1120: 2 个无法解析的外部命令
NMAKE : fatal error U1077: “link”: 返回代码“0x1”

这个问题网上的大神都说找旧版本的names2.c(\GmSSL\crypto\evp)替换掉新版本中对应的文件,重新编译即可,确实是这样的,但是这个文件在Git上真的不好找,我找了很久,下面把这个文件全部贴出来,如下所示:

/*
 * 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"

// 不同的cipher属性不同,似乎不能像MD那样简单处理
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";
}

注意在网页上复制下去保存文件的时候,文件格式要用ANSI的,不然编译时会提示找到"{",但是没有对应的"}"。
③其他错误暂时没有遇到,目前编译64位的库完成。

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值