我尝试使用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_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 :(得分:0)
无论出于何种原因,default configuration都禁用了CMAC。如果找到其他加密函数,而不是CMAC函数,这必须是因为CMAC函数没有包含在您的构建中。
修改import java.awt.*;
import java.util.*;
public class Circles {
public static final Scanner CONSOLE = new Scanner(System.in);
public static void blueCircle(Graphics g) {
g.setColor(Color.BLUE);
int r = CONSOLE.nextInt();
int x = CONSOLE.nextInt();
int y = CONSOLE.nextInt();
g.fillOval(0 + x, 0 + y, r * 2, r * 2);
}
public static void greenCircle(Graphics g) {
g.setColor(Color.GREEN);
int r = CONSOLE.nextInt();
int x = CONSOLE.nextInt();
int y = CONSOLE.nextInt();
g.fillOval(0 + x, 0 + y, r * 2, r * 2);
}
public static void redCircle(Graphics g) {
g.setColor(Color.RED);
int r = CONSOLE.nextInt();
int x = CONSOLE.nextInt();
int y = CONSOLE.nextInt();
g.fillOval(0 + x, 0 + y, r * 2, r * 2);
}
public static void compareCircles(int r1, int r2) {
int x;
if (r1 < r2)
x = -1;
if (r1 == r2)
x = 0;
if (r1 > r2)
x = 1;
return;
}
public static void main(String[] args) {
DrawingPanel panel = new DrawingPanel(400, 300);
Graphics g = panel.getGraphics();
System.out.println("Enter values for the radius, x , & y-coordinates of blue circle: ");
blueCircle(g);
System.out.println("Enter values for the radius, x , & y-coordinates of green circle: ");
greenCircle(g);
System.out.println("Enter values for the radius, x , & y-coordinates of red circle: ");
redCircle(g);
}
}
以取消注释config.h
并重建库。