2014-04-12 21:21:46 +00:00
|
|
|
|
|
|
|
#include "rijndael.h"
|
2020-09-30 13:13:59 +00:00
|
|
|
#include "btstack_debug.h"
|
2014-04-12 21:21:46 +00:00
|
|
|
#include <stdio.h>
|
2016-03-28 10:15:13 +00:00
|
|
|
#include <string.h>
|
2014-04-12 21:21:46 +00:00
|
|
|
|
|
|
|
void aes128_calc_cyphertext(uint8_t key[16], uint8_t plaintext[16], uint8_t cyphertext[16]){
|
|
|
|
uint32_t rk[RKLENGTH(KEYBITS)];
|
|
|
|
int nrounds = rijndaelSetupEncrypt(rk, &key[0], KEYBITS);
|
|
|
|
rijndaelEncrypt(rk, nrounds, plaintext, cyphertext);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void hexdump2(void *data, int size){
|
|
|
|
if (size <= 0) return;
|
|
|
|
int i;
|
|
|
|
for (i=0; i<size;i++){
|
|
|
|
printf("%02X ", ((uint8_t *)data)[i]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2015-05-13 08:30:46 +00:00
|
|
|
int main(void){
|
2014-04-12 21:21:46 +00:00
|
|
|
uint8_t key[16];
|
|
|
|
uint8_t plaintext[16];
|
2016-03-27 20:49:03 +00:00
|
|
|
memset(key, 0, 16);
|
|
|
|
memset(plaintext, 0, 16);
|
2014-04-12 21:21:46 +00:00
|
|
|
uint8_t cyphertext[16];
|
|
|
|
aes128_calc_cyphertext(key, plaintext, cyphertext);
|
|
|
|
hexdump2(cyphertext, 16);
|
2020-09-30 13:13:59 +00:00
|
|
|
|
|
|
|
// test invalid key len
|
|
|
|
uint32_t rk[RKLENGTH(KEYBITS)];
|
2021-12-03 10:47:45 +00:00
|
|
|
int result = rijndaelSetupEncrypt(rk, &key[0], 0);
|
|
|
|
btstack_assert(result == 0);
|
2014-04-12 21:21:46 +00:00
|
|
|
}
|