Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
djb authored and douglasbakkum committed Nov 24, 2018
1 parent ad6c57d commit 2314e62
Show file tree
Hide file tree
Showing 22 changed files with 1,488 additions and 645 deletions.
3 changes: 1 addition & 2 deletions src/CMakeLists.txt
Expand Up @@ -9,8 +9,7 @@

set(DBB-FIRMWARE-SOURCES
aes.c
sharedsecret.c
aescbcb64.c
cipher.c
base58.c
base64.c
pbkdf2.c
Expand Down
192 changes: 0 additions & 192 deletions src/aescbcb64.c

This file was deleted.

43 changes: 0 additions & 43 deletions src/aescbcb64.h

This file was deleted.

28 changes: 24 additions & 4 deletions src/ataes132.c
Expand Up @@ -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: {
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 9 additions & 2 deletions src/ataes132.h
Expand Up @@ -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
5 changes: 5 additions & 0 deletions src/board_com.c
Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions src/board_com.h
Expand Up @@ -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

0 comments on commit 2314e62

Please sign in to comment.