Created
September 16, 2018 02:24
-
-
Save ilebedev/6dbe3d709714a44b3540e19aa7e68353 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// root_of_trust.c | |
#include "sha3/sha3.h" | |
/* The location and size of the bootloader in DRAM | |
are linked into the boot ROM image. */ | |
extern const void * bootloader_ptr; | |
extern const size_t bootloader_size; | |
/* the expected SHA-3-512 hash is also a constant | |
linked into the boot ROM image */ | |
extern const uint64_t bootloader_expected_hash[8]; | |
bool rot_hash_and_verify() { | |
/* Reserve stack space for hash of bootloader in DRAM */ | |
uint64_t bootloader_hash[8]; // 512-bit (64 byte) hash | |
// Compute 64 Byte sha-3 hash of the trusted bootloader DRAM */ | |
sha3(&bootloader_ptr, bootloader_size, bootloader_hash, 64); | |
/* Compare the root of trust hash againt an expected value | |
(there is no private information to clean up afterward) */ | |
for (unsigned int i=0; i<8; i++) { | |
if (bootloader_hash[i] != bootloader_expected_hash[i]) { | |
return false; | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment