Permalink
Browse files

more efficient and robust eeprom storage

refactor naming: aescbcb64 -> cipher
on system faults, clear memory and disable SPI and I2C peripherals
use explicit names for flash wrapper functions
  • Loading branch information...
douglasbakkum committed Sep 15, 2018
1 parent ad6c57d commit 2314e626c3dfd6d2063bd66db5ea3a0537a41aba
Showing with 1,488 additions and 645 deletions.
  1. +1 −2 src/CMakeLists.txt
  2. +0 −192 src/aescbcb64.c
  3. +0 −43 src/aescbcb64.h
  4. +24 −4 src/ataes132.c
  5. +9 −2 src/ataes132.h
  6. +5 −0 src/board_com.c
  7. +1 −0 src/board_com.h
  8. +272 −0 src/cipher.c
  9. +17 −13 src/{sharedsecret.c → cipher.h}
  10. +35 −29 src/commander.c
  11. +6 −0 src/firmware.c
  12. +66 −16 src/flash.c
  13. +14 −17 src/flash.h
  14. +358 −122 src/memory.c
  15. +10 −36 src/memory.h
  16. +6 −5 src/random.c
  17. +0 −33 src/sharedsecret.h
  18. +3 −0 src/startup.c
  19. +7 −6 tests/api.h
  20. +9 −41 tests/hmac_check.h
  21. +42 −58 tests/tests_api.c
  22. +603 −26 tests/tests_unit.c
@@ -9,8 +9,7 @@
set(DBB-FIRMWARE-SOURCES
aes.c
sharedsecret.c
aescbcb64.c
cipher.c
base58.c
base64.c
pbkdf2.c

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -69,14 +69,32 @@ static void ataes_calculate_crc(uint8_t length, const uint8_t *data, uint8_t *cr
static int random_seeded = 0;
__extension__ static uint8_t ataes_eeprom_simulation[] = {[0 ... 0x0FFF] = 0xFF};
__extension__ static uint8_t ataes_eeprom_simulation[] = {[0 ... (ATAES_EEPROM_LEN - 1)] = 0xFF};
uint8_t *ataes_eeprom_simulation_report(void)
{
return ataes_eeprom_simulation;
}
void ataes_eeprom_simulation_clear(void)
{
memset(ataes_eeprom_simulation, 0xFF, sizeof(ataes_eeprom_simulation));
}
void ataes_eeprom_simulation_write(const uint8_t *data, uint16_t start, uint16_t len)
{
memcpy(ataes_eeprom_simulation + start, data, len);
}
#else
static uint8_t ataes_eeprom_write(uint32_t u32_start_address, uint16_t u16_length,
uint8_t *p_wr_buffer)
const uint8_t *p_wr_buffer)
{
switch (board_com_report_ataes_mode()) {
case BOARD_COM_ATAES_MODE_SPI: {
@@ -90,7 +108,9 @@ static uint8_t ataes_eeprom_write(uint32_t u32_start_address, uint16_t u16_lengt
return board_com_spi_write(BOARD_COM_SPI_DEV_ATAES, spi_cmd, sizeof(spi_cmd));
}
case BOARD_COM_ATAES_MODE_TWI: {
return board_com_twi_write(u32_start_address, p_wr_buffer, u16_length);
uint8_t twi_buf[u16_length];
memcpy(twi_buf, p_wr_buffer, u16_length);
return board_com_twi_write(u32_start_address, twi_buf, u16_length);
}
default: {
return 1;
@@ -274,7 +294,7 @@ int ataes_process(uint8_t const *command, uint16_t cmd_len,
// Pass NULL to read only or write only
int ataes_eeprom(uint16_t LEN, uint32_t ADDR, uint8_t *userdata_read,
uint8_t *userdata_write)
const uint8_t *userdata_write)
{
#ifdef TESTING
if (userdata_write != NULL) {
@@ -36,11 +36,18 @@
#define ATAES_CMD_RAND 0x02
#define ATAES_CMD_LOCK 0x0D
#ifdef TESTING
#define ATAES_EEPROM_LEN 0x1000
#define ATAES_EEPROM_ZONE_LEN 0x100
#define ATAES_EEPROM_ZONE_NUM (ATAES_EEPROM_LEN / ATAES_EEPROM_ZONE_LEN)
uint8_t *ataes_eeprom_simulation_report(void);
void ataes_eeprom_simulation_clear(void);
void ataes_eeprom_simulation_write(const uint8_t *data, uint16_t start, uint16_t len);
#endif
int ataes_process(uint8_t const *command, uint16_t cmd_len, uint8_t *response_block,
uint16_t response_len);
int ataes_eeprom(uint16_t LEN, uint32_t ADDR, uint8_t *userdata_read,
uint8_t *userdata_write);
const uint8_t *userdata_write);
#endif
@@ -164,3 +164,8 @@ void board_com_init(void)
}
void board_com_deinit(void)
{
spi_disable(SPI);
twi_disable_master_mode(BOARD_COM_ATAES_TWI);
}
@@ -104,6 +104,7 @@ uint8_t board_com_spi_write_read(BOARD_COM_SPI_DEV d, uint8_t *ins, uint32_t ins
uint8_t *reply, uint32_t reply_len);
uint8_t board_com_spi_write(BOARD_COM_SPI_DEV d, uint8_t *cmd, uint32_t len);
void board_com_init(void);
void board_com_deinit(void);
#endif
Oops, something went wrong.

0 comments on commit 2314e62

Please sign in to comment.