c++ - ‘AES_ctr128_encrypt’ was not declared in this scope
问题描述
I am testing this OpenSSL AES-128 CTR mode encryption.
#include <openssl/aes.h>
#include <openssl/rand.h>
#include <stdio.h>
#include <string.h>
- Eclipse
- OpenSSL 1.1.1c (include files path added in Eclipse C/C++ build settings)
I got this error (build in C++):
../src/AES_OpenSSL_CTR.cpp:128:3: error: ‘AES_ctr128_encrypt’ was not declared in this scope.
I included openssl/aes.h already. AES_ctr128_encrypt is removed from OpenSSL 1.1.1.c? Why still not declared?
解决方案
../src/AES_OpenSSL_CTR.cpp:128:3: error: ‘AES_ctr128_encrypt’ was not declared in this scope
OpenSSL 1.1.1 and 1.1.0 only provide AES_encrypt
. It is a software only implementation. It operates on full blocks. You need to manage the counter, provide the increments, encrypt the counter, and XOR the plain text.
Instead of using the low level AES_encrypt
, you should use the EVP interfaces. The EVP algorithms use hardware acceleration when available, and combine ciphers and modes like AES-128/CTR. The function you are looking for is EVP_aes_128_ctr()
. Also see EVP Symmetric Encryption and Decryption on the OpenSSL wiki.
If you provide a Minimal, Complete, and Verifiable example, then we can say more about what you can do to fix the issue.
If you want to use AES_ctr128_encrypt
, then you need to drop back to OpenSSL 1.0.2. OpenSSL 1.1.1 and 1.1.0 no longer provide it.
$ git checkout OpenSSL_1_0_2-stable
Branch 'OpenSSL_1_0_2-stable' set up to track remote branch 'OpenSSL_1_0_2-stable' from 'origin'.
Switched to a new branch 'OpenSSL_1_0_2-stable'
$ grep -IR AES_ctr128_encrypt
util/libeay.num:AES_ctr128_encrypt 3216 EXIST::FUNCTION:AES
crypto/aes/aes.h:void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out,
crypto/aes/aes_ctr.c:void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out,
If you go back to OpenSSL 1.0.2, then see AES CTR 256 Encryption Mode of operation on OpenSSL.
Since you have a C++ program, you might be interested in EVP Encryption ... | C++ Programs on the OpenSSL wiki. It uses std::unique_ptr
and a secure_string
to manage OpenSSL resources. secure_string
is a std::basic_string
typedef with a secure allocator. It cleans up the OpenSSL C code nicely.
I am testing this OpenSSL AES-128 CTR mode encryption...
Yeah, so that is the problem with blogs (not to mention one from 2012). It is probably best to follow what the project says. The OpenSSL project says to use the EVP interfaces.
推荐阅读
- swift - 在 Cocoapod 之后,Swift 中没有这样的模块错误
- python - 通过几个函数后的参数变化 - Python
- html - 想要在视差区域上使文本 div 透明
- python - 如何将 django 模型导出到按特定列排序的 pandas 数据框
- azure - 构建 ActorService 时 DotNet 命令退出并出现错误代码
- swift - 如何使用 SwiftUI 将我的按钮粘贴到视图底部?
- python - 使用 Python 将大数据加载到 List
- rest - RESTful API 身份验证和 SSO 与 OAuth2 / OIDC
- python-3.x - 如何从带有坐标的pdf图像文件中提取数据?
- android - 如何在 mapactivity 中正确导入 android support v4