OpenSSL 1.1.0 中的 EVP_get_cipherbyname 和“未定义的结构/联合 evp_cipher_st”

2023-12-01

我正在尝试将 openssl 与 Visual Studio C 项目一起使用。

我使用 Visual Studio nmake 命令编译 openssl,然后使用以下命令将所有内容安装到预定义文件夹 (C:\openssl):

nmake install

文件夹结构如下:

  • bin

  • include/openssl

  • lib

include/openssl 里面有 .h 头文件。

在我的 Visual studio 2012 中,我创建了一个空的通用 C++ 项目并包含 C:\openssl\include

[Project properties -> C/C++ -> General -> Additional Include Directories]

我还添加了 lib 目录和 .lib 文件。

但是当我编译代码时,我得到

left of 'key_len' specifies undefined struct/union 'evp_cipher_st'

在我的代码中我有这些行

const EVP_CIPHER *cipher = EVP_get_cipherbyname("aes-256-cbc");
//some other code
return cipher->key_len;

查看 ossl_typ.h 文件中的 evp_cipher_st 定义,它被声明为

typedef struct evp_cipher_st EVP_CIPHER;

并且结构体没有定义!

深入研究源代码树,evp_cipher_st 是在 crypto\include\internal\evp_int.h 中定义的,该文件不包含在 openssl 安装文件夹的 include 文件夹中。

我还尝试包含 crypto\include\internal\evp_int.h 开箱即用,但它会导致更多问题。

知道如何解决这个问题吗?

UPDATE:

这是完整的功能和我的主要功能,包括所有内容:

#include <winsock2.h>
#include <Ws2tcpip.h>
#include <mswsock.h>
#include <windows.h>
#include <minwindef.h>
#include <malloc.h>
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef int socklen_t;
#include "wingetopt.h"
#include <Wincrypt.h>
#include <iphlpapi.h>
#include "Shlwapi.h"
#include <Bcrypt.h>

#define inline __inline
#define STATUS_SUCCESS 0

#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "Ws2_32.lib")
#pragma comment(lib, "Shlwapi.lib")

#include <sys/stat.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdarg.h>
#include <fcntl.h>
#include <time.h>

int generate_aes_key(const unsigned char *input_key, uint16_t input_key_size,
            unsigned char *output_key, uint16_t *outputkey_size) {

        const EVP_MD *dgst = NULL;
        unsigned char iv[EVP_MAX_IV_LENGTH];
        const EVP_CIPHER *cipher = EVP_get_cipherbyname("aes-256-cbc");

        if(!cipher) {

            return -1;
        }

        dgst = EVP_get_digestbyname("sha256");

        if(!dgst) {

            fprintf(stderr, "no such digest\n");
            return -2;
        }

        if(!EVP_BytesToKey(cipher, dgst, NULL, input_key, input_key_size, 1, output_key, iv)) {

            return -3;
        }

        *outputkey_size = (uint16_t)cipher->key_len;

        return 0;
}

int main(int argc, char *argv[]) {

    char secret[] = "MIIFBTCCAu2gAwIBAgICEAAwDQYJKoZIhvcNAQELBQAwTjELMAkGA1UEBhMCR0Ix";

    unsigned char shared_secret[500];
    uint16_t aes_keylen = 0;

    //bunch of codes 

    if(generate_aes_key((unsigned char *)secret, strlen(secret), shared_secret, &aes_keylen) < 0) {

        fprintf(stderr, "Could not get initial shared secret\n");
        return 0;
    }

    //other codes
}

Openssl 版本是:

OpenSSL_1_1_0-pre6-1266-g487d3a726

上面的版本是来自 git 的最新标签名称,我认为它是迄今为止最新鲜的一个。最新提交版本和日期如下:

487d3a726a1970e84853434561d88cb4ac212d15

作者:EasySec 日期:2017 年 1 月 17 日星期二 17:21:55 +0100

最后是 Visual Studio 2012 编译输出:

Build started 1/28/2017 8:23:02 PM.
 1>Project "C:\CODE\mycode.vcxproj" on node 2 (Build target(s)).
 1>ClCompile:
     C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\CL.exe /c /I"c:\openssl\include" /ZI /nologo /W3 /WX- /Od /Oy- /D _MBCS /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Debug\\" /Fd"Debug\vc110.pdb" /Gd /TC /analyze- /errorReport:prompt src\main.c ... 

     wingetopt.c
 1>c:\openssl\include\openssl\lhash.h(198): warning C4090: 'function' : different 'const' qualifiers
     client.c
 1>c:\openssl\include\openssl\lhash.h(198): warning C4090: 'function' : different 'const' qualifiers
     client.c
 1>c:\openssl\include\openssl\lhash.h(198): warning C4090: 'function' : different 'const' qualifiers
     client.c
 1>c:\openssl\include\openssl\lhash.h(198): warning C4090: 'function' : different 'const' qualifiers
     client.c
 1>c:\openssl\include\openssl\lhash.h(198): warning C4090: 'function' : different 'const' qualifiers
     client.c
 1>c:\openssl\include\openssl\lhash.h(198): warning C4090: 'function' : different 'const' qualifiers
     client.c
 1>c:\openssl\include\openssl\lhash.h(198): warning C4090: 'function' : different 'const' qualifiers
     client.c
 1>c:\openssl\include\openssl\lhash.h(198): warning C4090: 'function' : different 'const' qualifiers
     client.c
 1>c:\openssl\include\openssl\lhash.h(198): warning C4090: 'function' : different 'const' qualifiers
     client.c
 1>c:\openssl\include\openssl\lhash.h(198): warning C4090: 'function' : different 'const' qualifiers
     client.c
 1>c:\openssl\include\openssl\lhash.h(198): warning C4090: 'function' : different 'const' qualifiers
     client.c
 1>c:\openssl\include\openssl\lhash.h(198): warning C4090: 'function' : different 'const' qualifiers
     client.c
 1>c:\openssl\include\openssl\lhash.h(198): warning C4090: 'function' : different 'const' qualifiers
     client.c
 1>c:\openssl\include\openssl\lhash.h(198): warning C4090: 'function' : different 'const' qualifiers
     crypto.c
 1>c:\openssl\include\openssl\lhash.h(198): warning C4090: 'function' : different 'const' qualifiers
 1>c:\CODE\src\crypto.c(517): error C2037: left of 'key_len' specifies undefined struct/union 'evp_cipher_st'
     client.c
 1>c:\openssl\include\openssl\lhash.h(198): warning C4090: 'function' : different 'const' qualifiers
     client.c
 1>c:\openssl\include\openssl\lhash.h(198): warning C4090: 'function' : different 'const' qualifiers
     Generating Code...
 1>Done Building Project "C:\CODE\mycode.vcxproj" (Build target(s)) -- FAILED.

Build FAILED.

Time Elapsed 00:00:08.55

您可以获得密钥长度 using:

*outputkey_size = EVP_CIPHER_key_length(cipher);

将以下几行放在代码末尾:

printf("Key-size: %d\n", aes_keylen);
printf("Key: "); for (int i = 0; i<aes_keylen; ++i) { printf("%02x", shared_secret[i]); } printf("\n");

它打印出正确的输出,如下所示:

Key-size: 32
Key: 51ae3ac4721439302cc5f90313f440bd9ca714c9a80b2213d034c87c00a700a0

我不确定是否key_len在以前的版本中可用,但在openssl-1.10 发行说明你可以阅读:

  • Mostlibcrypto 和 libssl 公共结构变得不透明,包括:BIGNUM 和关联类型、EC_KEY 和 EC_KEY_METHOD、DH 和 DH_METHOD、DSA 和 DSA_METHOD、RSA 和 RSA_METHOD、BIO 和 BIO_METHOD、EVP_MD_CTX、EVP_MD、EVP_CIPHER_CTX、EVP_CIPHER、EVP_PKEY 和关联类型,HMAC_CTX、X509、X509_CRL、X509_OBJECT、 X509_STORE_CTX、X509_STORE、X509_LOOKUP、X509_LOOKUP_METHOD
  • libssl 内部结构变得不透明

这意味着应用程序不再被允许查看结构的变量内部。这就是 _key_len (和其他)显示未定义的原因。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

OpenSSL 1.1.0 中的 EVP_get_cipherbyname 和“未定义的结构/联合 evp_cipher_st” 的相关文章

随机推荐

  • Google Chrome 扩展:主网页中的dispatchevent

    我的扩展内容脚本中有 从内容脚本中 我尝试在主网页上调度事件 但事件没有发送 什么也没有 为了更加确定 我在所有元素中分派事件 each function i entity console log entity entity trigger
  • c将不同长度的向量绑定到数据帧

    我有一个由两个样本组成的数据框 只有一个样本回答了有关状态焦虑的调查问卷 对于这种情况 我使用以下函数 rowSums 计算了躯体状态焦虑的向量 som lp lt rowSums sample1 c 1 7 8 10 108 na rm
  • 导入模块在 Jupyter Notebook 中有效,但在 IDLE 中无效

    我不明白我做错了什么 我上周重新安装了 Windows 之后我得到了 python 3 6 和我需要的所有库 但是当我尝试在 IDLE 中导入它们时返回错误 ModuleNotFoundError 没有名为 的模块 并且当我使用 pip 在
  • 将 Null-Object 拆箱为原始类型会导致 NullPointerException,可以吗?

    这段代码抛出了一个NullPointerException因为它被拆箱为原始类型并且Long longValue 叫做 对吗 如果您有这样的片段 那就更容易看出 long value Long null But the NullPointe
  • Mvc 4 添加带有脚手架的控制器,给出错误 -“无法检索元数据...”

    尝试添加具有 CRUD 操作和 EF 的控制器时出现以下错误 无法检索 LetLord Models Tenant 的元数据 不支持使用相同的 DbCompiledModel 针对不同类型的数据库创建上下文 相反 为正在使用的每种类型的服务
  • 使用 BlueZ Stack 作为外围设备(广告商)

    Goal 使用 BlueZ 和蓝牙 4LE 适配器创建一个外围设备 宣传 Hello World 的蓝牙等效项 我在哪里 我目前已经安装并下载了 BlueZ 堆栈 我可以使用 hci 工具来识别和查看蓝牙适配器 我已经对 hciconfig
  • Highcharts - 如何减少类别之间的空间?

    我需要减少那个空间 我该怎么做 Planificaci n prioridad 和 gerencia 是类别 里面的数字是按人排列的 去做这个点填充 and 点宽是你想要的 Try this 重要的部分是 plotOptions serie
  • AVAssetReader 和音频队列流问题

    我在使用 AVAssetReader 时遇到问题 无法从 iPod 库获取样本并通过音频队列进行流式传输 我无法找到任何这样的示例 因此我尝试实现自己的示例 但似乎 AssetReader 在音频队列的回调函数处 搞砸了 具体来说 当它执行
  • iPad详细设置页面,如弹出viewController

    我想澄清的第一件事是我不是在谈论 splitview 控制器 我想要一个带有导航控制器的弹出窗口 类似于您点击键盘 gt gt 语言或邮件 gt gt 新帐户时看到的控制器 现在这不是弹出窗口控制器 有可用的标准框架吗 也许我错过了显而易见
  • 为什么 x86 寄存器如此命名?

    例如 累加器命名为EAX并且 当指令指针被调用时IP 我还知道有一些字节称为CL and DH 我知道所有的名字一定有一个约定 但是它是什么 我发现的东西 EAX Accumulator Register EBX Base Register
  • 在 Angular 2 Typescript 中使用 flow.js

    我想将 flowjs 或 ng flow 集成到我的 Angular 2 应用程序中 我已经安装了flowjs使用打字 npm install save dev types flowjs from https www github com
  • MS Access 插入大型记录集速度较慢 (VBA)

    我有一段代码创建一个新表 然后尝试将记录集值复制到该表中 唯一的问题是它非常慢并且访问在执行下面的插入部分时显示加载符号 目前 插入 500 条记录时会出现此问题 但当我获得最终数据集时 我需要插入大约 10 000 到 20 000 条记
  • Ruby on Rails - 制作新应用程序时出错(rb:55:在“require”中)

    我一直在关注 Mike Hartl 的精彩作品Ruby on Rails 教程 我必须提前对 gem 文件和 ruby 的版本做出一些决定 我决定 在让 Heroku 工作出现一些问题之后 我会直接模仿所描述的教程和 ruby 版本 让我去
  • 将 libcutils 链接到本机可执行文件[重复]

    这个问题在这里已经有答案了 我希望我的可执行文件能够调用 libcuils 支持的函数 就像property get 在 Android mk 中我有 LOCAL LDLIBS lcutils ndk build返回 未定义的引用prope
  • Android 上的时间解析问题

    尝试解析时间字符串时出现解析异常02 22 p m 我有以下转换函数 public static long convertdatetotimestamp String datestring String newdateformat Stri
  • 在同一台计算机上连接两个本地 uwp 应用程序

    我试图让两个 uwp 应用程序 Windows 10 应用程序 在同一台计算机上运行时进行通信 应用程序已经可以进行通信当运行于不同的主机 因此代码正在运行 两个应用程序都可以在其清单文件中声明的本地和公共网络中进行通信 什么时候在同一主机
  • ReactCrop 预览未渲染

    我想为我的 Web 应用程序实现图像裁剪功能 并发现 React image crop 是实现该功能的最佳 npm 包 但是 由于某种原因 ReactCrop 组件提供的预览没有在我的视口上渲染 这是我一直使用的代码 import useS
  • 使用 JQuery 导航无根 dom

    给定这个 html 字符串 var string div div p p 我用它创建一个 jQuery 对象 var dom string 是否有机会使用选择器指向其标签之一 当然 无需将其全部嵌入到新创建的项目中 dom find p 当
  • CSS:IE7 的表格和表格单元格替换

    http jsfiddle net vByVD 9 这就是我所拥有的 在大多数浏览器中 菜单看起来都是水平的 但在 IE7 及更低版本中 当然是另一回事了 它是垂直的 我发现这是因为他们不支持表格 表格单元格 我尝试了一些技巧 正如您在 C
  • OpenSSL 1.1.0 中的 EVP_get_cipherbyname 和“未定义的结构/联合 evp_cipher_st”

    我正在尝试将 openssl 与 Visual Studio C 项目一起使用 我使用 Visual Studio nmake 命令编译 openssl 然后使用以下命令将所有内容安装到预定义文件夹 C openssl nmake inst