c++ - AES-CMAC 使用 mbedtls : undefined reference error

标签 c++ mbedtls cmac

我尝试使用 mbedTLS 实现 AES-CMAC。 我收到一些错误:

undefined reference to mbedtls_cipher_cmac_starts, undefined reference to mbedtls_cipher_cmac_update, undefined reference to mbedtls_cipher_cmac_finish,

为什么不能解析这些函数,即使 mbedtls_cipher_initmbedtls_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 %d\n",(int)d_len);
    for(i=0;i<d_len;i++)
    {
        printf("%x ",out1[i]);
    }


    return 0;

}

最佳答案

无论出于何种原因,CMAC 在 default configuration 中被禁用.如果找到其他加密函数,但没有找到 CMAC 函数,这一定是因为 CMAC 函数未包含在您的构建中。

编辑 config.h 以取消注释 #define MBEDTLS_CMAC_C 并重建库。

关于c++ - AES-CMAC 使用 mbedtls : undefined reference error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41973075/

相关文章:

c++ - Qt Connect 无法连接到插槽

c++ - 为什么我找不到我的着色器属性?

c++ - C++ 中对象的大小

c++ - 声明 d3ddevice 全局或传递到需要它的类中?

node.js - 我可以限制 Node.js/express.js 中 TLS 消息的长度吗?

c - mbedTLS sha256 的性能现实吗?

c# - AES CMAC计算C#

Java 卡中的 AES-CMAC