clean up, added tests

vtcsec_summit
conor 2016-02-15 02:12:48 -05:00
rodzic d29c20955c
commit 2e320d1bc7
10 zmienionych plików z 133 dodań i 46 usunięć

Wyświetl plik

@ -141,6 +141,7 @@
<listOptionValue builtIn="false" value="&quot;${StudioSdkPath}/Lib/efm8_usb/inc&quot;"/>
<listOptionValue builtIn="false" value="&quot;${StudioSdkPath}/Device/EFM8UB1/peripheral_driver/inc&quot;"/>
<listOptionValue builtIn="false" value="&quot;${StudioSdkPath}/Lib/efm8_assert&quot;"/>
<listOptionValue builtIn="false" value="&quot;${ProjDirPath}/tests&quot;"/>
</option>
<inputType id="com.silabs.ide.si8051.keil.assembler.inputType.1636083418" superClass="com.silabs.ide.si8051.keil.assembler.inputType"/>
</tool>

Wyświetl plik

@ -32,11 +32,15 @@ struct APP_DATA
uint8_t state;
};
extern data struct APP_DATA appdata;
struct debug_msg
{
char buf[40];
};
#define FIFO_HEADER(NAME, TYPE)\
void NAME##_fifo_init();\
int NAME##_fifo_append(TYPE* _data);\

Wyświetl plik

@ -38,7 +38,10 @@ void u2f_write_n(char* buf, uint32_t val, int base);
void qu2f_write_s(char* d);
void qu2f_write_n(char* buf, uint32_t val, int base);
extern SI_SEGMENT_VARIABLE(appdata, struct APP_DATA, SI_SEG_DATA);
// not reentrant
void dump_hex(uint8_t* hex, uint8_t len);
#ifdef U2F_PRINT
void u2f_print(char* fmt, ...);
@ -46,7 +49,7 @@ void u2f_print(char* fmt, ...);
#define u2f_print(x)
#endif
int hid_u2f_request(struct u2f_hid_msg* req, struct u2f_hid_msg* res);
#endif /* BSP_H_ */

Wyświetl plik

@ -73,10 +73,7 @@ SI_INTERRUPT (SMBUS0_ISR, SMBUS0_IRQn)
switch (SMB0CN0 & SMB_STATE_MASK)
{
case SMB_STATUS_START:
SMB0DAT = SMB.addr;
SMB0DAT &= 0xFE;
SMB0DAT |= SMB_FLAGS & SMB_READ;
SMB0DAT = SMB.addr | (SMB_FLAGS & SMB_READ);
SMB0CN0_STA = 0;
break;

Wyświetl plik

@ -54,5 +54,19 @@ void u2f_write_s(char* d)
}
}
// not reentrant
void dump_hex(uint8_t* hex, uint8_t len)
{
uint8_t i;
flush_messages();
for (i=0 ; i < len ; i++)
{
u2f_print(" %02bx",hex[i]);
flush_messages();
}
u2f_print("\r\n");
flush_messages();
}

Wyświetl plik

@ -23,7 +23,6 @@
#include "u2f_hid.h"
#define HID_INTERFACE_INDEX 0
extern SI_SEGMENT_VARIABLE(appdata, struct APP_DATA, SI_SEG_DATA);
uint8_t tmpBuffer;

Wyświetl plik

@ -15,8 +15,6 @@
uint8_t smb_read (uint8_t addr, uint8_t* dest, uint8_t count)
{
while(SMB_IS_BUSY());

Wyświetl plik

@ -11,6 +11,7 @@
#include "app.h"
#include "i2c.h"
#include "u2f_hid.h"
#include "tests.h"
data struct APP_DATA appdata;
@ -55,19 +56,7 @@ static void listen_for_pkt(struct APP_DATA* ap)
// not reentrant
static void dump_hex(uint8_t* hex, uint8_t len)
{
uint8_t i;
flush_messages();
for (i=0 ; i < len ; i++)
{
u2f_print(" %02bx",hex[i]);
flush_messages();
}
u2f_print("\r\n");
flush_messages();
}
void test_ecc508a()
{
@ -84,29 +73,8 @@ void test_ecc508a()
// ATECC_RNG_P1,
// ATECC_RNG_P2,NULL,0);
// }while((len = atecc_recv(buf,sizeof(buf))) < 0);
char pw[] = "2pckJ4IkT3PwdGMwuCygPpxD6+lObNGORiLGPQxM4ef4YoNvx9/k0xskZl84rCd3TllCvitepe+B";
do{
atecc_send(ATECC_CMD_SHA,
ATECC_SHA_START,
0,NULL,0);
}while((len = atecc_recv(buf,sizeof(buf))) < 0);
dump_hex(buf,len);
do{
atecc_send(ATECC_CMD_SHA,
ATECC_SHA_UPDATE,
64,pw,64);
}while((len = atecc_recv(buf,sizeof(buf))) < 0);
dump_hex(buf,len);
do{
atecc_send(ATECC_CMD_SHA,
ATECC_SHA_END,
sizeof(pw)-65,pw+64,sizeof(pw)-65);
}while((len = atecc_recv(buf,sizeof(buf))) < 0);
dump_hex(buf,len);
// sha256 sum should be bcddd71b48f8a31d1374ad51c2e4138a871cb7f1eb3f2bdab49bc9bc60afc3a5
}
@ -139,9 +107,7 @@ int16_t main(void) {
if (!test)
{
test_ecc508a();
test_ecc508a();
test_ecc508a();
run_tests();
test = 1;
}

Wyświetl plik

@ -0,0 +1,82 @@
/*
* tests.c
*
* Created on: Feb 14, 2016
* Author: Conor
*/
#include <stdarg.h>
#include <stdio.h>
#include "app.h"
#include "bsp.h"
#include "i2c.h"
#include "atecc508a.h"
#include "tests.h"
#ifdef ENABLE_TESTS
#define TEST_SHA
static void PRINT(const char * fmt, ...)
{
va_list args;
va_start(args,fmt);
vsprintf(appdata.hidmsgbuf, fmt, args);
va_end(args);
u2f_write_s(appdata.hidmsgbuf);
}
#ifdef TEST_SHA
static int test_sha()
{
uint8_t buf[40];
uint8_t len;
char pw[] = "2pckJ4IkT3PwdGMwuCygPpxD6+lObNGORiLGPQxM4ef4YoNvx9/k0xskZl84rCd3TllCvitepe+B";
do{
atecc_send(ATECC_CMD_SHA,
ATECC_SHA_START,
0,NULL,0);
}while((len = atecc_recv(buf,sizeof(buf))) < 0);
dump_hex(buf,len);
do{
atecc_send(ATECC_CMD_SHA,
ATECC_SHA_UPDATE,
64,pw,64);
} while ((len = atecc_recv(buf,sizeof(buf))) < 0);
dump_hex(buf,len);
do{
atecc_send(ATECC_CMD_SHA,
ATECC_SHA_END,
sizeof(pw)-65,pw+64,sizeof(pw)-65);
}while((len = atecc_recv(buf,sizeof(buf))) < 0);
dump_hex(buf,len);
// sha256 sum should be bcddd71b48f8a31d1374ad51c2e4138a871cb7f1eb3f2bdab49bc9bc60afc3a5
return (SMB.crc == 0x9768) ? 0 : -1;
}
#else
#define test_sha(x)
#endif
void run_tests()
{
int rc;
PRINT("--- STARTING SHA TEST ---\r\n");
rc = test_sha();
if (rc == 0)
PRINT("--- SHA TEST SUCCESS ---\r\n");
else
PRINT("--- SHA TEST FAILED %d ---\r\n",rc);
}
#endif

Wyświetl plik

@ -0,0 +1,23 @@
/*
* tests.h
*
* Created on: Feb 14, 2016
* Author: Conor
*/
#ifndef TESTS_H_
#define TESTS_H_
#define ENABLE_TESTS
#ifdef ENABLE_TESTS
void run_tests();
#else
#define run_tests(x)
#endif
#endif /* TESTS_H_ */