安装openssl
使用yum或者apt命令都可以安装,现在最新的系统自带的就是openssl1.1.1g
安装 GmSSL
关键点就是no-shared:只编译静态库
下载解压
# 下载 gmssl
wget https://github.com/guanzhi/GmSSL/archive/master.zip
# 解压
unzip master.zip
编译
cd GmSSL-master
# --prefix 指定 gmssl 的安装路径
# --openssldir 表示 OpenSSL 数据区域,例如openssl.cnf,证书和密钥. 如果是相对目录,它将被添加到--prefix给定的目录中。【可以不指定,默认在 --prefix 同级目录的 ssl 目录】
# no-shared 表示只编译静态库,不编译动态库
#
# 官方解释
#
# --prefix prefix for the OpenSSL installation, which includes the
# directories bin, lib, include, share/man, share/doc/openssl
# This becomes the value of INSTALLTOP in Makefile
# (Default: /usr/local)
# --openssldir OpenSSL data area, such as openssl.cnf, certificates and keys.
# If it's a relative directory, it will be added on the directory
# given with --prefix.
# This becomes the value of OPENSSLDIR in Makefile and in C.
# (Default: PREFIX/ssl)
# [no-]shared [don't] try to create shared libraries when supported.
./config --prefix=/usr/local/gmssl no-shared
安装
make
# 安装(如果有旧版本,可以使用 make uninstall 卸载,然后删除对应文件)
make install
添加环境变量
# 添加环境变量
echo 'export PATH="$PATH:/usr/local/gmssl/bin"' >> ~/.bash_profile
source ~/.bash_profile
查看版本信息(openssl 与 gmssl共存)
./config --prefix=/usr/local/gmssl no-shared no-sdf
Operating system: x86_64-whatever-linux2
Configuring for linux-x86_64
Configuring GmSSL version 2.5.4 (0x1010004fL)
no-asan [default] OPENSSL_NO_ASAN
no-crypto-mdebug [default] OPENSSL_NO_CRYPTO_MDEBUG
no-crypto-mdebug-backtrace [default] OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE
no-dynamic-engine [forced]
no-ec_nistp_64_gcc_128 [default] OPENSSL_NO_EC_NISTP_64_GCC_128
no-egd [default] OPENSSL_NO_EGD
no-fuzz-afl [default] OPENSSL_NO_FUZZ_AFL
no-fuzz-libfuzzer [default] OPENSSL_NO_FUZZ_LIBFUZZER
no-gmieng [default] OPENSSL_NO_GMIENG
no-heartbeats [default] OPENSSL_NO_HEARTBEATS
no-md2 [default] OPENSSL_NO_MD2 (skip dir)
no-msan [default] OPENSSL_NO_MSAN
no-rc5 [default] OPENSSL_NO_RC5 (skip dir)
no-sctp [default] OPENSSL_NO_SCTP
no-sdf [option] OPENSSL_NO_SDF (skip dir)
no-sdfeng [default] OPENSSL_NO_SDFENG
no-shared [option]
no-skfeng [default] OPENSSL_NO_SKFENG
no-ssl-trace [default] OPENSSL_NO_SSL_TRACE
no-ssl3 [default] OPENSSL_NO_SSL3
no-ssl3-method [default] OPENSSL_NO_SSL3_METHOD
no-ubsan [default] OPENSSL_NO_UBSAN
no-unit-test [default] OPENSSL_NO_UNIT_TEST
no-weak-ssl-ciphers [default] OPENSSL_NO_WEAK_SSL_CIPHERS
no-zlib [default]
no-zlib-dynamic [default]
Configuring for linux-x86_64
CC =gcc
CFLAG =-Wall -O3 -pthread -m64 -DL_ENDIAN -Wa,--noexecstack
SHARED_CFLAG =-fPIC -DOPENSSL_USE_NODELETE
DEFINES =DSO_DLFCN HAVE_DLFCN_H NDEBUG OPENSSL_THREADS OPENSSL_NO_DYNAMIC_ENGINE OPENSSL_PIC OPENSSL_IA32_SSE2 OPENSSL_BN_ASM_MONT OPENSSL_BN_ASM_MONT5 OPENSSL_BN_ASM_GF2m SHA1_ASM SHA256_ASM SHA512_ASM RC4_ASM MD5_ASM AES_ASM VPAES_ASM BSAES_ASM GHASH_ASM ECP_NISTZ256_ASM PADLOCK_ASM GMI_ASM POLY1305_ASM
LFLAG =
PLIB_LFLAG =
EX_LIBS =-ldl
APPS_OBJ =
CPUID_OBJ =x86_64cpuid.o
UPLINK_OBJ =
BN_ASM =asm/x86_64-gcc.o x86_64-mont.o x86_64-mont5.o x86_64-gf2m.o rsaz_exp.o rsaz-x86_64.o rsaz-avx2.o
EC_ASM =ecp_nistz256.o ecp_nistz256-x86_64.o ecp_sm2z256.o ecp_sm2z256-x86_64.o
DES_ENC =des_enc.o fcrypt_b.o
AES_ENC =aes-x86_64.o vpaes-x86_64.o bsaes-x86_64.o aesni-x86_64.o aesni-sha1-x86_64.o aesni-sha256-x86_64.o aesni-mb-x86_64.o
BF_ENC =bf_enc.o
CAST_ENC =c_enc.o
RC4_ENC =rc4-x86_64.o rc4-md5-x86_64.o
RC5_ENC =rc5_enc.o
MD5_OBJ_ASM =md5-x86_64.o
SHA1_OBJ_ASM =sha1-x86_64.o sha256-x86_64.o sha512-x86_64.o sha1-mb-x86_64.o sha256-mb-x86_64.o
RMD160_OBJ_ASM=
CMLL_ENC =cmll-x86_64.o cmll_misc.o
MODES_OBJ =ghash-x86_64.o aesni-gcm-x86_64.o
PADLOCK_OBJ =e_padlock-x86_64.o
GMI_OBJ =e_gmi-x86_64.o
CHACHA_ENC =chacha-x86_64.o
POLY1305_OBJ =poly1305-x86_64.o
BLAKE2_OBJ =
PROCESSOR =
RANLIB =ranlib
ARFLAGS =
PERL =/usr/bin/perlSIXTY_FOUR_BIT_LONG mode
Configured for linux-x86_64.
编译过程中出现的问题
1. Operating system: x86_64-whatever-linux2 “glob” is not exported by the File::Glob module Can’t continue after import errors at ./Configure line 18. BEGIN failed–compilation aborted at ./Configure line 18. “glob” is not exported by the File::Glob module Can’t continue after import errors at ./Configure line 18. BEGIN failed–compilation aborted at ./Configure line 18. This system (linux-x86_64) is not supported. See file INSTALL for details
glob相关问题
This issue is due to the Perl package File::Glob, 一些简单的修改就能修复这个. 在 Configure文件和 test/build.info这个文件,
把
use if $^O ne "VMS", 'File::Glob' => qw/glob/;
1
改成
use if $^O ne "VMS", 'File::Glob' => qw/:glob/;
1
就解决了
2. engines/afalg/e_afalg.c:110:20: error: '__NR_eventfd' undeclared (first use in this function);
加上 -DGMSSL_NO_TURBO no-afalgeng 选项
目前编译的时候默认用EC_GFp_sm2z256_method,这个实现提供超过4倍的性能提升,但是这个实现只在比较新的X86_64环境下可用,理想情况下应该判断当前硬件环境,但是目前的编译系统里面还没来得及做这个判断。
-DGMSSL_NO_TURBO可以显式指定不要用EC_GFp_sm2z256_method这个快速实现。
ec_nistp_64_gcc_128可以启用SM2的纯C优化实现,这个优化实现可以提供2倍的性能提升,可以用在所有64位的系统里面,但是需要较高版本编译器的支持,这个选项默认是不开启的,因此需要enable显式打开