1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <metadata_hash.h>
5 #include <security/vboot/misc.h>
8 #if !CONFIG(COMPRESS_BOOTBLOCK) || ENV_DECOMPRESSOR
9 __attribute__((used
, section(".metadata_hash_anchor")))
10 static struct metadata_hash_anchor metadata_hash_anchor
= {
11 /* This is the only place in all of coreboot where we actually need to use this. */
12 .magic
= DO_NOT_USE_METADATA_HASH_ANCHOR_MAGIC_DO_NOT_USE
,
13 .cbfs_hash
= { .algo
= CONFIG_CBFS_HASH_ALGO
}
16 static struct metadata_hash_anchor
*get_anchor(void)
18 return &metadata_hash_anchor
;
21 void *metadata_hash_export_anchor(void)
26 static struct metadata_hash_anchor
*anchor_ptr
= NULL
;
28 static struct metadata_hash_anchor
*get_anchor(void)
30 assert(anchor_ptr
!= NULL
);
34 void metadata_hash_import_anchor(void *ptr
)
40 struct vb2_hash
*metadata_hash_get(void)
42 return &get_anchor()->cbfs_hash
;
45 vb2_error_t
metadata_hash_verify_fmap(const void *fmap_buffer
, size_t fmap_size
)
47 struct vb2_hash hash
= { .algo
= get_anchor()->cbfs_hash
.algo
};
48 memcpy(hash
.raw
, metadata_hash_anchor_fmap_hash(get_anchor()),
49 vb2_digest_size(hash
.algo
));
50 return vb2_hash_verify(vboot_hwcrypto_allowed(), fmap_buffer
, fmap_size
, &hash
);