Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/129.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用mbedtls的AES-CMAC:未定义的参考错误_C++_Mbedtls_Cmac - Fatal编程技术网

C++ 使用mbedtls的AES-CMAC:未定义的参考错误

C++ 使用mbedtls的AES-CMAC:未定义的参考错误,c++,mbedtls,cmac,C++,Mbedtls,Cmac,我尝试使用mbedTLS实现AES-CMAC。 我发现了一些错误: 对mbedtls\u cipher\u cmac\u启动的未定义引用,对mbedtls\u cipher\u cmac\u更新的未定义引用,对mbedtls\u cipher\u cmac\u完成的未定义引用 为什么这些函数不能被解析,即使mbedtls\u cipher\u init和mbedtls\u cipher\u setup可以解析 顺便说一句,我在同一个项目下使用mbedTLS实现了AES,没有问题。我使用eclip

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

mbedtls\u cipher\u cmac\u启动的未定义引用
,对
mbedtls\u cipher\u cmac\u更新的未定义引用
,对
mbedtls\u cipher\u cmac\u完成的未定义引用

为什么这些函数不能被解析,即使
mbedtls\u cipher\u init
mbedtls\u cipher\u setup
可以解析

顺便说一句,我在同一个项目下使用mbedTLS实现了AES,没有问题。我使用eclipsenano

这是我的密码:

#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;

}
#包括“stdio.h”
#包括“stdlib.h”
#包括“string.h”
#包括“openssl/evp.h”
#包括“openssl/cmac.h”
#包括“mbedtls/cmac.h”
#包括“mbedtls/cipher.h”
使用名称空间std;
无符号字符键[16]={0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00、0x00};
int main()
{
无符号字符m[100],m_len=32;
无符号字符out[16]、out1[16]、out2[16];
尺寸;
int i,ret;
mbedtls\u cipher\u context\u t m\u ctx;
const mbedtls\u cipher\u info\u t*cipher\u info;
cipher_info=mbedtls_cipher_info_from_type(mbedtls_cipher_AES_128_ECB);
如果(密码信息==NULL)
printf(“\nmbedtls\u cipher\u info\u from\u type failed”);
mbedtls_cipher_init(&m_ctx);
ret=mbedtls\u密码设置(&m\u ctx,密码信息);
printf(“\n mbedtls\u cipher\u安装程序返回%d%d”,ret,m\u ctx.cipher\u info->type);
ret=mbedtls\u密码\u cmac\u启动(&m\u ctx,密钥,128);
printf(“\n mbedtls\u密码\u cmac\u启动返回%d”,ret);
ret=mbedtls\u密码\u cmac\u更新(&m\u ctx,m,m\u len);
printf(“\n mbedtls\u密码\u cmac\u更新返回%d”,ret);
ret=mbedtls\u密码\u cmac\u完成(&m\u ctx,out1);
printf(“\n mbedtls\u密码\u cmac\u启动返回%d”,ret);
d_len=16;
printf(“\n长度为%d\n”,(int)d\u len);

对于(i=0;i,无论出于何种原因,CMAC在中被禁用。如果找到了其他加密函数,但没有找到CMAC函数,这一定是因为CMAC函数未包含在生成中


编辑
config.h
以取消注释
#定义MBEDTLS\u CMAC\u C
并重建库。

无论出于何种原因,CMAC在中被禁用。如果找到了其他加密函数,但没有找到CMAC函数,这一定是因为生成中未包含CMAC函数


编辑
config.h
以取消注释
#定义MBEDTLS\u CMAC\u C
并重建库。

可能重复的警告:我在这里更正了一个错误
cipher\u info=MBEDTLS\u cipher\u info\u来自类型(MBEDTLS\u cipher\u AES\u 128\u ECB)
必须是ECB模式,而不是CBC模式,c.f。可能的警告重复:我在这里纠正了一个错误
cipher\u info=mbedtls\u cipher\u info\u from_type(mbedtls\u cipher\u AES\u 128\u ECB);
必须是ECB模式,而不是CBC模式,c.f。