diff options
Diffstat (limited to 'board/zinger')
-rw-r--r-- | board/zinger/board.c | 29 | ||||
-rw-r--r-- | board/zinger/board.h | 3 | ||||
-rw-r--r-- | board/zinger/build.mk | 3 | ||||
-rw-r--r-- | board/zinger/dev_key.pem | 27 | ||||
-rw-r--r-- | board/zinger/hardware.c | 13 | ||||
-rw-r--r-- | board/zinger/usb_pd_policy.c | 11 |
6 files changed, 61 insertions, 25 deletions
diff --git a/board/zinger/board.c b/board/zinger/board.c index faab419cc4..bf974cef24 100644 --- a/board/zinger/board.c +++ b/board/zinger/board.c @@ -7,11 +7,22 @@ #include "common.h" #include "debug.h" #include "registers.h" +#include "rsa.h" #include "sha1.h" +#include "sha256.h" #include "task.h" #include "usb_pd.h" #include "util.h" +/* Insert the RSA public key definition */ +const struct rsa_public_key pkey __attribute__((section(".rsa_pubkey"))) = +#include "gen_pub_key.h" +/* The RSA signature is stored at the end of the RW firmware */ +static const void *rw_sig = (void *)CONFIG_FLASH_BASE + CONFIG_FW_RW_OFF + + CONFIG_FW_RW_SIZE - RSANUMBYTES; +/* Large 768-Byte buffer for RSA computation : could be re-use afterwards... */ +static uint32_t rsa_workbuf[3 * RSANUMWORDS]; + extern void pd_rx_handler(void); /* RW firmware reset vector */ @@ -44,23 +55,17 @@ int is_ro_mode(void) static int check_rw_valid(void) { - uint32_t *hash; - uint32_t *fw_hash = (uint32_t *) - (CONFIG_FLASH_BASE + CONFIG_FLASH_SIZE - 32); + int good; + uint8_t *hash; /* Check if we have a RW firmware flashed */ if (*rw_rst == 0xffffffff) return 0; - hash = (uint32_t *)flash_hash_rw(); - /* TODO(crosbug.com/p/28336) use secret key to check RW */ - if (memcmp(hash, fw_hash, SHA1_DIGEST_SIZE) != 0) { - /* Firmware doesn't match the recorded hash */ - debug_printf("SHA-1 %08x %08x %08x %08x %08x\n", - hash[0], hash[1], hash[2], hash[3], hash[4]); - debug_printf("FW SHA-1 %08x %08x %08x %08x %08x\n", - fw_hash[0], fw_hash[1], fw_hash[2], - fw_hash[3], fw_hash[4]); + hash = flash_hash_rw(); + good = rsa_verify(&pkey, (void *)rw_sig, (void *)hash, rsa_workbuf); + if (!good) { + debug_printf("RSA verify FAILED\n"); return 0; } diff --git a/board/zinger/board.h b/board/zinger/board.h index daca59de8f..2b420e496a 100644 --- a/board/zinger/board.h +++ b/board/zinger/board.h @@ -24,7 +24,8 @@ #define CONFIG_USB_PD_CUSTOM_VDM #undef CONFIG_USB_PD_RX_COMP_IRQ #define CONFIG_HW_CRC -#define CONFIG_SHA1 +#define CONFIG_RSA +#define CONFIG_SHA256 #undef CONFIG_WATCHDOG_HELP #undef CONFIG_WATCHDOG_PERIOD_MS #define CONFIG_WATCHDOG_PERIOD_MS 2300 diff --git a/board/zinger/build.mk b/board/zinger/build.mk index 4e9e2f1f6d..885b0c5c0a 100644 --- a/board/zinger/build.mk +++ b/board/zinger/build.mk @@ -12,3 +12,6 @@ CHIP_VARIANT:=stm32f03x board-y=board.o hardware.o runtime.o usb_pd_policy.o board-$(CONFIG_DEBUG_PRINTF)+=debug.o + +# Add dependency to generate the public key coefficients header +$(out)/board/$(BOARD)/board.o: $(out)/gen_pub_key.h diff --git a/board/zinger/dev_key.pem b/board/zinger/dev_key.pem new file mode 100644 index 0000000000..6912b1f44e --- /dev/null +++ b/board/zinger/dev_key.pem @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpgIBAAKCAQEAvI3KBubudlZyX1oBNzWhQ+bNemHNVC5bO7TjJMTYTIJeKTaW +IyHCFLF9ztpe8tT9Y+ga4VO9PEktP1WJpdU0ecG6VwK3951/cElosfnIPmIY7dVp +PQtGtGS/Zih1nTMRV5hqtGa9SRg0i2kdph+quFXGQoMriTl0StmvNVtD51nRPGwc +ZsG9+P0yfnyo7l3qXtKu5gBx/jDne2kl5/isPHkKfl9le+aNQaNjWeJyB4XDqHXM +AjuW1G7FxoKlU4b363gQbE84Q80X1Qd9iAoRj/HLmDrx9h6FDFs+HbKDfCYtg2fK +up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wjNNQFLqs2YIN1eipLtjBtWwCRcrvdYKcmDrvCj2tcEtIg7D3 +j2qTBni1AoGBAI58xPHxB0cNclhWiFHPNgk98GkwADWxfeTZduoyfpraSrpbseu8 +Cfgq1p5E2nM9jWx4jdKA/fxdD40bneupPi5w5SE2gmwtmQFR3TehI8gxNbEL2Gq6 +6ZkgxnGNxFaE6saHVDHKU8Q2bgzCI8JlOOtSjzKvbr+hsQMYHcEJxom6 +-----END RSA PRIVATE KEY----- diff --git a/board/zinger/hardware.c b/board/zinger/hardware.c index 1b22ec64c4..061f3bdf89 100644 --- a/board/zinger/hardware.c +++ b/board/zinger/hardware.c @@ -9,7 +9,8 @@ #include "common.h" #include "cpu.h" #include "registers.h" -#include "sha1.h" +#include "rsa.h" +#include "sha256.h" #include "task.h" #include "timer.h" #include "util.h" @@ -374,11 +375,11 @@ exit_er: return res; } -static struct sha1_ctx ctx; +static struct sha256_ctx ctx; uint8_t *flash_hash_rw(void) { - sha1_init(&ctx); - sha1_update(&ctx, (void *)CONFIG_FLASH_BASE + CONFIG_FW_RW_OFF, - CONFIG_FW_RW_SIZE - 32); - return sha1_final(&ctx); + SHA256_init(&ctx); + SHA256_update(&ctx, (void *)CONFIG_FLASH_BASE + CONFIG_FW_RW_OFF, + CONFIG_FW_RW_SIZE - RSANUMBYTES); + return SHA256_final(&ctx); } diff --git a/board/zinger/usb_pd_policy.c b/board/zinger/usb_pd_policy.c index bc2a0ede3b..f54841bb72 100644 --- a/board/zinger/usb_pd_policy.c +++ b/board/zinger/usb_pd_policy.c @@ -378,13 +378,12 @@ int pd_custom_vdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload) break; case VDO_CMD_READ_INFO: hash = flash_hash_rw(); - /* copy hash into response */ - memcpy(payload + 1, hash, SHA1_DIGEST_SIZE); + /* copy the 20 first bytes of the hash into response */ + memcpy(payload + 1, hash, 5 * sizeof(uint32_t)); /* copy other info into response */ - payload[SHA1_DIGEST_SIZE/4 + 1] = VDO_INFO( - USB_PD_HARDWARE_DEVICE_ID, - ver_get_numcommits(), - !is_ro_mode()); + payload[6] = VDO_INFO(USB_PD_HARDWARE_DEVICE_ID, + ver_get_numcommits(), + !is_ro_mode()); rsize = 7; break; case VDO_CMD_FLASH_ERASE: |