summaryrefslogtreecommitdiff
path: root/cgpt
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2016-05-11 13:50:18 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-07-22 18:40:04 -0700
commit7c3ae42e045935728a63a6d592ecf6c5bdbd005a (patch)
treeb03c1bde6af714d2229b2362ad1d64b99c8f581d /cgpt
parentb3a625f8fef1768d78eab4cfaaea270cb3fbd0c3 (diff)
downloadvboot-7c3ae42e045935728a63a6d592ecf6c5bdbd005a.tar.gz
vboot: Convert vboot1 SHA calls to use vboot2
This change replaces all calls to the old vboot1 SHA library with their vboot2 equivalents. This is the first in a long series of changes to move the core vboot kernel verification into vb2, and the control/display loop out to depthcharge. BUG=chromium:611535 BRANCH=none TEST=make runtests; build samus firmware and boot it Change-Id: I31986eb766176c0e39a192c5ce15730471c3cf94 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/344342 Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'cgpt')
-rw-r--r--cgpt/cgpt_wrapper.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/cgpt/cgpt_wrapper.c b/cgpt/cgpt_wrapper.c
index 1716cdde..3903358e 100644
--- a/cgpt/cgpt_wrapper.c
+++ b/cgpt/cgpt_wrapper.c
@@ -22,9 +22,14 @@
#include <sys/types.h>
#include <unistd.h>
+#include "2sysincludes.h"
+
+#include "2common.h"
+#include "2sha.h"
#include "cgpt.h"
#include "cgpt_nor.h"
#include "cryptolib.h"
+#include "file_keys.h"
// Check if cmdline |argv| has "-D". "-D" signifies that GPT structs are stored
// off device, and hence we should not wrap around cgpt.
@@ -67,8 +72,8 @@ static const char *find_mtd_device(int argc, const char *const argv[]) {
static int wrap_cgpt(int argc,
const char *const argv[],
const char *mtd_device) {
- uint8_t *original_hash = NULL;
- uint8_t *modified_hash = NULL;
+ uint8_t original_hash[VB2_SHA1_DIGEST_SIZE];
+ uint8_t modified_hash[VB2_SHA1_DIGEST_SIZE];
int ret = 0;
// Create a temp dir to work in.
@@ -81,7 +86,11 @@ static int wrap_cgpt(int argc,
if (snprintf(rw_gpt_path, sizeof(rw_gpt_path), "%s/rw_gpt", temp_dir) < 0) {
goto cleanup;
}
- original_hash = DigestFile(rw_gpt_path, SHA1_DIGEST_ALGORITHM);
+ if (VB2_SUCCESS != DigestFile(rw_gpt_path, VB2_HASH_SHA1,
+ original_hash, sizeof(original_hash))) {
+ Error("Cannot compute original GPT digest.\n");
+ goto cleanup;
+ }
// Obtain the MTD size.
ret++;
@@ -126,9 +135,9 @@ static int wrap_cgpt(int argc,
// Write back "rw_gpt" to NOR flash in two chunks.
ret++;
- modified_hash = DigestFile(rw_gpt_path, SHA1_DIGEST_ALGORITHM);
- if (original_hash != NULL && modified_hash != NULL) {
- if (memcmp(original_hash, modified_hash, SHA1_DIGEST_SIZE) != 0) {
+ if (VB2_SUCCESS == DigestFile(rw_gpt_path, VB2_HASH_SHA1,
+ modified_hash, sizeof(modified_hash))) {
+ if (memcmp(original_hash, modified_hash, VB2_SHA1_DIGEST_SIZE) != 0) {
ret = WriteNorFlash(temp_dir);
} else {
ret = 0;
@@ -136,8 +145,6 @@ static int wrap_cgpt(int argc,
}
cleanup:
- free(original_hash);
- free(modified_hash);
RemoveDir(temp_dir);
return ret;
}