I'm writing simple aes decoder/encoder using libtomcrypt. I need to story symmetric keys used in encoding, to decode data later. The problem is that the value of key which I access from "storage" struct changes comparing to the key that was used in encoder.
I've tried to assign key value to element of global symmetric_key array elem, but the value is still different from original
#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
I expected them to be the same