Advertisement

GMSSL编译安装与VS2019环境配置

阅读量:
  1. 下载并安装 ActivePerl 5.24.0.2402,并设置环境变量
    注意:ActivePerl 5.26/5.28尚不支持

请对perl配置进行相应的修改(否则会报错libcrypto-1_1-x64.def : error LNK2001: 无法解析的外部符号 EVP_get_ciphernames)。

复制代码
    sub _warn {
    # my($msg) = @_;
    # unless (-t STDOUT) {
    # print "\n$msg\n";
    # return;
    # }
    # require Win32::Console;
    # unless ($console) {
    # $console = Win32::Console->new(Win32::Console::STD_OUTPUT_HANDLE());
    # }
    # my($col,undef) = $console->Size;
    # print "\n";
    # my $attr = $console->Attr;
    # $console->Attr($Win32::Console::FG_RED | $Win32::Console::BG_WHITE);
    # for (split(/\n/, "$msg")) {
    # $_ .= &quot; &quot; while length() < $col-1;
    # print &quot;$_\n&quot;;
    # }
    # $console->Attr($attr);
    # print &quot;\n&quot;;
    }
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
    AI写代码

gmssl里修修改源代码 crypto/evp/names2.c

复制代码
    /*
    Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
    Licensed under the OpenSSL license (the &quot;License&quot;). 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 &quot;internal/cryptlib.h&quot;
    #include <openssl/evp.h>
    #include <internal/objects.h>
    #include <openssl/x509.h>
    #include &quot;internal/evp_int.h&quot;
    
    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 &quot;sm3:sha1:sha256&quot;;
    }
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
    AI写代码

下载并安装 NASM

创建一个64位版本的项目
使用管理员权限启动Visual Studio 2019中的x64 Native Tools Command Prompt for VS2019控制台,并执行其功能

复制代码
    perl Configure VC-WIN64A
    nmake
    nmake install
    
    
      
      
      
    
    AI写代码

注:此操作需以管理员权限执行。

在VS 2019环境下进行GMssl的环境配置。为了便于统一使用和管理操作系统的相关功能,请将所有主要文件集中到一个名为Environment(ENV)的文件夹中。

将安装路径(GmSSL)中的include\openssl文件夹整个复制到Envior

为了实现GmSSL库的有效配置,在安装目录中将Lib文件夹转移至指定的环境变量位置(如:'C:\Program Files...'),其中包含两个关键 DLL 文件:'libcrypto-1_1-x64.dll' 和 'libssl-1_1-x64.dll'。

包含头文件

属性–C/C+±-常规–附加包含目录(添加目录Envior)

项目包含.lib文件所在的目录:

属性–链接器–常规–附加库目录(添加目录Envior\lib)

项目包含.lib文件

属性–链接器–输入–附加依赖项(libcrypto.lib;libssl.lib)

当配置完成后运行程序时仍出现问题,请再次检查自己的环境配置设置以排除潜在问题。作为参考尝试,请查看以下链接:

本文主要参考:
基于Windows平台运行的VS2019环境中各密码算法库(openssl、GMP、ZLib)的具体安装及使用方法
在VS2019开发环境中构建GmSSL模块的方法
针对Windows10 x64系统(版本20H2)的GMSSL编译指南

全部评论 (0)

还没有任何评论哟~