mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 15:38:11 +00:00
add crypto calls to bootloader
This commit is contained in:
parent
157b12374f
commit
727a5f8393
@ -81,7 +81,8 @@ SRC_LIB = $(addprefix lib/,\
|
||||
|
||||
SRC_C = \
|
||||
bootloader/bootloader.c \
|
||||
bootloader/bootloader_ui.c \
|
||||
bootloader/crypto.c \
|
||||
bootloader/ui.c \
|
||||
system_stm32.c \
|
||||
$(wildcard boards/$(BOARD)/*.c)
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
#include STM32_HAL_H
|
||||
|
||||
#include "crypto.h"
|
||||
#include "ui.h"
|
||||
|
||||
#include "display.h"
|
||||
#include "bootloader_ui.h"
|
||||
|
||||
// ### from main.c
|
||||
|
||||
@ -83,8 +85,15 @@ int main(void) {
|
||||
display_init();
|
||||
display_clear();
|
||||
|
||||
uint8_t hash[32];
|
||||
hash_flash(hash);
|
||||
|
||||
screen_welcome();
|
||||
|
||||
uint8_t *pubkey = (uint8_t *)"ThisIsJustAFakePublicKeyForTest!";
|
||||
uint8_t *signature = (uint8_t *)"ThisIsJustAFakeSignatureToTestTheVerifyMechanismInTRZRBootloader";
|
||||
ed25519_verify(hash, 32, pubkey, signature);
|
||||
|
||||
for (;;) {
|
||||
display_backlight(255);
|
||||
HAL_Delay(250);
|
||||
|
15
bootloader/crypto.c
Normal file
15
bootloader/crypto.c
Normal file
@ -0,0 +1,15 @@
|
||||
#include "crypto.h"
|
||||
|
||||
#include "ed25519-donna/ed25519.h"
|
||||
|
||||
#include "cmsis/stm32f405xx.h"
|
||||
|
||||
void hash_flash(uint8_t hash[SHA256_DIGEST_LENGTH])
|
||||
{
|
||||
sha256_Raw((const uint8_t *)FLASH_BASE, 1024*1024, hash);
|
||||
}
|
||||
|
||||
bool ed25519_verify(const uint8_t *msg, uint32_t msglen, uint8_t *pubkey, uint8_t *signature)
|
||||
{
|
||||
return (0 == ed25519_sign_open(msg, msglen, *(const ed25519_public_key *)pubkey, *(const ed25519_signature *)signature));
|
||||
}
|
12
bootloader/crypto.h
Normal file
12
bootloader/crypto.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef __BOOTLOADER_CRYPTO_H__
|
||||
#define __BOOTLOADER_CRYPTO_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "sha2.h"
|
||||
|
||||
void hash_flash(uint8_t hash[SHA256_DIGEST_LENGTH]);
|
||||
bool ed25519_verify(const uint8_t *msg, uint32_t msglen, uint8_t *pubkey, uint8_t *signature);
|
||||
|
||||
#endif
|
@ -1,5 +1,8 @@
|
||||
#include "ui.h"
|
||||
|
||||
#include "display.h"
|
||||
#include "bootloader_trezor.h"
|
||||
|
||||
#include "toi_trezor.h"
|
||||
|
||||
#define ui_WHITE 0xFFFF
|
||||
#define ui_BLACK 0x0000
|
Loading…
Reference in New Issue
Block a user