5#include "sw/device/silicon_creator/lib/boot_log.h"
8#include "sw/device/silicon_creator/lib/drivers/hmac.h"
10static void boot_log_digest_compute(
const boot_log_t *
boot_log,
11 hmac_digest_t *digest) {
14 kDigestRegionSize =
sizeof(boot_log_t) - kDigestRegionOffset,
16 static_assert(offsetof(boot_log_t, digest) == 0,
17 "`digest` must be the first field of `boot_log_t`.");
18 hmac_sha256((
const char *)
boot_log + kDigestRegionOffset, kDigestRegionSize,
22void boot_log_digest_update(boot_log_t *
boot_log) {
44static const uint32_t kCheckShares[kHmacDigestNumWords + 1] = {
45 0x7b00d08e, 0xfdb69374, 0x336c86df, 0xff2ef417, 0xe1517012,
46 0x4bf5408c, 0x9c6a7b25, 0xf771f8fa, 0xcd468505,
49rom_error_t boot_log_check(
const boot_log_t *
boot_log) {
50 static_assert(offsetof(boot_log_t, digest) == 0,
51 "`digest` must be the first field of `boot_log_t`.");
53 rom_error_t error = kErrorBootLogInvalid;
54 hmac_digest_t actual_digest;
55 boot_log_digest_compute(
boot_log, &actual_digest);
58 for (; launder32(i) < kHmacDigestNumWords; ++i) {
60 boot_log->
digest.digest[i] ^ actual_digest.digest[i] ^ kCheckShares[i];
66 if (launder32(error) == kErrorOk) {
71 return kErrorBootLogInvalid;
74void boot_log_check_or_init(boot_log_t *
boot_log, uint32_t rom_ext_slot,
75 const chip_info_t *info) {
76 rom_error_t error = boot_log_check(
boot_log);
77 if (launder32(error) == kErrorOk) {