1
0
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:
Pavol Rusnak 2016-10-04 18:01:48 +02:00
parent 157b12374f
commit 727a5f8393
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
7 changed files with 43 additions and 3 deletions

View File

@ -81,7 +81,8 @@ SRC_LIB = $(addprefix lib/,\
SRC_C = \ SRC_C = \
bootloader/bootloader.c \ bootloader/bootloader.c \
bootloader/bootloader_ui.c \ bootloader/crypto.c \
bootloader/ui.c \
system_stm32.c \ system_stm32.c \
$(wildcard boards/$(BOARD)/*.c) $(wildcard boards/$(BOARD)/*.c)

View File

@ -1,7 +1,9 @@
#include STM32_HAL_H #include STM32_HAL_H
#include "crypto.h"
#include "ui.h"
#include "display.h" #include "display.h"
#include "bootloader_ui.h"
// ### from main.c // ### from main.c
@ -83,8 +85,15 @@ int main(void) {
display_init(); display_init();
display_clear(); display_clear();
uint8_t hash[32];
hash_flash(hash);
screen_welcome(); screen_welcome();
uint8_t *pubkey = (uint8_t *)"ThisIsJustAFakePublicKeyForTest!";
uint8_t *signature = (uint8_t *)"ThisIsJustAFakeSignatureToTestTheVerifyMechanismInTRZRBootloader";
ed25519_verify(hash, 32, pubkey, signature);
for (;;) { for (;;) {
display_backlight(255); display_backlight(255);
HAL_Delay(250); HAL_Delay(250);

15
bootloader/crypto.c Normal file
View 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
View 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

View File

@ -1,5 +1,8 @@
#include "ui.h"
#include "display.h" #include "display.h"
#include "bootloader_trezor.h"
#include "toi_trezor.h"
#define ui_WHITE 0xFFFF #define ui_WHITE 0xFFFF
#define ui_BLACK 0x0000 #define ui_BLACK 0x0000