2017-02-01 7 views
1

mbedTLSを使用してAES-CMACを実装しようとしています。 私は若干の誤差が出る:mbedtlsを使用したAES-CMAC:未定義参照エラー

mbedtls_cipher_cmac_startsに未定義の参照、mbedtls_cipher_cmac_updateに未定義の参照、mbedtls_cipher_cmac_finishに未定義の参照、

は、なぜこれらの機能は、さらにmbedtls_cipher_initmbedtls_cipher_setupはできるものの、解決できませんでしたか?

BTW。同じプロジェクトの下で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_CBC); 
    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; 

} 
+0

[定義されていない参照/未解決の外部シンボルエラーとは何か、それを修正する方法は?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-外部記号エラー・アンド・ハウ・ド・イ・フィックス) – Biffen

答えて

0

何らかの理由で、CMACはdefault configurationで無効にされています

は、ここに私のコードです。他の暗号関数が見つかったが、CMAC関数は見つからない場合は、CMAC関数がビルドに含まれていないためです。

config.hを編集して#define MBEDTLS_CMAC_Cのコメントを外し、ライブラリを再構築します。