summaryrefslogtreecommitdiff
path: root/futility/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'futility/misc.c')
-rw-r--r--futility/misc.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/futility/misc.c b/futility/misc.c
index 703033c5..af291a49 100644
--- a/futility/misc.c
+++ b/futility/misc.c
@@ -4,6 +4,7 @@
* found in the LICENSE file.
*/
+#include <assert.h>
#include <errno.h>
#ifndef HAVE_MACOS
#include <linux/fs.h> /* For BLKGETSIZE64 */
@@ -166,6 +167,7 @@ int print_hwid_digest(GoogleBinaryBlockHeader *gbb,
return is_valid;
}
+/* Deprecated. Use futil_set_gbb_hwid in future. */
/* For GBB v1.2 and later, update the hwid_digest field. */
void update_hwid_digest(GoogleBinaryBlockHeader *gbb)
{
@@ -181,6 +183,29 @@ void update_hwid_digest(GoogleBinaryBlockHeader *gbb)
gbb->hwid_digest, sizeof(gbb->hwid_digest));
}
+/* Sets the HWID string field inside a GBB header. */
+int futil_set_gbb_hwid(struct vb2_gbb_header *gbb, const char *hwid)
+{
+ uint8_t *to = (uint8_t *)gbb + gbb->hwid_offset;
+ size_t len;
+
+ assert(hwid);
+ len = strlen(hwid);
+ if (len >= gbb->hwid_size)
+ return -1;
+
+ /* Zero whole area so we won't have garbage after NUL. */
+ memset(to, 0, gbb->hwid_size);
+ memcpy(to, hwid, len);
+
+ /* major_version starts from 1 and digest must be updated since v1.2. */
+ if (gbb->major_version == 1 && gbb->minor_version < 2)
+ return 0;
+
+ return vb2_digest_buffer(to, len, VB2_HASH_SHA256, gbb->hwid_digest,
+ sizeof(gbb->hwid_digest));
+}
+
/*
* TODO: All sorts of race conditions likely here, and everywhere this is used.
* Do we care? If so, fix it.