debug pairing test case

This commit is contained in:
matthias.ringwald@gmail.com 2014-04-12 21:21:46 +00:00
parent fdcd1130d4
commit e2bc2c157b
6 changed files with 1269 additions and 1233 deletions

View File

@ -26,11 +26,14 @@ COMMON = \
COMMON_OBJ = $(COMMON:.c=.o)
all: security_manager
all: security_manager aestest
security_manager: ${CORE_OBJ} ${COMMON_OBJ} security_manager.c
${CC} ${CORE_OBJ} ${COMMON_OBJ} security_manager.c ${CFLAGS} ${LDFLAGS} -o $@
aestest: aestest.c rijndael.c
${CC} ${CFLAGS} -m32 rijndael.c aestest.c -o $@
clean:
rm -f security_manager
rm -f *.o ${BTSTACK_ROOT}/src/*.o

View File

@ -0,0 +1,30 @@
#include "rijndael.h"
#include <stdio.h>
#include <strings.h>
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");
}
int main(){
uint8_t key[16];
uint8_t plaintext[16];
bzero(key, 16);
bzero(plaintext, 16);
uint8_t cyphertext[16];
aes128_calc_cyphertext(key, plaintext, cyphertext);
hexdump2(cyphertext, 16);
}

View File

@ -114,9 +114,9 @@ int hci_send_cmd(const hci_cmd_t *cmd, ...){
swap128(key_flipped, key);
swap128(plaintext_flipped, plaintext);
printf("le_encrypt key ");
hexdump(key_flipped, 16);
hexdump(key, 16);
printf("le_encrypt txt ");
hexdump(plaintext_flipped, 16);
hexdump(plaintext, 16);
aes128_calc_cyphertext(key, plaintext, aes128_cyphertext);
printf("le_encrypt res ");
hexdump(aes128_cyphertext, 16);

View File

@ -5,12 +5,15 @@
#define FULL_UNROLL
#include <stdint.h>
#include "rijndael.h"
typedef uint32_t u32;
typedef uint8_t u8;
int rijndaelStartOfCode(){
return 1;
}
static const u32 Te0[256] =
{
0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU,
@ -714,7 +717,7 @@ static const u32 rcon[] =
*
* @return the number of rounds for the given cipher key size.
*/
int rijndaelSetupEncrypt(uint32_t *rk, const u8 *key, int keybits)
int rijndaelSetupEncrypt(u32 *rk, const u8 *key, int keybits)
{
int i = 0;
u32 temp;
@ -803,7 +806,7 @@ int rijndaelSetupEncrypt(uint32_t *rk, const u8 *key, int keybits)
*
* @return the number of rounds for the given cipher key size.
*/
int rijndaelSetupDecrypt(uint32_t *rk, const u8 *key, int keybits)
int rijndaelSetupDecrypt(u32 *rk, const u8 *key, int keybits)
{
int nrounds, i, j;
u32 temp;
@ -849,6 +852,7 @@ int rijndaelSetupDecrypt(uint32_t *rk, const u8 *key, int keybits)
void rijndaelEncrypt(const u32 *rk, int nrounds, const u8 plaintext[16],
u8 ciphertext[16])
{
u32 s0, s1, s2, s3, t0, t1, t2, t3;
#ifndef FULL_UNROLL
int r;
@ -1027,6 +1031,7 @@ void rijndaelEncrypt(const u32 *rk, int nrounds, const u8 plaintext[16],
rk[3];
PUTU32(ciphertext + 12, s3);
}
void rijndaelDecrypt(const u32 *rk, int nrounds, const u8 ciphertext[16],
@ -1034,6 +1039,7 @@ void rijndaelDecrypt(const u32 *rk, int nrounds, const u8 ciphertext[16],
{
u32 s0, s1, s2, s3, t0, t1, t2, t3;
#ifndef FULL_UNROLL
int r;
@ -1214,4 +1220,9 @@ u32 s0, s1, s2, s3, t0, t1, t2, t3;
PUTU32(plaintext + 12, s3);
}
int rijndaelEndOfCode(){
return 1;
}

View File

@ -6,16 +6,12 @@
#ifndef H__RIJNDAEL
#define H__RIJNDAEL
#if defined __cplusplus
extern "C" {
#endif
#include <stdint.h>
int rijndaelSetupEncrypt(uint32_t *rk, const unsigned char *key, int keybits);
int rijndaelSetupDecrypt(uint32_t *rk, const unsigned char *key, int keybits);
void rijndaelEncrypt(const uint32_t *rk, int nrounds, const unsigned char plaintext[16], unsigned char ciphertext[16]);
void rijndaelDecrypt(const uint32_t *rk, int nrounds, const unsigned char ciphertext[16], unsigned char plaintext[16]);
int rijndaelSetupEncrypt(uint32_t *rk, const uint8_t *key, int keybits);
int rijndaelSetupDecrypt(uint32_t *rk, const uint8_t *key, int keybits);
void rijndaelEncrypt(const uint32_t *rk, int nrounds, const uint8_t plaintext[16], uint8_t ciphertext[16]);
void rijndaelDecrypt(const uint32_t *rk, int nrounds, const uint8_t ciphertext[16], uint8_t plaintext[16]);
#define KEYBITS 128
@ -23,9 +19,5 @@ void rijndaelDecrypt(const uint32_t *rk, int nrounds, const unsigned char cipher
#define RKLENGTH(keybits) ((keybits)/8+28)
#define NROUNDS(keybits) ((keybits)/32+6)
#if defined __cplusplus
}
#endif
#endif

View File

@ -78,7 +78,7 @@ TEST_GROUP(GATTClient){
run_loop_init(RUN_LOOP_POSIX);
sm_init();
sm_set_io_capabilities(IO_CAPABILITY_NO_INPUT_NO_OUTPUT);
sm_set_authentication_requirements( SM_AUTHREQ_BONDING | SM_AUTHREQ_MITM_PROTECTION);
sm_set_authentication_requirements( SM_AUTHREQ_BONDING );
mock_simulate_hci_state_working();