feat(legacy): Show progress in GetFirmwareHash.

pull/2251/head
Andrew Kozlik 2 years ago committed by Martin Milata
parent 485ee6e209
commit bd8d9c9c6b

@ -537,14 +537,20 @@ void fsm_msgGetNextU2FCounter() {
layoutHome();
}
static void progress_callback(uint32_t iter, uint32_t total) {
layoutProgress(_("Please wait"), 1000 * iter / total);
}
void fsm_msgGetFirmwareHash(const GetFirmwareHash *msg) {
RESP_INIT(FirmwareHash);
layoutProgressSwipe(_("Please wait"), 0);
if (memory_firmware_hash(msg->challenge.bytes, msg->challenge.size,
resp->hash.bytes) != 0) {
progress_callback, resp->hash.bytes) != 0) {
fsm_sendFailure(FailureType_Failure_FirmwareError, NULL);
return;
}
resp->hash.size = sizeof(resp->hash.bytes);
msg_write(MessageType_MessageType_FirmwareHash, resp);
layoutHome();
}

@ -22,6 +22,7 @@
#include <stdint.h>
#include "blake2s.h"
#include "flash.h"
#include "layout.h"
#include "sha2.h"
#define FLASH_OPTION_BYTES_1 (*(const uint64_t *)0x1FFFC000)
@ -86,6 +87,7 @@ int memory_bootloader_hash(uint8_t *hash) {
}
int memory_firmware_hash(const uint8_t *challenge, uint32_t challenge_size,
void (*progress_callback)(uint32_t, uint32_t),
uint8_t hash[BLAKE2S_DIGEST_LENGTH]) {
BLAKE2S_CTX ctx;
if (challenge_size != 0) {
@ -104,6 +106,10 @@ int memory_firmware_hash(const uint8_t *challenge, uint32_t challenge_size,
return 1;
}
blake2s_Update(&ctx, data, size);
if (progress_callback != NULL) {
progress_callback(i - FLASH_CODE_SECTOR_FIRST,
FLASH_CODE_SECTOR_LAST - FLASH_CODE_SECTOR_FIRST);
}
}
return blake2s_Final(&ctx, hash, BLAKE2S_DIGEST_LENGTH);

@ -94,6 +94,7 @@ void memory_protect(void);
void memory_write_unlock(void);
int memory_bootloader_hash(uint8_t *hash);
int memory_firmware_hash(const uint8_t *challenge, uint32_t challenge_size,
void (*progress_callback)(uint32_t, uint32_t),
uint8_t hash[32]);
static inline void flash_write32(uint32_t addr, uint32_t word) {

Loading…
Cancel
Save