使用 mbedtls 的 AES-CMAC:未定义的引用错误
AES-CMAC using mbedtls: undefined reference error
我尝试使用mbedTLS实现AES-CMAC。我收到一些错误:
对
mbedtls_cipher_cmac_starts
的未定义引用,对mbedtls_cipher_cmac_update
的未定义引用,对mbedtls_cipher_cmac_finish
的未定义引用,
为什么这些功能无法解决,即使mbedtls_cipher_init
和mbedtls_cipher_setup
可以解决?
顺便说一句。我在同一项目下使用 mbedTLS 实现了 AES,没有问题。我使用 Eclipse Nano。
这是我的代码:
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "openssl/evp.h"
#include "openssl/cmac.h"
#include "mbedtls/cmac.h"
#include "mbedtls/cipher.h"
using namespace std;
unsigned char key[16]={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
int main()
{
unsigned char m[100],m_len=32;
unsigned char out[16],out1[16],out2[16];
size_t d_len;
int i,ret;
mbedtls_cipher_context_t m_ctx;
const mbedtls_cipher_info_t *cipher_info;
cipher_info = mbedtls_cipher_info_from_type( MBEDTLS_CIPHER_AES_128_ECB );
if(cipher_info==NULL)
printf("nmbedtls_cipher_info_from_type failed");
mbedtls_cipher_init(&m_ctx);
ret=mbedtls_cipher_setup( &m_ctx, cipher_info );
printf("n mbedtls_cipher_setup returned %d %d",ret, m_ctx.cipher_info->type);
ret=mbedtls_cipher_cmac_starts(&m_ctx,key,128);
printf("n mbedtls_cipher_cmac_starts returned %d",ret);
ret= mbedtls_cipher_cmac_update(&m_ctx, m,m_len);
printf("n mbedtls_cipher_cmac_update returned %d",ret);
ret=mbedtls_cipher_cmac_finish(&m_ctx,out1);
printf("n mbedtls_cipher_cmac_starts returned %d",ret);
d_len=16;
printf("nLength is %dn",(int)d_len);
for(i=0;i<d_len;i++)
{
printf("%x ",out1[i]);
}
return 0;
}
无论出于何种原因,CMAC 在默认配置中处于禁用状态。如果找到其他加密函数,但找不到 CMAC 函数,则一定是因为生成中未包含 CMAC 函数。
编辑config.h
以取消注释#define MBEDTLS_CMAC_C
并重建库。
相关文章:
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- C++引用错误
- 已定义函数时出现 G++ "未定义的引用"错误
- 链接 cmake 时出现未定义的引用错误
- 只有级联分类器会发出未定义的引用错误
- 2个模板化类的非模板友元函数未定义引用错误
- C/C++ 取消引用错误:在空检查之前取消引用
- 为什么我的C++代码无法编译,出现未定义的引用错误
- 我的代码中C++未定义的引用错误?
- 模板专用化会导致未定义的引用错误
- .cpp文件中未定义的引用错误
- c++ 中目录中文件的未定义引用错误
- Opencv4 使用 pkg-config 给出未定义的引用错误
- 使用Cygwin C++时出现未定义的引用错误,为什么我的文件没有链接?
- 共享指针取消引用错误
- 编译简单的多文件类程序时出现未定义的引用错误
- 模板函数产生未定义的引用错误
- 调用提取重加载器会产生对"运算符"的未定义引用错误>>
- 如何修复"未定义的引用"错误 opencv 和 g++
- 未定义的引用错误,我该怎么办?