You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
2.2 KiB
118 lines
2.2 KiB
#include "Device/Include/stm32f10x.h" // Device header
|
|
|
|
#include<stdint.h>
|
|
#include"AES_CBC_SW.h"
|
|
#define AES_MAXROUNDS 14
|
|
#define AES_BLOCKSIZE 16
|
|
#define AES_IV_SIZE 16
|
|
#define KEYSIZE 16
|
|
#define MSG_SIZE KEYSIZE * 4
|
|
|
|
static const uint8_t key[KEYSIZE] =
|
|
{
|
|
0xff, 0xde, 0x00, 0xad,
|
|
0xff, 0xb0, 0x00, 0x0b,
|
|
0xff, 0xde, 0x00, 0xad,
|
|
0xff, 0xb0, 0x00, 0x0b
|
|
};
|
|
|
|
static const uint8_t iv[KEYSIZE] =
|
|
{
|
|
0xff, 0xc0, 0x00, 0xfe,
|
|
0xff, 0xc0, 0x00, 0x7d,
|
|
0xff, 0xc0, 0x00, 0xfe,
|
|
0xff, 0xc0, 0x00, 0x7d
|
|
};
|
|
|
|
static const uint8_t original_msg[MSG_SIZE] =
|
|
{
|
|
0xf4, 0xfc, 0xa2, 0xf4,
|
|
0x93, 0xfa, 0x64, 0xeb,
|
|
0x87, 0xca, 0xeb, 0x62,
|
|
0x90, 0x89, 0x34, 0xdb,
|
|
0x34, 0xe3, 0xf8, 0xc6,
|
|
0xd7, 0xf6, 0x89, 0xe7,
|
|
0xc0, 0x37, 0x43, 0xcd,
|
|
0x32, 0x69, 0xcd, 0xbd,
|
|
0x05, 0xec, 0x97, 0xbf,
|
|
0x05, 0x92, 0xc9, 0xf7,
|
|
0x8d, 0x4b, 0xb0, 0x88,
|
|
0x1a, 0xc2, 0x15, 0x2e,
|
|
0xba, 0x46, 0x58, 0xf9,
|
|
0x4d, 0x1f, 0xe9, 0xef,
|
|
0xa8, 0x6b, 0x5a, 0x6f,
|
|
0x8b, 0xe6, 0x7d, 0x51
|
|
};
|
|
|
|
static uint8_t out[MSG_SIZE] ;
|
|
static uint8_t msg[MSG_SIZE] ;
|
|
|
|
static AES_CTX context ;
|
|
|
|
void test_setup()
|
|
{
|
|
}
|
|
|
|
void test_clear()
|
|
{
|
|
uint8_t i =0;
|
|
|
|
memcpy(msg, original_msg, MSG_SIZE);
|
|
memset(out, 0, MSG_SIZE);
|
|
memset(&context, 0, sizeof(context));
|
|
|
|
|
|
printf("\r\n original_msg[%d]\r\n",MSG_SIZE);
|
|
for(i = 0 ; i<MSG_SIZE ; i++)
|
|
{
|
|
printf("%02x", original_msg[i]);
|
|
}
|
|
printf("\r\n");
|
|
}
|
|
|
|
void test_run()
|
|
{
|
|
uint8_t i =0;
|
|
|
|
AES_set_key(&context, key, iv, AES_MODE_128);
|
|
AES_cbc_encrypt(&context, msg, out, MSG_SIZE);
|
|
|
|
printf("\r\n out[%d]\r\n",MSG_SIZE);
|
|
for(i = 0 ; i<MSG_SIZE ; i++)
|
|
{
|
|
printf("%02x", out[i]);
|
|
}
|
|
printf("\r\n");
|
|
|
|
memset(msg, 0, MSG_SIZE);
|
|
memset(&context, 0, sizeof(context));
|
|
AES_set_key(&context, key, iv, AES_MODE_128);
|
|
|
|
AES_convert_key(&context);
|
|
AES_cbc_decrypt(&context, out, msg, MSG_SIZE);
|
|
|
|
printf("\r\n msg[%d]\r\n",MSG_SIZE);
|
|
for(i = 0 ; i<MSG_SIZE ; i++)
|
|
{
|
|
printf("%02x", msg[i]);
|
|
}
|
|
printf("\r\n");
|
|
}
|
|
|
|
int test_check()
|
|
{
|
|
return 0 == memcmp(msg, original_msg, MSG_SIZE);
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
|
|
test_clear();
|
|
test_run();
|
|
test_check();
|
|
|
|
for(;;)
|
|
{
|
|
|
|
}
|
|
} |