我正在使用 libtomcrypt 编写简单的 aes 解码器/编码器。我需要讲述编码中使用的对称密钥,以便稍后解码数据。问题是我从“存储”结构访问的键的值与编码器中使用的键相比发生了变化。
我尝试将键值分配给全局 symmetric_key 数组 elem 的元素,但该值仍然与原始值不同
#include <tomcrypt.h>
typedef struct {
unsigned char * data;
unsigned char * crc_value;
symmetric_key skey;
}
aes_info_set;
aes_info_set aes_encrypter(unsigned char * data, unsigned char * key, int buf_size, int keysize, int rounds);
void main() {
unsigned char * data = "hallo world";
aes_info_set test;
test = aes_encrypter(data, key, 80, 32, 14);
printf("struct skey: %x \n", test.skey);
}
aes_info_set aes_encrypter(unsigned char * data, unsigned char * key, int buf_size, int keysize, int rounds) {
aes_info_set info_pack;
unsigned char * text = data;
unsigned char enc_out[buf_size];
unsigned char * crc_value = (unsigned char * ) malloc(4 * sizeof(unsigned char));
symmetric_key skey;
crc_value = crc_check(text, strlen(text));
aes_keysize( & keysize);
aes_setup(key, keysize, rounds, & skey);
aes_ecb_encrypt(text, enc_out, & skey);
printf("FROM FUNC\n");
info_pack.data = enc_out;
info_pack.crc_value = crc_value;
info_pack.skey = skey;
printf("func skey: %x \n", skey);
return info_pack;
}
//Output
>func skey: a15b56e0
>
>struct skey: a15b7890
我希望他们是一样的