summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Kitching <kitching@google.com>2019-07-31 14:12:30 +0800
committerCommit Bot <commit-bot@chromium.org>2019-08-13 04:36:52 +0000
commite6700f4c70fe72850ae4f3f5df19c9281ebcefc8 (patch)
tree0f2abff7be99bc140e288058fb2eeab6f8bb8b64
parenta5afd01feb0b4b45adbcd8ab38ab8a2ef2a2ef67 (diff)
downloadvboot-e6700f4c70fe72850ae4f3f5df19c9281ebcefc8.tar.gz
vboot: update vboot2 functions to use new vb2_error_t
To make explicit when vboot2 error codes should be returned, use the new vb2_error_t type on all functions which return VB2_ERROR_* constants. BUG=b:124141368, chromium:988410 TEST=make clean && make runtests BRANCH=none Change-Id: Idd3ee8afe8c78347783ce5fa829cb78f1e5719e2 Signed-off-by: Joel Kitching <kitching@google.com> Cq-Depend: chromium:1728113, chromium:1728499 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1728292 Reviewed-by: Joel Kitching <kitching@chromium.org> Commit-Queue: Joel Kitching <kitching@chromium.org> Tested-by: Joel Kitching <kitching@chromium.org>
-rw-r--r--firmware/2lib/2api.c12
-rw-r--r--firmware/2lib/2common.c16
-rw-r--r--firmware/2lib/2gbb.c40
-rw-r--r--firmware/2lib/2misc.c23
-rw-r--r--firmware/2lib/2nvstorage.c2
-rw-r--r--firmware/2lib/2rsa.c12
-rw-r--r--firmware/2lib/2secdata.c18
-rw-r--r--firmware/2lib/2secdatak.c18
-rw-r--r--firmware/2lib/2sha_utility.c28
-rw-r--r--firmware/2lib/2stub.c23
-rw-r--r--firmware/2lib/include/2api.h85
-rw-r--r--firmware/2lib/include/2common.h19
-rw-r--r--firmware/2lib/include/2gbb.h14
-rw-r--r--firmware/2lib/include/2misc.h27
-rw-r--r--firmware/2lib/include/2nvstorage.h2
-rw-r--r--firmware/2lib/include/2rsa.h8
-rw-r--r--firmware/2lib/include/2secdata.h24
-rw-r--r--firmware/2lib/include/2sha.h27
-rw-r--r--firmware/include/vboot_api.h2
-rw-r--r--firmware/include/vboot_test.h3
-rw-r--r--firmware/lib/ec_sync.c16
-rw-r--r--firmware/lib/include/rollback_index.h3
-rw-r--r--firmware/lib/include/vboot_common.h28
-rw-r--r--firmware/lib/include/vboot_kernel.h2
-rw-r--r--firmware/lib/mocked_rollback_index.c2
-rw-r--r--firmware/lib/rollback_index.c2
-rw-r--r--firmware/lib/vboot_api_kernel.c4
-rw-r--r--firmware/lib/vboot_common.c24
-rw-r--r--firmware/lib/vboot_common_init.c2
-rw-r--r--firmware/lib/vboot_display.c2
-rw-r--r--firmware/lib/vboot_kernel.c28
-rw-r--r--firmware/lib/vboot_ui.c6
-rw-r--r--firmware/lib20/api.c16
-rw-r--r--firmware/lib20/api_kernel.c24
-rw-r--r--firmware/lib20/common.c35
-rw-r--r--firmware/lib20/include/vb2_common.h65
-rw-r--r--firmware/lib20/kernel.c24
-rw-r--r--firmware/lib20/misc.c8
-rw-r--r--firmware/lib20/packed_key.c11
-rw-r--r--firmware/lib21/api.c10
-rw-r--r--firmware/lib21/common.c60
-rw-r--r--firmware/lib21/include/vb21_common.h61
-rw-r--r--firmware/lib21/misc.c20
-rw-r--r--firmware/lib21/packed_key.c12
-rw-r--r--firmware/stub/vboot_api_stub.c2
-rw-r--r--futility/file_type_usbpd1.c37
-rw-r--r--host/arch/x86/lib/crossystem_arch.c2
-rw-r--r--host/lib/crossystem.c2
-rw-r--r--host/lib/file_keys.c4
-rw-r--r--host/lib/host_key2.c22
-rw-r--r--host/lib/host_misc.c2
-rw-r--r--host/lib/host_signature.c10
-rw-r--r--host/lib/host_signature2.c4
-rw-r--r--host/lib/include/file_keys.h4
-rw-r--r--host/lib/include/host_key.h21
-rw-r--r--host/lib/include/host_misc.h10
-rw-r--r--host/lib/include/host_signature.h10
-rw-r--r--host/lib21/host_fw_preamble.c12
-rw-r--r--host/lib21/host_key.c55
-rw-r--r--host/lib21/host_keyblock.c11
-rw-r--r--host/lib21/host_misc.c9
-rw-r--r--host/lib21/host_signature.c45
-rw-r--r--host/lib21/include/host_fw_preamble2.h12
-rw-r--r--host/lib21/include/host_key2.h52
-rw-r--r--host/lib21/include/host_keyblock2.h11
-rw-r--r--host/lib21/include/host_misc2.h2
-rw-r--r--host/lib21/include/host_signature2.h39
-rw-r--r--tests/vb20_api_kernel_tests.c27
-rw-r--r--tests/vb20_api_tests.c46
-rw-r--r--tests/vb20_kernel_tests.c28
-rw-r--r--tests/vb20_misc_tests.c28
-rw-r--r--tests/vb20_verify_fw.c16
-rw-r--r--tests/vb21_api_tests.c21
-rw-r--r--tests/vb21_misc_tests.c28
-rw-r--r--tests/vb2_api_tests.c16
-rw-r--r--tests/vb2_gbb_tests.c8
-rw-r--r--tests/vb2_misc_tests.c10
-rw-r--r--tests/vboot_api_kernel2_tests.c8
-rw-r--r--tests/vboot_api_kernel4_tests.c4
-rw-r--r--tests/vboot_api_kernel5_tests.c57
-rw-r--r--tests/vboot_api_kernel6_tests.c2
-rw-r--r--tests/vboot_detach_menu_tests.c4
-rw-r--r--tests/vboot_kernel_tests.c66
-rw-r--r--tests/verify_kernel.c6
84 files changed, 756 insertions, 865 deletions
diff --git a/firmware/2lib/2api.c b/firmware/2lib/2api.c
index f2e7d6bb..f39ba290 100644
--- a/firmware/2lib/2api.c
+++ b/firmware/2lib/2api.c
@@ -24,9 +24,9 @@ void vb2api_fail(struct vb2_context *ctx, uint8_t reason, uint8_t subcode)
vb2_fail(ctx, reason, subcode);
}
-int vb2api_fw_phase1(struct vb2_context *ctx)
+vb2_error_t vb2api_fw_phase1(struct vb2_context *ctx)
{
- int rv;
+ vb2_error_t rv;
struct vb2_shared_data *sd;
/* Initialize the vboot context if it hasn't been yet */
@@ -116,9 +116,9 @@ int vb2api_fw_phase1(struct vb2_context *ctx)
return VB2_SUCCESS;
}
-int vb2api_fw_phase2(struct vb2_context *ctx)
+vb2_error_t vb2api_fw_phase2(struct vb2_context *ctx)
{
- int rv;
+ vb2_error_t rv;
/*
* Use the slot from the last boot if this is a resume. Do not set
@@ -159,7 +159,7 @@ int vb2api_fw_phase2(struct vb2_context *ctx)
return VB2_SUCCESS;
}
-int vb2api_extend_hash(struct vb2_context *ctx,
+vb2_error_t vb2api_extend_hash(struct vb2_context *ctx,
const void *buf,
uint32_t size)
{
@@ -183,7 +183,7 @@ int vb2api_extend_hash(struct vb2_context *ctx,
return vb2_digest_extend(dc, buf, size);
}
-int vb2api_get_pcr_digest(struct vb2_context *ctx,
+vb2_error_t vb2api_get_pcr_digest(struct vb2_context *ctx,
enum vb2_pcr_digest which_digest,
uint8_t *dest,
uint32_t *dest_size)
diff --git a/firmware/2lib/2common.c b/firmware/2lib/2common.c
index 472d5acc..de1fc498 100644
--- a/firmware/2lib/2common.c
+++ b/firmware/2lib/2common.c
@@ -11,7 +11,7 @@
#include "2rsa.h"
#include "2sha.h"
-int vb2_safe_memcmp(const void *s1, const void *s2, size_t size)
+vb2_error_t vb2_safe_memcmp(const void *s1, const void *s2, size_t size)
{
const unsigned char *us1 = s1;
const unsigned char *us2 = s2;
@@ -30,7 +30,8 @@ int vb2_safe_memcmp(const void *s1, const void *s2, size_t size)
return result != 0;
}
-int vb2_align(uint8_t **ptr, uint32_t *size, uint32_t align, uint32_t want_size)
+vb2_error_t vb2_align(uint8_t **ptr, uint32_t *size, uint32_t align,
+ uint32_t want_size)
{
uintptr_t p = (uintptr_t)*ptr;
uintptr_t offs = p & (align - 1);
@@ -77,8 +78,7 @@ void *vb2_workbuf_alloc(struct vb2_workbuf *wb, uint32_t size)
return ptr;
}
-void *vb2_workbuf_realloc(struct vb2_workbuf *wb,
- uint32_t oldsize,
+void *vb2_workbuf_realloc(struct vb2_workbuf *wb, uint32_t oldsize,
uint32_t newsize)
{
/*
@@ -104,10 +104,10 @@ ptrdiff_t vb2_offset_of(const void *base, const void *ptr)
return (uintptr_t)ptr - (uintptr_t)base;
}
-int vb2_verify_member_inside(const void *parent, size_t parent_size,
- const void *member, size_t member_size,
- ptrdiff_t member_data_offset,
- size_t member_data_size)
+vb2_error_t vb2_verify_member_inside(const void *parent, size_t parent_size,
+ const void *member, size_t member_size,
+ ptrdiff_t member_data_offset,
+ size_t member_data_size)
{
const uintptr_t parent_end = (uintptr_t)parent + parent_size;
const ptrdiff_t member_offs = vb2_offset_of(parent, member);
diff --git a/firmware/2lib/2gbb.c b/firmware/2lib/2gbb.c
index c7f22564..a752c8ba 100644
--- a/firmware/2lib/2gbb.c
+++ b/firmware/2lib/2gbb.c
@@ -8,14 +8,13 @@
#include "2common.h"
#include "2misc.h"
-static int vb2_gbb_read_key(struct vb2_context *ctx,
- uint32_t offset,
- uint32_t *size,
- struct vb2_packed_key **keyp,
- struct vb2_workbuf *wb)
+static vb2_error_t vb2_gbb_read_key(struct vb2_context *ctx, uint32_t offset,
+ uint32_t *size,
+ struct vb2_packed_key **keyp,
+ struct vb2_workbuf *wb)
{
struct vb2_workbuf wblocal = *wb;
- int rv;
+ vb2_error_t rv;
/* Check offset and size. */
if (offset < sizeof(struct vb2_gbb_header))
@@ -56,41 +55,38 @@ static int vb2_gbb_read_key(struct vb2_context *ctx,
return rv;
}
-int vb2_gbb_read_root_key(struct vb2_context *ctx,
- struct vb2_packed_key **keyp,
- uint32_t *size,
- struct vb2_workbuf *wb)
+vb2_error_t vb2_gbb_read_root_key(struct vb2_context *ctx,
+ struct vb2_packed_key **keyp, uint32_t *size,
+ struct vb2_workbuf *wb)
{
struct vb2_gbb_header *gbb = vb2_get_gbb(ctx);
uint32_t size_in = gbb->rootkey_size;
- int ret = vb2_gbb_read_key(ctx, gbb->rootkey_offset,
- &size_in, keyp, wb);
+ vb2_error_t ret = vb2_gbb_read_key(ctx, gbb->rootkey_offset,
+ &size_in, keyp, wb);
if (size)
*size = size_in;
return ret;
}
-int vb2_gbb_read_recovery_key(struct vb2_context *ctx,
- struct vb2_packed_key **keyp,
- uint32_t *size,
- struct vb2_workbuf *wb)
+vb2_error_t vb2_gbb_read_recovery_key(struct vb2_context *ctx,
+ struct vb2_packed_key **keyp,
+ uint32_t *size, struct vb2_workbuf *wb)
{
struct vb2_gbb_header *gbb = vb2_get_gbb(ctx);
uint32_t size_in = gbb->recovery_key_size;
- int ret = vb2_gbb_read_key(ctx, gbb->recovery_key_offset,
- &size_in, keyp, wb);
+ vb2_error_t ret = vb2_gbb_read_key(ctx, gbb->recovery_key_offset,
+ &size_in, keyp, wb);
if (size)
*size = size_in;
return ret;
}
-int vb2api_gbb_read_hwid(struct vb2_context *ctx,
- char *hwid,
- uint32_t *size)
+vb2_error_t vb2api_gbb_read_hwid(struct vb2_context *ctx, char *hwid,
+ uint32_t *size)
{
struct vb2_gbb_header *gbb = vb2_get_gbb(ctx);
uint32_t i;
- int ret;
+ vb2_error_t ret;
if (gbb->hwid_size == 0) {
VB2_DEBUG("invalid HWID size %d\n", gbb->hwid_size);
diff --git a/firmware/2lib/2misc.c b/firmware/2lib/2misc.c
index 03e0353a..19380973 100644
--- a/firmware/2lib/2misc.c
+++ b/firmware/2lib/2misc.c
@@ -14,7 +14,7 @@
#include "2sha.h"
#include "2rsa.h"
-int vb2_validate_gbb_signature(uint8_t *sig)
+vb2_error_t vb2_validate_gbb_signature(uint8_t *sig)
{
const static uint8_t sig_xor[VB2_GBB_SIGNATURE_SIZE] =
VB2_GBB_XOR_SIGNATURE;
@@ -44,9 +44,10 @@ void vb2_set_workbuf_used(struct vb2_context *ctx, uint32_t used)
ctx->workbuf_used = vb2_wb_round_up(used);
}
-int vb2_read_gbb_header(struct vb2_context *ctx, struct vb2_gbb_header *gbb)
+vb2_error_t vb2_read_gbb_header(struct vb2_context *ctx,
+ struct vb2_gbb_header *gbb)
{
- int rv;
+ vb2_error_t rv;
/* Read the entire header */
rv = vb2ex_read_resource(ctx, VB2_RES_GBB, 0, gbb, sizeof(*gbb));
@@ -128,7 +129,7 @@ void vb2_fail(struct vb2_context *ctx, uint8_t reason, uint8_t subcode)
#pragma GCC diagnostic push
/* Don't warn for the version_minor check even if the checked version is 0. */
#pragma GCC diagnostic ignored "-Wtype-limits"
-int vb2_init_context(struct vb2_context *ctx)
+vb2_error_t vb2_init_context(struct vb2_context *ctx)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
@@ -208,12 +209,12 @@ void vb2_check_recovery(struct vb2_context *ctx)
}
}
-int vb2_fw_parse_gbb(struct vb2_context *ctx)
+vb2_error_t vb2_fw_parse_gbb(struct vb2_context *ctx)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
struct vb2_gbb_header *gbb;
struct vb2_workbuf wb;
- int rv;
+ vb2_error_t rv;
vb2_workbuf_from_ctx(ctx, &wb);
@@ -233,7 +234,7 @@ int vb2_fw_parse_gbb(struct vb2_context *ctx)
return VB2_SUCCESS;
}
-int vb2_check_dev_switch(struct vb2_context *ctx)
+vb2_error_t vb2_check_dev_switch(struct vb2_context *ctx)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
struct vb2_gbb_header *gbb = vb2_get_gbb(ctx);
@@ -241,7 +242,7 @@ int vb2_check_dev_switch(struct vb2_context *ctx)
uint32_t old_flags;
int is_dev = 0;
int use_secdata = 1;
- int rv;
+ vb2_error_t rv;
/* Read secure flags */
rv = vb2_secdata_get(ctx, VB2_SECDATA_FLAGS, &flags);
@@ -348,9 +349,9 @@ int vb2_check_dev_switch(struct vb2_context *ctx)
return VB2_SUCCESS;
}
-int vb2_check_tpm_clear(struct vb2_context *ctx)
+vb2_error_t vb2_check_tpm_clear(struct vb2_context *ctx)
{
- int rv;
+ vb2_error_t rv;
/* Check if we've been asked to clear the owner */
if (!vb2_nv_get(ctx, VB2_NV_CLEAR_TPM_OWNER_REQUEST))
@@ -376,7 +377,7 @@ int vb2_check_tpm_clear(struct vb2_context *ctx)
return VB2_SUCCESS;
}
-int vb2_select_fw_slot(struct vb2_context *ctx)
+vb2_error_t vb2_select_fw_slot(struct vb2_context *ctx)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
uint32_t tries;
diff --git a/firmware/2lib/2nvstorage.c b/firmware/2lib/2nvstorage.c
index 95d2f6e7..a418a559 100644
--- a/firmware/2lib/2nvstorage.c
+++ b/firmware/2lib/2nvstorage.c
@@ -38,7 +38,7 @@ int vb2_nv_get_size(const struct vb2_context *ctx)
* @param ctx Context pointer
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_nv_check_crc(const struct vb2_context *ctx)
+vb2_error_t vb2_nv_check_crc(const struct vb2_context *ctx)
{
const uint8_t *p = ctx->nvdata;
const int offs = ctx->flags & VB2_CONTEXT_NVDATA_V2 ?
diff --git a/firmware/2lib/2rsa.c b/firmware/2lib/2rsa.c
index 5fda9599..199c1c2e 100644
--- a/firmware/2lib/2rsa.c
+++ b/firmware/2lib/2rsa.c
@@ -320,7 +320,8 @@ static const uint8_t sha512_tail[] = {
* @param key Key to take signature and hash algorithms from
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb2_check_padding(const uint8_t *sig, const struct vb2_public_key *key)
+vb2_error_t vb2_check_padding(const uint8_t *sig,
+ const struct vb2_public_key *key)
{
/* Determine padding to use depending on the signature type */
uint32_t sig_size = vb2_rsa_sig_size(key->sig_alg);
@@ -368,10 +369,9 @@ int vb2_check_padding(const uint8_t *sig, const struct vb2_public_key *key)
return result ? VB2_ERROR_RSA_PADDING : VB2_SUCCESS;
}
-int vb2_rsa_verify_digest(const struct vb2_public_key *key,
- uint8_t *sig,
- const uint8_t *digest,
- const struct vb2_workbuf *wb)
+vb2_error_t vb2_rsa_verify_digest(const struct vb2_public_key *key,
+ uint8_t *sig, const uint8_t *digest,
+ const struct vb2_workbuf *wb)
{
struct vb2_workbuf wblocal = *wb;
uint32_t *workbuf32;
@@ -379,7 +379,7 @@ int vb2_rsa_verify_digest(const struct vb2_public_key *key,
int sig_size;
int pad_size;
int exp;
- int rv;
+ vb2_error_t rv;
if (!key || !sig || !digest)
return VB2_ERROR_RSA_VERIFY_PARAM;
diff --git a/firmware/2lib/2secdata.c b/firmware/2lib/2secdata.c
index e4b42e44..aaca7683 100644
--- a/firmware/2lib/2secdata.c
+++ b/firmware/2lib/2secdata.c
@@ -11,7 +11,7 @@
#include "2misc.h"
#include "2secdata.h"
-int vb2api_secdata_check(const struct vb2_context *ctx)
+vb2_error_t vb2api_secdata_check(const struct vb2_context *ctx)
{
const struct vb2_secdata *sec =
(const struct vb2_secdata *)ctx->secdata;
@@ -27,7 +27,7 @@ int vb2api_secdata_check(const struct vb2_context *ctx)
return VB2_SUCCESS;
}
-int vb2api_secdata_create(struct vb2_context *ctx)
+vb2_error_t vb2api_secdata_create(struct vb2_context *ctx)
{
struct vb2_secdata *sec = (struct vb2_secdata *)ctx->secdata;
@@ -43,10 +43,10 @@ int vb2api_secdata_create(struct vb2_context *ctx)
return VB2_SUCCESS;
}
-int vb2_secdata_init(struct vb2_context *ctx)
+vb2_error_t vb2_secdata_init(struct vb2_context *ctx)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
- int rv;
+ vb2_error_t rv;
rv = vb2api_secdata_check(ctx);
if (rv)
@@ -65,9 +65,8 @@ int vb2_secdata_init(struct vb2_context *ctx)
return VB2_SUCCESS;
}
-int vb2_secdata_get(struct vb2_context *ctx,
- enum vb2_secdata_param param,
- uint32_t *dest)
+vb2_error_t vb2_secdata_get(struct vb2_context *ctx,
+ enum vb2_secdata_param param, uint32_t *dest)
{
struct vb2_secdata *sec = (struct vb2_secdata *)ctx->secdata;
@@ -88,9 +87,8 @@ int vb2_secdata_get(struct vb2_context *ctx,
}
}
-int vb2_secdata_set(struct vb2_context *ctx,
- enum vb2_secdata_param param,
- uint32_t value)
+vb2_error_t vb2_secdata_set(struct vb2_context *ctx,
+ enum vb2_secdata_param param, uint32_t value)
{
struct vb2_secdata *sec = (struct vb2_secdata *)ctx->secdata;
uint32_t now;
diff --git a/firmware/2lib/2secdatak.c b/firmware/2lib/2secdatak.c
index 228312d8..d965eb44 100644
--- a/firmware/2lib/2secdatak.c
+++ b/firmware/2lib/2secdatak.c
@@ -11,7 +11,7 @@
#include "2misc.h"
#include "2secdata.h"
-int vb2api_secdatak_check(const struct vb2_context *ctx)
+vb2_error_t vb2api_secdatak_check(const struct vb2_context *ctx)
{
const struct vb2_secdatak *sec =
(const struct vb2_secdatak *)ctx->secdatak;
@@ -23,7 +23,7 @@ int vb2api_secdatak_check(const struct vb2_context *ctx)
return VB2_SUCCESS;
}
-int vb2api_secdatak_create(struct vb2_context *ctx)
+vb2_error_t vb2api_secdatak_create(struct vb2_context *ctx)
{
struct vb2_secdatak *sec = (struct vb2_secdatak *)ctx->secdatak;
@@ -42,11 +42,11 @@ int vb2api_secdatak_create(struct vb2_context *ctx)
return VB2_SUCCESS;
}
-int vb2_secdatak_init(struct vb2_context *ctx)
+vb2_error_t vb2_secdatak_init(struct vb2_context *ctx)
{
struct vb2_secdatak *sec = (struct vb2_secdatak *)ctx->secdatak;
struct vb2_shared_data *sd = vb2_get_sd(ctx);
- int rv;
+ vb2_error_t rv;
rv = vb2api_secdatak_check(ctx);
if (rv)
@@ -63,9 +63,8 @@ int vb2_secdatak_init(struct vb2_context *ctx)
return VB2_SUCCESS;
}
-int vb2_secdatak_get(struct vb2_context *ctx,
- enum vb2_secdatak_param param,
- uint32_t *dest)
+vb2_error_t vb2_secdatak_get(struct vb2_context *ctx,
+ enum vb2_secdatak_param param, uint32_t *dest)
{
struct vb2_secdatak *sec = (struct vb2_secdatak *)ctx->secdatak;
@@ -82,9 +81,8 @@ int vb2_secdatak_get(struct vb2_context *ctx,
}
}
-int vb2_secdatak_set(struct vb2_context *ctx,
- enum vb2_secdatak_param param,
- uint32_t value)
+vb2_error_t vb2_secdatak_set(struct vb2_context *ctx,
+ enum vb2_secdatak_param param, uint32_t value)
{
struct vb2_secdatak *sec = (struct vb2_secdatak *)ctx->secdatak;
uint32_t now;
diff --git a/firmware/2lib/2sha_utility.c b/firmware/2lib/2sha_utility.c
index c45606bb..cc36b99f 100644
--- a/firmware/2lib/2sha_utility.c
+++ b/firmware/2lib/2sha_utility.c
@@ -56,7 +56,7 @@ enum vb2_hash_algorithm vb2_crypto_to_hash(uint32_t algorithm)
return VB2_HASH_INVALID;
}
-int vb2_digest_size(enum vb2_hash_algorithm hash_alg)
+vb2_error_t vb2_digest_size(enum vb2_hash_algorithm hash_alg)
{
switch (hash_alg) {
#if VB2_SUPPORT_SHA1
@@ -76,7 +76,7 @@ int vb2_digest_size(enum vb2_hash_algorithm hash_alg)
}
}
-int vb2_hash_block_size(enum vb2_hash_algorithm alg)
+vb2_error_t vb2_hash_block_size(enum vb2_hash_algorithm alg)
{
switch (alg) {
#if VB2_SUPPORT_SHA1
@@ -116,8 +116,8 @@ const char *vb2_get_hash_algorithm_name(enum vb2_hash_algorithm alg)
}
}
-int vb2_digest_init(struct vb2_digest_context *dc,
- enum vb2_hash_algorithm hash_alg)
+vb2_error_t vb2_digest_init(struct vb2_digest_context *dc,
+ enum vb2_hash_algorithm hash_alg)
{
dc->hash_alg = hash_alg;
dc->using_hwcrypto = 0;
@@ -143,9 +143,8 @@ int vb2_digest_init(struct vb2_digest_context *dc,
}
}
-int vb2_digest_extend(struct vb2_digest_context *dc,
- const uint8_t *buf,
- uint32_t size)
+vb2_error_t vb2_digest_extend(struct vb2_digest_context *dc, const uint8_t *buf,
+ uint32_t size)
{
switch (dc->hash_alg) {
#if VB2_SUPPORT_SHA1
@@ -168,9 +167,8 @@ int vb2_digest_extend(struct vb2_digest_context *dc,
}
}
-int vb2_digest_finalize(struct vb2_digest_context *dc,
- uint8_t *digest,
- uint32_t digest_size)
+vb2_error_t vb2_digest_finalize(struct vb2_digest_context *dc, uint8_t *digest,
+ uint32_t digest_size)
{
if (digest_size < vb2_digest_size(dc->hash_alg))
return VB2_ERROR_SHA_FINALIZE_DIGEST_SIZE;
@@ -196,14 +194,12 @@ int vb2_digest_finalize(struct vb2_digest_context *dc,
}
}
-int vb2_digest_buffer(const uint8_t *buf,
- uint32_t size,
- enum vb2_hash_algorithm hash_alg,
- uint8_t *digest,
- uint32_t digest_size)
+vb2_error_t vb2_digest_buffer(const uint8_t *buf, uint32_t size,
+ enum vb2_hash_algorithm hash_alg, uint8_t *digest,
+ uint32_t digest_size)
{
struct vb2_digest_context dc;
- int rv;
+ vb2_error_t rv;
rv = vb2_digest_init(&dc, hash_alg);
if (rv)
diff --git a/firmware/2lib/2stub.c b/firmware/2lib/2stub.c
index 39503a58..0818ed8e 100644
--- a/firmware/2lib/2stub.c
+++ b/firmware/2lib/2stub.c
@@ -25,46 +25,43 @@ void vb2ex_printf(const char *func, const char *fmt, ...)
}
__attribute__((weak))
-int vb2ex_tpm_clear_owner(struct vb2_context *ctx)
+vb2_error_t vb2ex_tpm_clear_owner(struct vb2_context *ctx)
{
fprintf(stderr, "%s: function not implemented\n", __func__);
return VB2_ERROR_EX_UNIMPLEMENTED;
}
__attribute__((weak))
-int vb2ex_read_resource(struct vb2_context *ctx,
- enum vb2_resource_index index,
- uint32_t offset,
- void *buf,
- uint32_t size)
+vb2_error_t vb2ex_read_resource(struct vb2_context *ctx,
+ enum vb2_resource_index index, uint32_t offset,
+ void *buf, uint32_t size)
{
fprintf(stderr, "%s: function not implemented\n", __func__);
return VB2_ERROR_EX_UNIMPLEMENTED;
}
__attribute__((weak))
-int vb2ex_hwcrypto_digest_init(enum vb2_hash_algorithm hash_alg,
- uint32_t data_size)
+vb2_error_t vb2ex_hwcrypto_digest_init(enum vb2_hash_algorithm hash_alg,
+ uint32_t data_size)
{
return VB2_ERROR_EX_HWCRYPTO_UNSUPPORTED;
}
__attribute__((weak))
-int vb2ex_hwcrypto_digest_extend(const uint8_t *buf,
- uint32_t size)
+vb2_error_t vb2ex_hwcrypto_digest_extend(const uint8_t *buf, uint32_t size)
{
return VB2_ERROR_SHA_EXTEND_ALGORITHM; /* Should not be called. */
}
__attribute__((weak))
-int vb2ex_hwcrypto_digest_finalize(uint8_t *digest,
- uint32_t digest_size)
+vb2_error_t vb2ex_hwcrypto_digest_finalize(uint8_t *digest,
+ uint32_t digest_size)
{
return VB2_ERROR_SHA_FINALIZE_ALGORITHM; /* Should not be called. */
}
__attribute__((weak))
-int vb2ex_tpm_set_mode(enum vb2_tpm_mode mode_val)
+vb2_error_t vb2ex_tpm_set_mode(enum vb2_tpm_mode mode_val)
{
fprintf(stderr, "%s: function not implemented\n", __func__);
return VB2_ERROR_EX_UNIMPLEMENTED;
diff --git a/firmware/2lib/include/2api.h b/firmware/2lib/include/2api.h
index 487616d4..98f9ff08 100644
--- a/firmware/2lib/include/2api.h
+++ b/firmware/2lib/include/2api.h
@@ -404,7 +404,7 @@ enum vb2_pcr_digest {
* @param ctx Context pointer
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2api_secdata_check(const struct vb2_context *ctx);
+vb2_error_t vb2api_secdata_check(const struct vb2_context *ctx);
/**
* Create fresh data in the secure storage context.
@@ -420,7 +420,7 @@ int vb2api_secdata_check(const struct vb2_context *ctx);
* @param ctx Context pointer
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2api_secdata_create(struct vb2_context *ctx);
+vb2_error_t vb2api_secdata_create(struct vb2_context *ctx);
/**
* Check the CRC of the kernel version secure storage context.
@@ -434,7 +434,7 @@ int vb2api_secdata_create(struct vb2_context *ctx);
* @param ctx Context pointer
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2api_secdatak_check(const struct vb2_context *ctx);
+vb2_error_t vb2api_secdatak_check(const struct vb2_context *ctx);
/**
* Create fresh data in the kernel version secure storage context.
@@ -450,7 +450,7 @@ int vb2api_secdatak_check(const struct vb2_context *ctx);
* @param ctx Context pointer
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2api_secdatak_create(struct vb2_context *ctx);
+vb2_error_t vb2api_secdatak_create(struct vb2_context *ctx);
/**
* Report firmware failure to vboot.
@@ -478,7 +478,7 @@ void vb2api_fail(struct vb2_context *ctx, uint8_t reason, uint8_t subcode);
* @param ctx Vboot context
* @return VB2_SUCCESS, or error code on error.
*/
-int vb2api_fw_phase1(struct vb2_context *ctx);
+vb2_error_t vb2api_fw_phase1(struct vb2_context *ctx);
/**
* Firmware selection, phase 2.
@@ -489,7 +489,7 @@ int vb2api_fw_phase1(struct vb2_context *ctx);
* @param ctx Vboot context
* @return VB2_SUCCESS, or error code on error.
*/
-int vb2api_fw_phase2(struct vb2_context *ctx);
+vb2_error_t vb2api_fw_phase2(struct vb2_context *ctx);
/**
* Firmware selection, phase 3.
@@ -503,12 +503,12 @@ int vb2api_fw_phase2(struct vb2_context *ctx);
* @param ctx Vboot context
* @return VB2_SUCCESS, or error code on error.
*/
-int vb2api_fw_phase3(struct vb2_context *ctx);
+vb2_error_t vb2api_fw_phase3(struct vb2_context *ctx);
/**
* Same, but for new-style structs.
*/
-int vb21api_fw_phase3(struct vb2_context *ctx);
+vb2_error_t vb21api_fw_phase3(struct vb2_context *ctx);
/**
* Initialize hashing data for the specified tag.
@@ -519,14 +519,14 @@ int vb21api_fw_phase3(struct vb2_context *ctx);
* stored here on output.
* @return VB2_SUCCESS, or error code on error.
*/
-int vb2api_init_hash(struct vb2_context *ctx, uint32_t tag, uint32_t *size);
+vb2_error_t vb2api_init_hash(struct vb2_context *ctx, uint32_t tag,
+ uint32_t *size);
/**
* Same, but for new-style structs.
*/
-int vb21api_init_hash(struct vb2_context *ctx,
- const struct vb2_id *id,
- uint32_t *size);
+vb2_error_t vb21api_init_hash(struct vb2_context *ctx, const struct vb2_id *id,
+ uint32_t *size);
/**
* Extend the hash started by vb2api_init_hash() with additional data.
@@ -538,9 +538,8 @@ int vb21api_init_hash(struct vb2_context *ctx,
* @param size Size of data in bytes
* @return VB2_SUCCESS, or error code on error.
*/
-int vb2api_extend_hash(struct vb2_context *ctx,
- const void *buf,
- uint32_t size);
+vb2_error_t vb2api_extend_hash(struct vb2_context *ctx, const void *buf,
+ uint32_t size);
/**
* Check the hash value started by vb2api_init_hash().
@@ -553,7 +552,7 @@ int vb2api_check_hash(struct vb2_context *ctx);
/**
* Same, but for new-style structs.
*/
-int vb21api_check_hash(struct vb2_context *ctx);
+vb2_error_t vb21api_check_hash(struct vb2_context *ctx);
/**
* Check the hash value started by vb2api_init_hash() while retrieving
@@ -564,8 +563,9 @@ int vb21api_check_hash(struct vb2_context *ctx);
* @param digest_out_size optional size of buffer to store digest
* @return VB2_SUCCESS, or error code on error.
*/
-int vb2api_check_hash_get_digest(struct vb2_context *ctx, void *digest_out,
- uint32_t digest_out_size);
+vb2_error_t vb2api_check_hash_get_digest(struct vb2_context *ctx,
+ void *digest_out,
+ uint32_t digest_out_size);
/**
* Get a PCR digest
@@ -578,10 +578,9 @@ int vb2api_check_hash_get_digest(struct vb2_context *ctx, void *digest_out,
* OUT: size of the copied digest
* @return VB2_SUCCESS, or error code on error
*/
-int vb2api_get_pcr_digest(struct vb2_context *ctx,
- enum vb2_pcr_digest which_digest,
- uint8_t *dest,
- uint32_t *dest_size);
+vb2_error_t vb2api_get_pcr_digest(struct vb2_context *ctx,
+ enum vb2_pcr_digest which_digest,
+ uint8_t *dest, uint32_t *dest_size);
/**
* Prepare for kernel verification stage.
@@ -591,7 +590,7 @@ int vb2api_get_pcr_digest(struct vb2_context *ctx,
* @param ctx Vboot context
* @return VB2_SUCCESS, or error code on error.
*/
-int vb2api_kernel_phase1(struct vb2_context *ctx);
+vb2_error_t vb2api_kernel_phase1(struct vb2_context *ctx);
/**
* Load the verified boot block (vblock) for a kernel.
@@ -603,7 +602,7 @@ int vb2api_kernel_phase1(struct vb2_context *ctx);
* @param stream Kernel stream
* @return VB2_SUCCESS, or error code on error.
*/
-int vb2api_load_kernel_vblock(struct vb2_context *ctx);
+vb2_error_t vb2api_load_kernel_vblock(struct vb2_context *ctx);
/**
* Get the size and offset of the kernel data for the most recent vblock.
@@ -616,9 +615,8 @@ int vb2api_load_kernel_vblock(struct vb2_context *ctx);
* @param size_ptr Destination for size of kernel data in bytes.
* @return VB2_SUCCESS, or error code on error.
*/
-int vb2api_get_kernel_size(struct vb2_context *ctx,
- uint32_t *offset_ptr,
- uint32_t *size_ptr);
+vb2_error_t vb2api_get_kernel_size(struct vb2_context *ctx,
+ uint32_t *offset_ptr, uint32_t *size_ptr);
/**
* Verify kernel data using the previously loaded kernel vblock.
@@ -632,9 +630,8 @@ int vb2api_get_kernel_size(struct vb2_context *ctx,
* @param size Size of kernel data in bytes
* @return VB2_SUCCESS, or error code on error.
*/
-int vb2api_verify_kernel_data(struct vb2_context *ctx,
- const void *buf,
- uint32_t size);
+vb2_error_t vb2api_verify_kernel_data(struct vb2_context *ctx, const void *buf,
+ uint32_t size);
/**
* Clean up after kernel verification.
@@ -645,7 +642,7 @@ int vb2api_verify_kernel_data(struct vb2_context *ctx,
* This cleans up intermediate data structures in the vboot context, and
* updates the version in the secure data if necessary.
*/
-int vb2api_kernel_phase3(struct vb2_context *ctx);
+vb2_error_t vb2api_kernel_phase3(struct vb2_context *ctx);
/**
* Read the hardware ID from the GBB, and store it onto the given buffer.
@@ -660,9 +657,8 @@ int vb2api_kernel_phase3(struct vb2_context *ctx);
* also including null terminator.
* @return VB2_SUCCESS, or error code on error.
*/
-int vb2api_gbb_read_hwid(struct vb2_context *ctx,
- char *hwid,
- uint32_t *size);
+vb2_error_t vb2api_gbb_read_hwid(struct vb2_context *ctx, char *hwid,
+ uint32_t *size);
/**
* Retrieve current GBB flags.
@@ -684,7 +680,7 @@ vb2_gbb_flags_t vb2api_gbb_get_flags(struct vb2_context *ctx);
* @param ctx Vboot context
* @return VB2_SUCCESS, or error code on error.
*/
-int vb2ex_tpm_clear_owner(struct vb2_context *ctx);
+vb2_error_t vb2ex_tpm_clear_owner(struct vb2_context *ctx);
/**
* Read a verified boot resource.
@@ -696,11 +692,9 @@ int vb2ex_tpm_clear_owner(struct vb2_context *ctx);
* @param size Amount of data to read
* @return VB2_SUCCESS, or error code on error.
*/
-int vb2ex_read_resource(struct vb2_context *ctx,
- enum vb2_resource_index index,
- uint32_t offset,
- void *buf,
- uint32_t size);
+vb2_error_t vb2ex_read_resource(struct vb2_context *ctx,
+ enum vb2_resource_index index, uint32_t offset,
+ void *buf, uint32_t size);
/**
* Print debug output
@@ -723,8 +717,8 @@ void vb2ex_printf(const char *func, const char *fmt, ...);
* @param data_size Expected total size of data to hash
* @return VB2_SUCCESS, or non-zero error code (HWCRYPTO_UNSUPPORTED not fatal).
*/
-int vb2ex_hwcrypto_digest_init(enum vb2_hash_algorithm hash_alg,
- uint32_t data_size);
+vb2_error_t vb2ex_hwcrypto_digest_init(enum vb2_hash_algorithm hash_alg,
+ uint32_t data_size);
/**
* Extend the hash in the hardware crypto engine with another block of data.
@@ -733,7 +727,7 @@ int vb2ex_hwcrypto_digest_init(enum vb2_hash_algorithm hash_alg,
* @param size Length of data block in bytes
* @return VB2_SUCCESS, or non-zero error code.
*/
-int vb2ex_hwcrypto_digest_extend(const uint8_t *buf, uint32_t size);
+vb2_error_t vb2ex_hwcrypto_digest_extend(const uint8_t *buf, uint32_t size);
/**
* Finalize the digest in the hardware crypto engine and extract the result.
@@ -742,7 +736,8 @@ int vb2ex_hwcrypto_digest_extend(const uint8_t *buf, uint32_t size);
* @param digest_size Length of digest buffer in bytes
* @return VB2_SUCCESS, or non-zero error code.
*/
-int vb2ex_hwcrypto_digest_finalize(uint8_t *digest, uint32_t digest_size);
+vb2_error_t vb2ex_hwcrypto_digest_finalize(uint8_t *digest,
+ uint32_t digest_size);
/*
* Set the current TPM mode value, and validate that it was changed. If one
@@ -757,6 +752,6 @@ int vb2ex_hwcrypto_digest_finalize(uint8_t *digest, uint32_t digest_size);
* or DISABLED from vb2_tpm_mode enum.
* @returns VB2_SUCCESS, or non-zero error code.
*/
-int vb2ex_tpm_set_mode(enum vb2_tpm_mode mode_val);
+vb2_error_t vb2ex_tpm_set_mode(enum vb2_tpm_mode mode_val);
#endif /* VBOOT_2_API_H_ */
diff --git a/firmware/2lib/include/2common.h b/firmware/2lib/include/2common.h
index 7cd8c041..f0df9c0b 100644
--- a/firmware/2lib/include/2common.h
+++ b/firmware/2lib/include/2common.h
@@ -111,8 +111,7 @@ void *vb2_workbuf_alloc(struct vb2_workbuf *wb, uint32_t size);
* @param newsize Requested size in bytes
* @return A pointer to the allocated space, or NULL if error.
*/
-void *vb2_workbuf_realloc(struct vb2_workbuf *wb,
- uint32_t oldsize,
+void *vb2_workbuf_realloc(struct vb2_workbuf *wb, uint32_t oldsize,
uint32_t newsize);
/**
@@ -143,7 +142,7 @@ void vb2_workbuf_free(struct vb2_workbuf *wb, uint32_t size);
* @param size Number of bytes to compare
* @return 0 if match or size=0, non-zero if at least one byte mismatched.
*/
-int vb2_safe_memcmp(const void *s1, const void *s2, size_t size);
+vb2_error_t vb2_safe_memcmp(const void *s1, const void *s2, size_t size);
/**
* Align a buffer and check its size.
@@ -154,10 +153,8 @@ int vb2_safe_memcmp(const void *s1, const void *s2, size_t size);
* @param want_size Required size
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb2_align(uint8_t **ptr,
- uint32_t *size,
- uint32_t align,
- uint32_t want_size);
+vb2_error_t vb2_align(uint8_t **ptr, uint32_t *size, uint32_t align,
+ uint32_t want_size);
/**
* Return offset of ptr from base.
@@ -233,10 +230,10 @@ const struct vb2_id *vb2_hash_id(enum vb2_hash_algorithm hash_alg);
* @param member_data_size Size of member data in bytes
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb2_verify_member_inside(const void *parent, size_t parent_size,
- const void *member, size_t member_size,
- ptrdiff_t member_data_offset,
- size_t member_data_size);
+vb2_error_t vb2_verify_member_inside(const void *parent, size_t parent_size,
+ const void *member, size_t member_size,
+ ptrdiff_t member_data_offset,
+ size_t member_data_size);
/*
* Helper function to get data pointed to by a public key.
diff --git a/firmware/2lib/include/2gbb.h b/firmware/2lib/include/2gbb.h
index 6ad0eb3b..4e4bd906 100644
--- a/firmware/2lib/include/2gbb.h
+++ b/firmware/2lib/include/2gbb.h
@@ -24,10 +24,9 @@ struct vb2_workbuf;
* @param wb Workbuf for data storage.
* @return VB2_SUCCESS, or error code on error.
*/
-int vb2_gbb_read_root_key(struct vb2_context *ctx,
- struct vb2_packed_key **keyp,
- uint32_t *size,
- struct vb2_workbuf *wb);
+vb2_error_t vb2_gbb_read_root_key(struct vb2_context *ctx,
+ struct vb2_packed_key **keyp, uint32_t *size,
+ struct vb2_workbuf *wb);
/**
* Read the recovery key from the GBB, and store it onto the given workbuf.
@@ -40,9 +39,8 @@ int vb2_gbb_read_root_key(struct vb2_context *ctx,
* @param wb Workbuf for data storage.
* @return VB2_SUCCESS, or error code on error.
*/
-int vb2_gbb_read_recovery_key(struct vb2_context *ctx,
- struct vb2_packed_key **keyp,
- uint32_t *size,
- struct vb2_workbuf *wb);
+vb2_error_t vb2_gbb_read_recovery_key(struct vb2_context *ctx,
+ struct vb2_packed_key **keyp,
+ uint32_t *size, struct vb2_workbuf *wb);
#endif /* VBOOT_REFERENCE_VBOOT_2GBB_H_ */
diff --git a/firmware/2lib/include/2misc.h b/firmware/2lib/include/2misc.h
index 3e1f1000..3b61bda4 100644
--- a/firmware/2lib/include/2misc.h
+++ b/firmware/2lib/include/2misc.h
@@ -39,7 +39,7 @@ struct vb2_gbb_header *vb2_get_gbb(struct vb2_context *ctx);
* @param sig Pointer to the signature bytes to validate
* @return VB2_SUCCESS if valid or non-zero if error.
*/
-int vb2_validate_gbb_signature(uint8_t *sig);
+vb2_error_t vb2_validate_gbb_signature(uint8_t *sig);
/**
* Initialize a work buffer from the vboot context.
@@ -69,7 +69,8 @@ void vb2_set_workbuf_used(struct vb2_context *ctx, uint32_t used);
* @param gbb Destination for header
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb2_read_gbb_header(struct vb2_context *ctx, struct vb2_gbb_header *gbb);
+vb2_error_t vb2_read_gbb_header(struct vb2_context *ctx,
+ struct vb2_gbb_header *gbb);
/**
* Handle vboot failure.
@@ -95,7 +96,7 @@ void vb2_fail(struct vb2_context *ctx, uint8_t reason, uint8_t subcode);
* @param ctx Vboot context to initialize
* @return VB2_SUCCESS, or error code on error.
*/
-int vb2_init_context(struct vb2_context *ctx);
+vb2_error_t vb2_init_context(struct vb2_context *ctx);
/**
* Check for recovery reasons we can determine early in the boot process.
@@ -116,7 +117,7 @@ void vb2_check_recovery(struct vb2_context *ctx);
* @param ctx Vboot context
* @return VB2_SUCCESS, or error code on error.
*/
-int vb2_fw_parse_gbb(struct vb2_context *ctx);
+vb2_error_t vb2_fw_parse_gbb(struct vb2_context *ctx);
/**
* Check developer switch position.
@@ -124,7 +125,7 @@ int vb2_fw_parse_gbb(struct vb2_context *ctx);
* @param ctx Vboot context
* @return VB2_SUCCESS, or error code on error.
*/
-int vb2_check_dev_switch(struct vb2_context *ctx);
+vb2_error_t vb2_check_dev_switch(struct vb2_context *ctx);
/**
* Check if we need to clear the TPM owner.
@@ -132,7 +133,7 @@ int vb2_check_dev_switch(struct vb2_context *ctx);
* @param ctx Vboot context
* @return VB2_SUCCESS, or error code on error.
*/
-int vb2_check_tpm_clear(struct vb2_context *ctx);
+vb2_error_t vb2_check_tpm_clear(struct vb2_context *ctx);
/**
* Decide which firmware slot to try this boot.
@@ -140,7 +141,7 @@ int vb2_check_tpm_clear(struct vb2_context *ctx);
* @param ctx Vboot context
* @return VB2_SUCCESS, or error code on error.
*/
-int vb2_select_fw_slot(struct vb2_context *ctx);
+vb2_error_t vb2_select_fw_slot(struct vb2_context *ctx);
/**
* Verify the firmware keyblock using the root key.
@@ -150,8 +151,8 @@ int vb2_select_fw_slot(struct vb2_context *ctx);
* @param ctx Vboot context
* @return VB2_SUCCESS, or error code on error.
*/
-int vb2_load_fw_keyblock(struct vb2_context *ctx);
-int vb21_load_fw_keyblock(struct vb2_context *ctx);
+vb2_error_t vb2_load_fw_keyblock(struct vb2_context *ctx);
+vb2_error_t vb21_load_fw_keyblock(struct vb2_context *ctx);
/**
* Verify the firmware preamble using the data subkey from the keyblock.
@@ -161,8 +162,8 @@ int vb21_load_fw_keyblock(struct vb2_context *ctx);
* @param ctx Vboot context
* @return VB2_SUCCESS, or error code on error.
*/
-int vb2_load_fw_preamble(struct vb2_context *ctx);
-int vb21_load_fw_preamble(struct vb2_context *ctx);
+vb2_error_t vb2_load_fw_preamble(struct vb2_context *ctx);
+vb2_error_t vb21_load_fw_preamble(struct vb2_context *ctx);
/**
* Verify the kernel keyblock using the previously-loaded kernel key.
@@ -172,7 +173,7 @@ int vb21_load_fw_preamble(struct vb2_context *ctx);
* @param ctx Vboot context
* @return VB2_SUCCESS, or error code on error.
*/
-int vb2_load_kernel_keyblock(struct vb2_context *ctx);
+vb2_error_t vb2_load_kernel_keyblock(struct vb2_context *ctx);
/**
* Verify the kernel preamble using the data subkey from the keyblock.
@@ -182,6 +183,6 @@ int vb2_load_kernel_keyblock(struct vb2_context *ctx);
* @param ctx Vboot context
* @return VB2_SUCCESS, or error code on error.
*/
-int vb2_load_kernel_preamble(struct vb2_context *ctx);
+vb2_error_t vb2_load_kernel_preamble(struct vb2_context *ctx);
#endif /* VBOOT_REFERENCE_VBOOT_2MISC_H_ */
diff --git a/firmware/2lib/include/2nvstorage.h b/firmware/2lib/include/2nvstorage.h
index b51cb6fa..1a6ab8ad 100644
--- a/firmware/2lib/include/2nvstorage.h
+++ b/firmware/2lib/include/2nvstorage.h
@@ -186,7 +186,7 @@ int vb2_nv_get_size(const struct vb2_context *ctx);
* @param ctx Context pointer
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_nv_check_crc(const struct vb2_context *ctx);
+vb2_error_t vb2_nv_check_crc(const struct vb2_context *ctx);
/**
* Initialize the non-volatile storage context and verify its CRC.
diff --git a/firmware/2lib/include/2rsa.h b/firmware/2lib/include/2rsa.h
index 4357029a..0ee72ca5 100644
--- a/firmware/2lib/include/2rsa.h
+++ b/firmware/2lib/include/2rsa.h
@@ -7,6 +7,7 @@
#define VBOOT_REFERENCE_2RSA_H_
#include "2crypto.h"
+#include "2return_codes.h"
#include "2struct.h"
struct vb2_workbuf;
@@ -63,9 +64,8 @@ uint32_t vb2_packed_key_size(enum vb2_signature_algorithm sig_alg);
* @param wb Work buffer
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb2_rsa_verify_digest(const struct vb2_public_key *key,
- uint8_t *sig,
- const uint8_t *digest,
- const struct vb2_workbuf *wb);
+vb2_error_t vb2_rsa_verify_digest(const struct vb2_public_key *key,
+ uint8_t *sig, const uint8_t *digest,
+ const struct vb2_workbuf *wb);
#endif /* VBOOT_REFERENCE_2RSA_H_ */
diff --git a/firmware/2lib/include/2secdata.h b/firmware/2lib/include/2secdata.h
index 2563b3fb..90f4bf23 100644
--- a/firmware/2lib/include/2secdata.h
+++ b/firmware/2lib/include/2secdata.h
@@ -99,7 +99,7 @@ enum vb2_secdatak_param {
* @param ctx Context pointer
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_secdata_init(struct vb2_context *ctx);
+vb2_error_t vb2_secdata_init(struct vb2_context *ctx);
/**
* Read a secure storage value.
@@ -109,9 +109,8 @@ int vb2_secdata_init(struct vb2_context *ctx);
* @param dest Destination for value
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_secdata_get(struct vb2_context *ctx,
- enum vb2_secdata_param param,
- uint32_t *dest);
+vb2_error_t vb2_secdata_get(struct vb2_context *ctx,
+ enum vb2_secdata_param param, uint32_t *dest);
/**
* Write a secure storage value.
@@ -121,9 +120,8 @@ int vb2_secdata_get(struct vb2_context *ctx,
* @param value New value
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_secdata_set(struct vb2_context *ctx,
- enum vb2_secdata_param param,
- uint32_t value);
+vb2_error_t vb2_secdata_set(struct vb2_context *ctx,
+ enum vb2_secdata_param param, uint32_t value);
/*****************************************************************************/
/* Kernel version space functions.
@@ -140,7 +138,7 @@ int vb2_secdata_set(struct vb2_context *ctx,
* @param ctx Context pointer
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_secdatak_init(struct vb2_context *ctx);
+vb2_error_t vb2_secdatak_init(struct vb2_context *ctx);
/**
* Read a secure storage value.
@@ -150,9 +148,8 @@ int vb2_secdatak_init(struct vb2_context *ctx);
* @param dest Destination for value
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_secdatak_get(struct vb2_context *ctx,
- enum vb2_secdatak_param param,
- uint32_t *dest);
+vb2_error_t vb2_secdatak_get(struct vb2_context *ctx,
+ enum vb2_secdatak_param param, uint32_t *dest);
/**
* Write a secure storage value.
@@ -162,8 +159,7 @@ int vb2_secdatak_get(struct vb2_context *ctx,
* @param value New value
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_secdatak_set(struct vb2_context *ctx,
- enum vb2_secdatak_param param,
- uint32_t value);
+vb2_error_t vb2_secdatak_set(struct vb2_context *ctx,
+ enum vb2_secdatak_param param, uint32_t value);
#endif /* VBOOT_REFERENCE_VBOOT_2SECDATA_H_ */
diff --git a/firmware/2lib/include/2sha.h b/firmware/2lib/include/2sha.h
index f41d8e15..646c7c17 100644
--- a/firmware/2lib/include/2sha.h
+++ b/firmware/2lib/include/2sha.h
@@ -12,6 +12,7 @@
#define VBOOT_REFERENCE_2SHA_H_
#include "2crypto.h"
+#include "2return_codes.h"
/* Hash algorithms may be disabled individually to save code space */
@@ -158,7 +159,7 @@ enum vb2_hash_algorithm vb2_crypto_to_hash(uint32_t algorithm);
* @param hash_alg Hash algorithm
* @return The size of the digest, or 0 if error.
*/
-int vb2_digest_size(enum vb2_hash_algorithm hash_alg);
+vb2_error_t vb2_digest_size(enum vb2_hash_algorithm hash_alg);
/**
* Return the block size of a hash algorithm.
@@ -166,7 +167,7 @@ int vb2_digest_size(enum vb2_hash_algorithm hash_alg);
* @param hash_alg Hash algorithm
* @return The block size of the algorithm, or 0 if error.
*/
-int vb2_hash_block_size(enum vb2_hash_algorithm alg);
+vb2_error_t vb2_hash_block_size(enum vb2_hash_algorithm alg);
/**
* Return the name of a hash algorithm
@@ -184,8 +185,8 @@ const char *vb2_get_hash_algorithm_name(enum vb2_hash_algorithm alg);
* @param hash_alg Hash algorithm
* @return VB2_SUCCESS, or non-zero on error.
*/
-int vb2_digest_init(struct vb2_digest_context *dc,
- enum vb2_hash_algorithm hash_alg);
+vb2_error_t vb2_digest_init(struct vb2_digest_context *dc,
+ enum vb2_hash_algorithm hash_alg);
/**
* Extend a digest's hash with another block of data.
@@ -195,9 +196,8 @@ int vb2_digest_init(struct vb2_digest_context *dc,
* @param size Length of data in bytes
* @return VB2_SUCCESS, or non-zero on error.
*/
-int vb2_digest_extend(struct vb2_digest_context *dc,
- const uint8_t *buf,
- uint32_t size);
+vb2_error_t vb2_digest_extend(struct vb2_digest_context *dc, const uint8_t *buf,
+ uint32_t size);
/**
* Finalize a digest and store the result.
@@ -209,9 +209,8 @@ int vb2_digest_extend(struct vb2_digest_context *dc,
* @param digest_size Length of digest buffer in bytes.
* @return VB2_SUCCESS, or non-zero on error.
*/
-int vb2_digest_finalize(struct vb2_digest_context *dc,
- uint8_t *digest,
- uint32_t digest_size);
+vb2_error_t vb2_digest_finalize(struct vb2_digest_context *dc,
+ uint8_t *digest, uint32_t digest_size);
/**
* Calculate the digest of a buffer and store the result.
@@ -223,10 +222,8 @@ int vb2_digest_finalize(struct vb2_digest_context *dc,
* @param digest_size Length of digest buffer in bytes.
* @return VB2_SUCCESS, or non-zero on error.
*/
-int vb2_digest_buffer(const uint8_t *buf,
- uint32_t size,
- enum vb2_hash_algorithm hash_alg,
- uint8_t *digest,
- uint32_t digest_size);
+vb2_error_t vb2_digest_buffer(const uint8_t *buf, uint32_t size,
+ enum vb2_hash_algorithm hash_alg, uint8_t *digest,
+ uint32_t digest_size);
#endif /* VBOOT_REFERENCE_2SHA_H_ */
diff --git a/firmware/include/vboot_api.h b/firmware/include/vboot_api.h
index 0621750b..8fdc18f7 100644
--- a/firmware/include/vboot_api.h
+++ b/firmware/include/vboot_api.h
@@ -877,7 +877,7 @@ enum VbAltFwIndex_t {
* verified before they are run. Currently these #s are defined:
* -1 diagnostic payload
*/
-int VbExLegacy(enum VbAltFwIndex_t altfw_num);
+vb2_error_t VbExLegacy(enum VbAltFwIndex_t altfw_num);
/* Regions for VbExRegionRead() */
enum vb_firmware_region {
diff --git a/firmware/include/vboot_test.h b/firmware/include/vboot_test.h
index b8e59a22..03dc54db 100644
--- a/firmware/include/vboot_test.h
+++ b/firmware/include/vboot_test.h
@@ -19,7 +19,8 @@
*/
struct vb2_public_key;
int vb2_mont_ge(const struct vb2_public_key *key, uint32_t *a);
-int vb2_check_padding(const uint8_t *sig, const struct vb2_public_key *key);
+vb2_error_t vb2_check_padding(const uint8_t *sig,
+ const struct vb2_public_key *key);
enum VbEcBootMode_t;
enum VbEcBootMode_t VbGetMode(void);
diff --git a/firmware/lib/ec_sync.c b/firmware/lib/ec_sync.c
index 23951aff..bdea2f9a 100644
--- a/firmware/lib/ec_sync.c
+++ b/firmware/lib/ec_sync.c
@@ -46,7 +46,7 @@ static void request_recovery(struct vb2_context *ctx, uint32_t recovery_request)
static vb2_error_t protect_ec(struct vb2_context *ctx, int devidx,
enum VbSelectFirmware_t select)
{
- int rv = VbExEcProtect(devidx, select);
+ vb2_error_t rv = VbExEcProtect(devidx, select);
if (rv == VBERROR_EC_REBOOT_TO_RO_REQUIRED) {
VB2_DEBUG("VbExEcProtect() needs reboot\n");
@@ -97,15 +97,16 @@ static const char *image_name_to_string(enum VbSelectFirmware_t select)
* @param select Which firmware image to check
* @return VB2_SUCCESS, or non-zero error code.
*/
-static int check_ec_hash(struct vb2_context *ctx, int devidx,
- enum VbSelectFirmware_t select)
+static vb2_error_t check_ec_hash(struct vb2_context *ctx, int devidx,
+ enum VbSelectFirmware_t select)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
/* Get current EC hash. */
const uint8_t *ec_hash = NULL;
int ec_hash_size;
- int rv = VbExEcHashImage(devidx, select, &ec_hash, &ec_hash_size);
+ vb2_error_t rv = VbExEcHashImage(devidx, select, &ec_hash,
+ &ec_hash_size);
if (rv) {
VB2_DEBUG("VbExEcHashImage() returned %d\n", rv);
request_recovery(ctx, VB2_RECOVERY_EC_HASH_FAILED);
@@ -155,7 +156,8 @@ static vb2_error_t update_ec(struct vb2_context *ctx, int devidx,
/* Get expected EC image */
const uint8_t *want = NULL;
int want_size;
- int rv = VbExEcGetExpectedImage(devidx, select, &want, &want_size);
+ vb2_error_t rv = VbExEcGetExpectedImage(devidx, select, &want,
+ &want_size);
if (rv) {
VB2_DEBUG("VbExEcGetExpectedImage() returned %d\n", rv);
request_recovery(ctx, VB2_RECOVERY_EC_EXPECTED_IMAGE);
@@ -211,7 +213,7 @@ static vb2_error_t check_ec_active(struct vb2_context *ctx, int devidx)
* trust what EC-RW says. If it lies it's in RO, we'll flash RW while
* it's in RW.
*/
- int rv = VbExEcRunningRW(devidx, &in_rw);
+ vb2_error_t rv = VbExEcRunningRW(devidx, &in_rw);
/* If we couldn't determine where the EC was, reboot to recovery. */
if (rv != VBERROR_SUCCESS) {
@@ -239,7 +241,7 @@ static vb2_error_t sync_one_ec(struct vb2_context *ctx, int devidx)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
int is_rw_ab = ctx->flags & RW_AB(devidx);
- int rv;
+ vb2_error_t rv;
const enum VbSelectFirmware_t select_rw = is_rw_ab ?
VB_SELECT_FIRMWARE_EC_UPDATE :
diff --git a/firmware/lib/include/rollback_index.h b/firmware/lib/include/rollback_index.h
index ff369114..c5b119e2 100644
--- a/firmware/lib/include/rollback_index.h
+++ b/firmware/lib/include/rollback_index.h
@@ -9,6 +9,7 @@
#ifndef VBOOT_REFERENCE_ROLLBACK_INDEX_H_
#define VBOOT_REFERENCE_ROLLBACK_INDEX_H_
+#include "2return_codes.h"
#include "sysincludes.h"
#include "tss_constants.h"
@@ -164,6 +165,6 @@ uint32_t SafeWrite(uint32_t index, const void *data, uint32_t length);
/**
* Utility function to turn the virtual dev-mode flag on or off. 0=off, 1=on.
*/
-uint32_t SetVirtualDevMode(int val);
+vb2_error_t SetVirtualDevMode(int val);
#endif /* VBOOT_REFERENCE_ROLLBACK_INDEX_H_ */
diff --git a/firmware/lib/include/vboot_common.h b/firmware/lib/include/vboot_common.h
index 95916488..ac020cc3 100644
--- a/firmware/lib/include/vboot_common.h
+++ b/firmware/lib/include/vboot_common.h
@@ -55,14 +55,14 @@ const uint8_t *GetSignatureDataC(const VbSignature *sig);
/*
* Helper functions to verify the data pointed to by a subfield is inside the
- * parent data. Returns 0 if inside, 1 if error.
+ * parent data.
*/
-int VerifyPublicKeyInside(const void *parent, uint64_t parent_size,
- const struct vb2_packed_key *key);
+vb2_error_t VerifyPublicKeyInside(const void *parent, uint64_t parent_size,
+ const struct vb2_packed_key *key);
-int VerifySignatureInside(const void *parent, uint64_t parent_size,
- const VbSignature *sig);
+vb2_error_t VerifySignatureInside(const void *parent, uint64_t parent_size,
+ const VbSignature *sig);
/**
* Initialize a public key to refer to [key_data].
@@ -86,9 +86,9 @@ int PublicKeyCopy(struct vb2_packed_key *dest,
*
* Returns VBOOT_SUCCESS if successful.
*/
-int VbGetKernelVmlinuzHeader(const VbKernelPreambleHeader *preamble,
- uint64_t *vmlinuz_header_address,
- uint64_t *vmlinuz_header_size);
+vb2_error_t VbGetKernelVmlinuzHeader(const VbKernelPreambleHeader *preamble,
+ uint64_t *vmlinuz_header_address,
+ uint64_t *vmlinuz_header_size);
/**
* Checks if the kernel preamble has flags field. This is available only if the
@@ -97,21 +97,21 @@ int VbGetKernelVmlinuzHeader(const VbKernelPreambleHeader *preamble,
*
* Returns VBOOT_SUCCESS if version is >=2.2.
*/
-int VbKernelHasFlags(const VbKernelPreambleHeader *preamble);
+vb2_error_t VbKernelHasFlags(const VbKernelPreambleHeader *preamble);
/**
* Verify that the Vmlinuz Header is contained inside of the kernel blob.
*
* Returns VBOOT_SUCCESS or VBOOT_PREAMBLE_INVALID on error
*/
-int VerifyVmlinuzInsideKBlob(uint64_t kblob, uint64_t kblob_size,
- uint64_t header, uint64_t header_size);
+vb2_error_t VerifyVmlinuzInsideKBlob(uint64_t kblob, uint64_t kblob_size,
+ uint64_t header, uint64_t header_size);
/**
* Initialize a verified boot shared data structure.
*
* Returns 0 if success, non-zero if error.
*/
-int VbSharedDataInit(VbSharedDataHeader *header, uint64_t size);
+vb2_error_t VbSharedDataInit(VbSharedDataHeader *header, uint64_t size);
/**
* Reserve [size] bytes of the shared data area. Returns the offset of the
@@ -124,8 +124,8 @@ uint64_t VbSharedDataReserve(VbSharedDataHeader *header, uint64_t size);
*
* Returns 0 if success, non-zero if error.
*/
-int VbSharedDataSetKernelKey(VbSharedDataHeader *header,
- const struct vb2_packed_key *src);
+vb2_error_t VbSharedDataSetKernelKey(VbSharedDataHeader *header,
+ const struct vb2_packed_key *src);
/**
* Check whether recovery is allowed or not.
diff --git a/firmware/lib/include/vboot_kernel.h b/firmware/lib/include/vboot_kernel.h
index 61ce2c93..7044ba10 100644
--- a/firmware/lib/include/vboot_kernel.h
+++ b/firmware/lib/include/vboot_kernel.h
@@ -27,7 +27,7 @@ struct vb2_context;
* @return VBERROR_SUCCESS, VBERROR_NO_DISK_FOUND if no disks of the specified
* type were found, or other non-zero VBERROR_ codes for other failures.
*/
-uint32_t VbTryLoadKernel(struct vb2_context *ctx, uint32_t get_info_flags);
+vb2_error_t VbTryLoadKernel(struct vb2_context *ctx, uint32_t get_info_flags);
/* Flags for VbUserConfirms() */
#define VB_CONFIRM_MUST_TRUST_KEYBOARD (1 << 0)
diff --git a/firmware/lib/mocked_rollback_index.c b/firmware/lib/mocked_rollback_index.c
index a4b0ceb0..733b0a54 100644
--- a/firmware/lib/mocked_rollback_index.c
+++ b/firmware/lib/mocked_rollback_index.c
@@ -14,7 +14,7 @@
#include "tss_constants.h"
-uint32_t SetVirtualDevMode(int val)
+vb2_error_t SetVirtualDevMode(int val)
{
return TPM_SUCCESS;
}
diff --git a/firmware/lib/rollback_index.c b/firmware/lib/rollback_index.c
index f52c8b59..41df72bb 100644
--- a/firmware/lib/rollback_index.c
+++ b/firmware/lib/rollback_index.c
@@ -143,7 +143,7 @@ uint32_t WriteSpaceFirmware(RollbackSpaceFirmware *rsf)
return TPM_E_CORRUPTED_STATE;
}
-uint32_t SetVirtualDevMode(int val)
+vb2_error_t SetVirtualDevMode(int val)
{
RollbackSpaceFirmware rsf;
diff --git a/firmware/lib/vboot_api_kernel.c b/firmware/lib/vboot_api_kernel.c
index 9202c6b8..6187655b 100644
--- a/firmware/lib/vboot_api_kernel.c
+++ b/firmware/lib/vboot_api_kernel.c
@@ -66,7 +66,7 @@ uint32_t vb2_get_fwmp_flags(void)
return fwmp.flags;
}
-uint32_t VbTryLoadKernel(struct vb2_context *ctx, uint32_t get_info_flags)
+vb2_error_t VbTryLoadKernel(struct vb2_context *ctx, uint32_t get_info_flags)
{
vb2_error_t retval = VBERROR_UNKNOWN;
VbDiskInfo* disk_info = NULL;
@@ -473,7 +473,7 @@ vb2_error_t VbVerifyMemoryBootImage(struct vb2_context *ctx,
uint32_t allow_fastboot_full_cap = 0;
struct vb2_workbuf wb;
vb2_error_t retval;
- int rv;
+ vb2_error_t rv;
/* Allocate work buffer */
vb2_workbuf_from_ctx(ctx, &wb);
diff --git a/firmware/lib/vboot_common.c b/firmware/lib/vboot_common.c
index e9516476..87500452 100644
--- a/firmware/lib/vboot_common.c
+++ b/firmware/lib/vboot_common.c
@@ -55,16 +55,16 @@ const uint8_t *GetSignatureDataC(const VbSignature *sig)
* the parent data.
*/
-int VerifyPublicKeyInside(const void *parent, uint64_t parent_size,
- const struct vb2_packed_key *key)
+vb2_error_t VerifyPublicKeyInside(const void *parent, uint64_t parent_size,
+ const struct vb2_packed_key *key)
{
return vb2_verify_member_inside(parent, parent_size,
key, sizeof(struct vb2_packed_key),
key->key_offset, key->key_size);
}
-int VerifySignatureInside(const void *parent, uint64_t parent_size,
- const VbSignature *sig)
+vb2_error_t VerifySignatureInside(const void *parent, uint64_t parent_size,
+ const VbSignature *sig)
{
return vb2_verify_member_inside(parent, parent_size,
sig, sizeof(VbSignature),
@@ -92,9 +92,9 @@ int PublicKeyCopy(struct vb2_packed_key *dest, const struct vb2_packed_key *src)
return 0;
}
-int VbGetKernelVmlinuzHeader(const VbKernelPreambleHeader *preamble,
- uint64_t *vmlinuz_header_address,
- uint64_t *vmlinuz_header_size)
+vb2_error_t VbGetKernelVmlinuzHeader(const VbKernelPreambleHeader *preamble,
+ uint64_t *vmlinuz_header_address,
+ uint64_t *vmlinuz_header_size)
{
*vmlinuz_header_address = 0;
*vmlinuz_header_size = 0;
@@ -111,7 +111,7 @@ int VbGetKernelVmlinuzHeader(const VbKernelPreambleHeader *preamble,
return VBOOT_SUCCESS;
}
-int VbKernelHasFlags(const VbKernelPreambleHeader *preamble)
+vb2_error_t VbKernelHasFlags(const VbKernelPreambleHeader *preamble)
{
if (preamble->header_version_minor > 1)
return VBOOT_SUCCESS;
@@ -119,8 +119,8 @@ int VbKernelHasFlags(const VbKernelPreambleHeader *preamble)
return VBOOT_KERNEL_PREAMBLE_NO_FLAGS;
}
-int VerifyVmlinuzInsideKBlob(uint64_t kblob, uint64_t kblob_size,
- uint64_t header, uint64_t header_size)
+vb2_error_t VerifyVmlinuzInsideKBlob(uint64_t kblob, uint64_t kblob_size,
+ uint64_t header, uint64_t header_size)
{
uint64_t end = header-kblob;
if (end > kblob_size)
@@ -147,8 +147,8 @@ uint64_t VbSharedDataReserve(VbSharedDataHeader *header, uint64_t size)
return offs;
}
-int VbSharedDataSetKernelKey(VbSharedDataHeader *header,
- const struct vb2_packed_key *src)
+vb2_error_t VbSharedDataSetKernelKey(VbSharedDataHeader *header,
+ const struct vb2_packed_key *src)
{
struct vb2_packed_key *kdest;
diff --git a/firmware/lib/vboot_common_init.c b/firmware/lib/vboot_common_init.c
index b85c3cc3..44b3eb26 100644
--- a/firmware/lib/vboot_common_init.c
+++ b/firmware/lib/vboot_common_init.c
@@ -14,7 +14,7 @@
#include "vboot_common.h"
#include "utility.h"
-int VbSharedDataInit(VbSharedDataHeader *header, uint64_t size)
+vb2_error_t VbSharedDataInit(VbSharedDataHeader *header, uint64_t size)
{
VB2_DEBUG("VbSharedDataInit, %d bytes, header %d bytes\n", (int)size,
(int)sizeof(VbSharedDataHeader));
diff --git a/firmware/lib/vboot_display.c b/firmware/lib/vboot_display.c
index a2b57ef4..364cd131 100644
--- a/firmware/lib/vboot_display.c
+++ b/firmware/lib/vboot_display.c
@@ -278,7 +278,7 @@ vb2_error_t VbDisplayDebugInfo(struct vb2_context *ctx)
char buf[DEBUG_INFO_SIZE] = "";
char sha1sum[VB2_SHA1_DIGEST_SIZE * 2 + 1];
uint32_t used = 0;
- int ret;
+ vb2_error_t ret;
uint32_t i;
vb2_workbuf_from_ctx(ctx, &wb);
diff --git a/firmware/lib/vboot_kernel.c b/firmware/lib/vboot_kernel.c
index 96461d9f..a8c536d5 100644
--- a/firmware/lib/vboot_kernel.c
+++ b/firmware/lib/vboot_kernel.c
@@ -126,14 +126,11 @@ static uint32_t get_body_offset(uint8_t *kbuf)
* VB2_VERIFY_KERNEL_PREAMBLE_WORKBUF_BYTES bytes.
* @return VB2_SUCCESS, or non-zero error code.
*/
-static int vb2_verify_kernel_vblock(struct vb2_context *ctx,
- uint8_t *kbuf,
- uint32_t kbuf_size,
- const struct vb2_packed_key *kernel_subkey,
- const LoadKernelParams *params,
- uint32_t min_version,
- VbSharedDataKernelPart *shpart,
- struct vb2_workbuf *wb)
+static vb2_error_t vb2_verify_kernel_vblock(
+ struct vb2_context *ctx, uint8_t *kbuf, uint32_t kbuf_size,
+ const struct vb2_packed_key *kernel_subkey,
+ const LoadKernelParams *params, uint32_t min_version,
+ VbSharedDataKernelPart *shpart, struct vb2_workbuf *wb)
{
/* Unpack kernel subkey */
struct vb2_public_key kernel_subkey2;
@@ -311,14 +308,11 @@ enum vb2_load_partition_flags {
* @param wb Workbuf for data storage
* @return VB2_SUCCESS, or non-zero error code.
*/
-static int vb2_load_partition(struct vb2_context *ctx,
- VbExStream_t stream,
- const struct vb2_packed_key *kernel_subkey,
- uint32_t flags,
- LoadKernelParams *params,
- uint32_t min_version,
- VbSharedDataKernelPart *shpart,
- struct vb2_workbuf *wb)
+static vb2_error_t vb2_load_partition(
+ struct vb2_context *ctx, VbExStream_t stream,
+ const struct vb2_packed_key *kernel_subkey, uint32_t flags,
+ LoadKernelParams *params, uint32_t min_version,
+ VbSharedDataKernelPart *shpart, struct vb2_workbuf *wb)
{
uint64_t read_us = 0, start_ts;
struct vb2_workbuf wblocal = *wb;
@@ -444,7 +438,7 @@ vb2_error_t LoadKernel(struct vb2_context *ctx, LoadKernelParams *params)
uint32_t lowest_version = LOWEST_TPM_VERSION;
vb2_error_t retval = VBERROR_UNKNOWN;
int recovery = VB2_RECOVERY_LK_UNSPECIFIED;
- int rv;
+ vb2_error_t rv;
vb2_workbuf_from_ctx(ctx, &wb);
diff --git a/firmware/lib/vboot_ui.c b/firmware/lib/vboot_ui.c
index acce8ca9..cbf653d9 100644
--- a/firmware/lib/vboot_ui.c
+++ b/firmware/lib/vboot_ui.c
@@ -83,7 +83,7 @@ static int VbWantShutdown(struct vb2_context *ctx, uint32_t key)
return shutdown_request;
}
-static uint32_t VbTryUsb(struct vb2_context *ctx)
+static vb2_error_t VbTryUsb(struct vb2_context *ctx)
{
uint32_t retval = VbTryLoadKernel(ctx, VB_DISK_FLAG_REMOVABLE);
if (VBERROR_SUCCESS == retval) {
@@ -677,7 +677,7 @@ static vb2_error_t vb2_developer_ui(struct vb2_context *ctx)
VB2_DEBUG("VbBootDeveloper() - "
"user pressed Ctrl+L; Try alt firmware\n");
if (allow_legacy) {
- int ret;
+ vb2_error_t ret;
ret = vb2_altfw_ui(ctx);
if (ret)
@@ -693,7 +693,7 @@ static vb2_error_t vb2_developer_ui(struct vb2_context *ctx)
* Only show the vendor data ui if it is tag is settable
*/
if (ctx->flags & VB2_CONTEXT_VENDOR_DATA_SETTABLE) {
- int ret;
+ vb2_error_t ret;
VB2_DEBUG("VbBootDeveloper() - user pressed "
"Ctrl+S; Try set vendor data\n");
diff --git a/firmware/lib20/api.c b/firmware/lib20/api.c
index 606b5ceb..7c6b0d46 100644
--- a/firmware/lib20/api.c
+++ b/firmware/lib20/api.c
@@ -15,9 +15,9 @@
#include "2rsa.h"
#include "vb2_common.h"
-int vb2api_fw_phase3(struct vb2_context *ctx)
+vb2_error_t vb2api_fw_phase3(struct vb2_context *ctx)
{
- int rv;
+ vb2_error_t rv;
/* Verify firmware keyblock */
rv = vb2_load_fw_keyblock(ctx);
@@ -36,14 +36,15 @@ int vb2api_fw_phase3(struct vb2_context *ctx)
return VB2_SUCCESS;
}
-int vb2api_init_hash(struct vb2_context *ctx, uint32_t tag, uint32_t *size)
+vb2_error_t vb2api_init_hash(struct vb2_context *ctx, uint32_t tag,
+ uint32_t *size)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
const struct vb2_fw_preamble *pre;
struct vb2_digest_context *dc;
struct vb2_public_key key;
struct vb2_workbuf wb;
- int rv;
+ vb2_error_t rv;
vb2_workbuf_from_ctx(ctx, &wb);
@@ -129,8 +130,9 @@ int vb2api_init_hash(struct vb2_context *ctx, uint32_t tag, uint32_t *size)
return vb2_digest_init(dc, key.hash_alg);
}
-int vb2api_check_hash_get_digest(struct vb2_context *ctx, void *digest_out,
- uint32_t digest_out_size)
+vb2_error_t vb2api_check_hash_get_digest(struct vb2_context *ctx,
+ void *digest_out,
+ uint32_t digest_out_size)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
struct vb2_digest_context *dc = (struct vb2_digest_context *)
@@ -142,7 +144,7 @@ int vb2api_check_hash_get_digest(struct vb2_context *ctx, void *digest_out,
struct vb2_fw_preamble *pre;
struct vb2_public_key key;
- int rv;
+ vb2_error_t rv;
vb2_workbuf_from_ctx(ctx, &wb);
diff --git a/firmware/lib20/api_kernel.c b/firmware/lib20/api_kernel.c
index dbe47e61..8e5f5e61 100644
--- a/firmware/lib20/api_kernel.c
+++ b/firmware/lib20/api_kernel.c
@@ -15,13 +15,13 @@
#include "2rsa.h"
#include "vb2_common.h"
-int vb2api_kernel_phase1(struct vb2_context *ctx)
+vb2_error_t vb2api_kernel_phase1(struct vb2_context *ctx)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
struct vb2_workbuf wb;
uint8_t *key_data;
uint32_t key_size;
- int rv;
+ vb2_error_t rv;
vb2_workbuf_from_ctx(ctx, &wb);
@@ -125,9 +125,9 @@ int vb2api_kernel_phase1(struct vb2_context *ctx)
return VB2_SUCCESS;
}
-int vb2api_load_kernel_vblock(struct vb2_context *ctx)
+vb2_error_t vb2api_load_kernel_vblock(struct vb2_context *ctx)
{
- int rv;
+ vb2_error_t rv;
/* Verify kernel keyblock */
rv = vb2_load_kernel_keyblock(ctx);
@@ -142,9 +142,8 @@ int vb2api_load_kernel_vblock(struct vb2_context *ctx)
return VB2_SUCCESS;
}
-int vb2api_get_kernel_size(struct vb2_context *ctx,
- uint32_t *offset_ptr,
- uint32_t *size_ptr)
+vb2_error_t vb2api_get_kernel_size(struct vb2_context *ctx,
+ uint32_t *offset_ptr, uint32_t *size_ptr)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
const struct vb2_kernel_preamble *pre;
@@ -170,9 +169,8 @@ int vb2api_get_kernel_size(struct vb2_context *ctx,
return VB2_SUCCESS;
}
-int vb2api_verify_kernel_data(struct vb2_context *ctx,
- const void *buf,
- uint32_t size)
+vb2_error_t vb2api_verify_kernel_data(struct vb2_context *ctx, const void *buf,
+ uint32_t size)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
struct vb2_kernel_preamble *pre;
@@ -183,7 +181,7 @@ int vb2api_verify_kernel_data(struct vb2_context *ctx,
uint8_t *digest;
uint32_t digest_size;
- int rv;
+ vb2_error_t rv;
vb2_workbuf_from_ctx(ctx, &wb);
@@ -250,10 +248,10 @@ int vb2api_verify_kernel_data(struct vb2_context *ctx,
return vb2_verify_digest(&key, &pre->body_signature, digest, &wb);
}
-int vb2api_kernel_phase3(struct vb2_context *ctx)
+vb2_error_t vb2api_kernel_phase3(struct vb2_context *ctx)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
- int rv;
+ vb2_error_t rv;
/*
* If the kernel is a newer version than in secure storage, and the
diff --git a/firmware/lib20/common.c b/firmware/lib20/common.c
index 64644d4a..8e9a2d85 100644
--- a/firmware/lib20/common.c
+++ b/firmware/lib20/common.c
@@ -16,7 +16,7 @@ uint8_t *vb2_signature_data(struct vb2_signature *sig)
return (uint8_t *)sig + sig->sig_offset;
}
-int vb2_verify_signature_inside(const void *parent,
+vb2_error_t vb2_verify_signature_inside(const void *parent,
uint32_t parent_size,
const struct vb2_signature *sig)
{
@@ -25,10 +25,9 @@ int vb2_verify_signature_inside(const void *parent,
sig->sig_offset, sig->sig_size);
}
-int vb2_verify_digest(const struct vb2_public_key *key,
- struct vb2_signature *sig,
- const uint8_t *digest,
- const struct vb2_workbuf *wb)
+vb2_error_t vb2_verify_digest(const struct vb2_public_key *key,
+ struct vb2_signature *sig, const uint8_t *digest,
+ const struct vb2_workbuf *wb)
{
uint8_t *sig_data = vb2_signature_data(sig);
@@ -43,7 +42,7 @@ int vb2_verify_digest(const struct vb2_public_key *key,
return vb2_rsa_verify_digest(key, sig_data, digest, wb);
}
-int vb2_verify_data(const uint8_t *data,
+vb2_error_t vb2_verify_data(const uint8_t *data,
uint32_t size,
struct vb2_signature *sig,
const struct vb2_public_key *key,
@@ -53,7 +52,7 @@ int vb2_verify_data(const uint8_t *data,
struct vb2_digest_context *dc;
uint8_t *digest;
uint32_t digest_size;
- int rv;
+ vb2_error_t rv;
if (sig->data_size > size) {
VB2_DEBUG("Data buffer smaller than length of signed data.\n");
@@ -91,9 +90,8 @@ int vb2_verify_data(const uint8_t *data,
return vb2_verify_digest(key, sig, digest, &wblocal);
}
-int vb2_check_keyblock(const struct vb2_keyblock *block,
- uint32_t size,
- const struct vb2_signature *sig)
+vb2_error_t vb2_check_keyblock(const struct vb2_keyblock *block, uint32_t size,
+ const struct vb2_signature *sig)
{
if(size < sizeof(*block)) {
VB2_DEBUG("Not enough space for key block header.\n");
@@ -147,13 +145,12 @@ int vb2_check_keyblock(const struct vb2_keyblock *block,
return VB2_SUCCESS;
}
-int vb2_verify_keyblock(struct vb2_keyblock *block,
- uint32_t size,
- const struct vb2_public_key *key,
- const struct vb2_workbuf *wb)
+vb2_error_t vb2_verify_keyblock(struct vb2_keyblock *block, uint32_t size,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *wb)
{
struct vb2_signature *sig = &block->keyblock_signature;
- int rv;
+ vb2_error_t rv;
/* Sanity check keyblock before attempting signature check of data */
rv = vb2_check_keyblock(block, size, sig);
@@ -171,10 +168,10 @@ int vb2_verify_keyblock(struct vb2_keyblock *block,
return VB2_SUCCESS;
}
-int vb2_verify_fw_preamble(struct vb2_fw_preamble *preamble,
- uint32_t size,
- const struct vb2_public_key *key,
- const struct vb2_workbuf *wb)
+vb2_error_t vb2_verify_fw_preamble(struct vb2_fw_preamble *preamble,
+ uint32_t size,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *wb)
{
struct vb2_signature *sig = &preamble->preamble_signature;
diff --git a/firmware/lib20/include/vb2_common.h b/firmware/lib20/include/vb2_common.h
index 2f70d544..d16572a5 100644
--- a/firmware/lib20/include/vb2_common.h
+++ b/firmware/lib20/include/vb2_common.h
@@ -32,9 +32,9 @@ uint8_t *vb2_signature_data(struct vb2_signature *sig);
* @param sig Signature pointer
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb2_verify_signature_inside(const void *parent,
- uint32_t parent_size,
- const struct vb2_signature *sig);
+vb2_error_t vb2_verify_signature_inside(const void *parent,
+ uint32_t parent_size,
+ const struct vb2_signature *sig);
/**
* Unpack a vboot1-format key buffer for use in verification
@@ -47,9 +47,8 @@ int vb2_verify_signature_inside(const void *parent,
* @param size Size of buffer in bytes
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_unpack_key_buffer(struct vb2_public_key *key,
- const uint8_t *buf,
- uint32_t size);
+vb2_error_t vb2_unpack_key_buffer(struct vb2_public_key *key,
+ const uint8_t *buf, uint32_t size);
/**
* Unpack a vboot1-format key for use in verification
@@ -62,8 +61,8 @@ int vb2_unpack_key_buffer(struct vb2_public_key *key,
* @param size Size of buffer in bytes
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_unpack_key(struct vb2_public_key *key,
- const struct vb2_packed_key *packed_key);
+vb2_error_t vb2_unpack_key(struct vb2_public_key *key,
+ const struct vb2_packed_key *packed_key);
/**
* Verify a signature against an expected hash digest.
@@ -74,10 +73,9 @@ int vb2_unpack_key(struct vb2_public_key *key,
* @param wb Work buffer
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb2_verify_digest(const struct vb2_public_key *key,
- struct vb2_signature *sig,
- const uint8_t *digest,
- const struct vb2_workbuf *wb);
+vb2_error_t vb2_verify_digest(const struct vb2_public_key *key,
+ struct vb2_signature *sig, const uint8_t *digest,
+ const struct vb2_workbuf *wb);
/**
* Verify data matches signature.
@@ -90,11 +88,10 @@ int vb2_verify_digest(const struct vb2_public_key *key,
* @param wb Work buffer
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_verify_data(const uint8_t *data,
- uint32_t size,
- struct vb2_signature *sig,
- const struct vb2_public_key *key,
- const struct vb2_workbuf *wb);
+vb2_error_t vb2_verify_data(const uint8_t *data, uint32_t size,
+ struct vb2_signature *sig,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *wb);
/**
* Check the sanity of a key block structure.
@@ -108,9 +105,8 @@ int vb2_verify_data(const uint8_t *data,
* @param size Size of key block buffer
* @param sig Which signature inside the keyblock to use
*/
-int vb2_check_keyblock(const struct vb2_keyblock *block,
- uint32_t size,
- const struct vb2_signature *sig);
+vb2_error_t vb2_check_keyblock(const struct vb2_keyblock *block, uint32_t size,
+ const struct vb2_signature *sig);
/**
* Verify a key block using a public key.
@@ -124,10 +120,9 @@ int vb2_check_keyblock(const struct vb2_keyblock *block,
* @param wb Work buffer
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_verify_keyblock(struct vb2_keyblock *block,
- uint32_t size,
- const struct vb2_public_key *key,
- const struct vb2_workbuf *wb);
+vb2_error_t vb2_verify_keyblock(struct vb2_keyblock *block, uint32_t size,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *wb);
/**
* Verify a key block using its hash.
@@ -141,9 +136,9 @@ int vb2_verify_keyblock(struct vb2_keyblock *block,
* @param wb Work buffer
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_verify_keyblock_hash(const struct vb2_keyblock *block,
- uint32_t size,
- const struct vb2_workbuf *wb);
+vb2_error_t vb2_verify_keyblock_hash(const struct vb2_keyblock *block,
+ uint32_t size,
+ const struct vb2_workbuf *wb);
/**
* Check the sanity of a firmware preamble using a public key.
@@ -156,10 +151,10 @@ int vb2_verify_keyblock_hash(const struct vb2_keyblock *block,
* @param wb Work buffer
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_verify_fw_preamble(struct vb2_fw_preamble *preamble,
- uint32_t size,
- const struct vb2_public_key *key,
- const struct vb2_workbuf *wb);
+vb2_error_t vb2_verify_fw_preamble(struct vb2_fw_preamble *preamble,
+ uint32_t size,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *wb);
/**
* Check the sanity of a kernel preamble using a public key.
@@ -172,10 +167,10 @@ int vb2_verify_fw_preamble(struct vb2_fw_preamble *preamble,
* @param wb Work buffer
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_verify_kernel_preamble(struct vb2_kernel_preamble *preamble,
- uint32_t size,
- const struct vb2_public_key *key,
- const struct vb2_workbuf *wb);
+vb2_error_t vb2_verify_kernel_preamble(struct vb2_kernel_preamble *preamble,
+ uint32_t size,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *wb);
/**
* Retrieve the 16-bit vmlinuz header address and size from the preamble.
diff --git a/firmware/lib20/kernel.c b/firmware/lib20/kernel.c
index c192b892..4d8f7721 100644
--- a/firmware/lib20/kernel.c
+++ b/firmware/lib20/kernel.c
@@ -40,16 +40,16 @@ static int vb2_need_signed_kernel(struct vb2_context *ctx)
return 0;
}
-int vb2_verify_keyblock_hash(const struct vb2_keyblock *block,
- uint32_t size,
- const struct vb2_workbuf *wb)
+vb2_error_t vb2_verify_keyblock_hash(const struct vb2_keyblock *block,
+ uint32_t size,
+ const struct vb2_workbuf *wb)
{
const struct vb2_signature *sig = &block->keyblock_hash;
struct vb2_workbuf wblocal = *wb;
struct vb2_digest_context *dc;
uint8_t *digest;
uint32_t digest_size;
- int rv;
+ vb2_error_t rv;
/* Sanity check keyblock before attempting hash check of data */
rv = vb2_check_keyblock(block, size, sig);
@@ -91,7 +91,7 @@ int vb2_verify_keyblock_hash(const struct vb2_keyblock *block,
return VB2_SUCCESS;
}
-int vb2_load_kernel_keyblock(struct vb2_context *ctx)
+vb2_error_t vb2_load_kernel_keyblock(struct vb2_context *ctx)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
struct vb2_workbuf wb;
@@ -109,7 +109,7 @@ int vb2_load_kernel_keyblock(struct vb2_context *ctx)
int need_keyblock_valid = vb2_need_signed_kernel(ctx);
int keyblock_is_valid = 1;
- int rv;
+ vb2_error_t rv;
vb2_workbuf_from_ctx(ctx, &wb);
@@ -244,10 +244,10 @@ int vb2_load_kernel_keyblock(struct vb2_context *ctx)
return VB2_SUCCESS;
}
-int vb2_verify_kernel_preamble(struct vb2_kernel_preamble *preamble,
- uint32_t size,
- const struct vb2_public_key *key,
- const struct vb2_workbuf *wb)
+vb2_error_t vb2_verify_kernel_preamble(struct vb2_kernel_preamble *preamble,
+ uint32_t size,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *wb)
{
struct vb2_signature *sig = &preamble->preamble_signature;
uint32_t min_size = EXPECTED_VB2_KERNEL_PREAMBLE_2_0_SIZE;
@@ -352,7 +352,7 @@ int vb2_verify_kernel_preamble(struct vb2_kernel_preamble *preamble,
return VB2_SUCCESS;
}
-int vb2_load_kernel_preamble(struct vb2_context *ctx)
+vb2_error_t vb2_load_kernel_preamble(struct vb2_context *ctx)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
struct vb2_workbuf wb;
@@ -367,7 +367,7 @@ int vb2_load_kernel_preamble(struct vb2_context *ctx)
struct vb2_kernel_preamble *pre;
uint32_t pre_size;
- int rv;
+ vb2_error_t rv;
vb2_workbuf_from_ctx(ctx, &wb);
diff --git a/firmware/lib20/misc.c b/firmware/lib20/misc.c
index bc479ab7..70f3ab80 100644
--- a/firmware/lib20/misc.c
+++ b/firmware/lib20/misc.c
@@ -65,7 +65,7 @@ static void vb2_report_dev_firmware(struct vb2_public_key *root)
VB2_DEBUG("This is developer signed firmware\n");
}
-int vb2_load_fw_keyblock(struct vb2_context *ctx)
+vb2_error_t vb2_load_fw_keyblock(struct vb2_context *ctx)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
struct vb2_gbb_header *gbb = vb2_get_gbb(ctx);
@@ -79,7 +79,7 @@ int vb2_load_fw_keyblock(struct vb2_context *ctx)
struct vb2_keyblock *kb;
uint32_t block_size;
- int rv;
+ vb2_error_t rv;
vb2_workbuf_from_ctx(ctx, &wb);
@@ -192,7 +192,7 @@ int vb2_load_fw_keyblock(struct vb2_context *ctx)
return VB2_SUCCESS;
}
-int vb2_load_fw_preamble(struct vb2_context *ctx)
+vb2_error_t vb2_load_fw_preamble(struct vb2_context *ctx)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
struct vb2_gbb_header *gbb = vb2_get_gbb(ctx);
@@ -206,7 +206,7 @@ int vb2_load_fw_preamble(struct vb2_context *ctx)
struct vb2_fw_preamble *pre;
uint32_t pre_size;
- int rv;
+ vb2_error_t rv;
vb2_workbuf_from_ctx(ctx, &wb);
diff --git a/firmware/lib20/packed_key.c b/firmware/lib20/packed_key.c
index 2e1c9cbc..af888e6e 100644
--- a/firmware/lib20/packed_key.c
+++ b/firmware/lib20/packed_key.c
@@ -11,15 +11,14 @@
#include "vb2_common.h"
test_mockable
-int vb2_unpack_key_buffer(struct vb2_public_key *key,
- const uint8_t *buf,
- uint32_t size)
+vb2_error_t vb2_unpack_key_buffer(struct vb2_public_key *key,
+ const uint8_t *buf, uint32_t size)
{
const struct vb2_packed_key *packed_key =
(const struct vb2_packed_key *)buf;
const uint32_t *buf32;
uint32_t expected_key_size;
- int rv;
+ vb2_error_t rv;
/* Make sure passed buffer is big enough for the packed key */
rv = vb2_verify_packed_key_inside(buf, size, packed_key);
@@ -64,8 +63,8 @@ int vb2_unpack_key_buffer(struct vb2_public_key *key,
return VB2_SUCCESS;
}
-int vb2_unpack_key(struct vb2_public_key *key,
- const struct vb2_packed_key *packed_key)
+vb2_error_t vb2_unpack_key(struct vb2_public_key *key,
+ const struct vb2_packed_key *packed_key)
{
if (!packed_key)
return VB2_ERROR_UNPACK_KEY_BUFFER;
diff --git a/firmware/lib21/api.c b/firmware/lib21/api.c
index 9f14579e..59448695 100644
--- a/firmware/lib21/api.c
+++ b/firmware/lib21/api.c
@@ -16,9 +16,9 @@
#include "2rsa.h"
#include "vb21_common.h"
-int vb21api_fw_phase3(struct vb2_context *ctx)
+vb2_error_t vb21api_fw_phase3(struct vb2_context *ctx)
{
- int rv;
+ vb2_error_t rv;
/* Verify firmware keyblock */
rv = vb21_load_fw_keyblock(ctx);
@@ -37,7 +37,7 @@ int vb21api_fw_phase3(struct vb2_context *ctx)
return VB2_SUCCESS;
}
-int vb21api_init_hash(struct vb2_context *ctx,
+vb2_error_t vb21api_init_hash(struct vb2_context *ctx,
const struct vb2_id *id,
uint32_t *size)
{
@@ -113,7 +113,7 @@ int vb21api_init_hash(struct vb2_context *ctx,
return vb2_digest_init(dc, sig->hash_alg);
}
-int vb21api_check_hash(struct vb2_context *ctx)
+vb2_error_t vb21api_check_hash(struct vb2_context *ctx)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
struct vb2_digest_context *dc = (struct vb2_digest_context *)
@@ -125,7 +125,7 @@ int vb21api_check_hash(struct vb2_context *ctx)
const struct vb21_signature *sig;
- int rv;
+ vb2_error_t rv;
vb2_workbuf_from_ctx(ctx, &wb);
diff --git a/firmware/lib21/common.c b/firmware/lib21/common.c
index c38a39ef..ed96ea08 100644
--- a/firmware/lib21/common.c
+++ b/firmware/lib21/common.c
@@ -18,7 +18,7 @@ const char *vb21_common_desc(const void *buf)
return c->desc_size ? (const char *)c + c->fixed_size : "";
}
-int vb21_verify_common_header(const void *parent, uint32_t parent_size)
+vb2_error_t vb21_verify_common_header(const void *parent, uint32_t parent_size)
{
const struct vb21_struct_common *c = parent;
@@ -57,10 +57,9 @@ int vb21_verify_common_header(const void *parent, uint32_t parent_size)
return VB2_SUCCESS;
}
-int vb21_verify_common_member(const void *parent,
- uint32_t *min_offset,
- uint32_t member_offset,
- uint32_t member_size)
+vb2_error_t vb21_verify_common_member(const void *parent, uint32_t *min_offset,
+ uint32_t member_offset,
+ uint32_t member_size)
{
const struct vb21_struct_common *c = parent;
uint32_t member_end = member_offset + member_size;
@@ -92,15 +91,15 @@ int vb21_verify_common_member(const void *parent,
return VB2_SUCCESS;
}
-int vb21_verify_common_subobject(const void *parent,
- uint32_t *min_offset,
- uint32_t member_offset)
+vb2_error_t vb21_verify_common_subobject(const void *parent,
+ uint32_t *min_offset,
+ uint32_t member_offset)
{
const struct vb21_struct_common *p = parent;
const struct vb21_struct_common *m =
(const struct vb21_struct_common *)
((const uint8_t *)parent + member_offset);
- int rv;
+ vb2_error_t rv;
/*
* Verify the parent has space at the member offset for the common
@@ -171,11 +170,12 @@ const struct vb2_id *vb2_hash_id(enum vb2_hash_algorithm hash_alg)
}
}
-int vb21_verify_signature(const struct vb21_signature *sig, uint32_t size)
+vb2_error_t vb21_verify_signature(const struct vb21_signature *sig,
+ uint32_t size)
{
uint32_t min_offset = 0;
uint32_t expect_sig_size;
- int rv;
+ vb2_error_t rv;
/* Check magic number */
if (sig->c.magic != VB21_MAGIC_SIGNATURE)
@@ -222,10 +222,10 @@ static uint8_t *vb21_signature_data(struct vb21_signature *sig)
return (uint8_t *)sig + sig->sig_offset;
}
-int vb21_verify_digest(const struct vb2_public_key *key,
- struct vb21_signature *sig,
- const uint8_t *digest,
- const struct vb2_workbuf *wb)
+vb2_error_t vb21_verify_digest(const struct vb2_public_key *key,
+ struct vb21_signature *sig,
+ const uint8_t *digest,
+ const struct vb2_workbuf *wb)
{
uint32_t key_sig_size = vb2_sig_size(key->sig_alg, key->hash_alg);
@@ -255,17 +255,16 @@ int vb21_verify_digest(const struct vb2_public_key *key,
}
}
-int vb21_verify_data(const void *data,
- uint32_t size,
- struct vb21_signature *sig,
- const struct vb2_public_key *key,
- const struct vb2_workbuf *wb)
+vb2_error_t vb21_verify_data(const void *data, uint32_t size,
+ struct vb21_signature *sig,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *wb)
{
struct vb2_workbuf wblocal = *wb;
struct vb2_digest_context *dc;
uint8_t *digest;
uint32_t digest_size;
- int rv;
+ vb2_error_t rv;
if (sig->data_size != size) {
VB2_DEBUG("Wrong amount of data signed.\n");
@@ -303,13 +302,12 @@ int vb21_verify_data(const void *data,
return vb21_verify_digest(key, sig, digest, &wblocal);
}
-int vb21_verify_keyblock(struct vb21_keyblock *block,
- uint32_t size,
- const struct vb2_public_key *key,
- const struct vb2_workbuf *wb)
+vb2_error_t vb21_verify_keyblock(struct vb21_keyblock *block, uint32_t size,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *wb)
{
uint32_t min_offset = 0, sig_offset;
- int rv, i;
+ vb2_error_t rv, i;
/* Check magic number */
if (block->c.magic != VB21_MAGIC_KEYBLOCK)
@@ -372,14 +370,14 @@ int vb21_verify_keyblock(struct vb21_keyblock *block,
return VB2_ERROR_KEYBLOCK_SIG_ID;
}
-int vb21_verify_fw_preamble(struct vb21_fw_preamble *preamble,
- uint32_t size,
- const struct vb2_public_key *key,
- const struct vb2_workbuf *wb)
+vb2_error_t vb21_verify_fw_preamble(struct vb21_fw_preamble *preamble,
+ uint32_t size,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *wb)
{
struct vb21_signature *sig;
uint32_t min_offset = 0, hash_offset;
- int rv, i;
+ vb2_error_t rv, i;
/* Check magic number */
if (preamble->c.magic != VB21_MAGIC_FW_PREAMBLE)
diff --git a/firmware/lib21/include/vb21_common.h b/firmware/lib21/include/vb21_common.h
index e89eb6cc..7ca5b4f5 100644
--- a/firmware/lib21/include/vb21_common.h
+++ b/firmware/lib21/include/vb21_common.h
@@ -37,7 +37,7 @@ const char *vb21_common_desc(const void *buf);
* @param parent_size Parent size in bytes
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb21_verify_common_header(const void *parent, uint32_t parent_size);
+vb2_error_t vb21_verify_common_header(const void *parent, uint32_t parent_size);
/**
* Verify a member is within the data for a parent object
@@ -52,10 +52,9 @@ int vb21_verify_common_header(const void *parent, uint32_t parent_size);
* @param member_size Size of member data, in bytes
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb21_verify_common_member(const void *parent,
- uint32_t *min_offset,
- uint32_t member_offset,
- uint32_t member_size);
+vb2_error_t vb21_verify_common_member(const void *parent, uint32_t *min_offset,
+ uint32_t member_offset,
+ uint32_t member_size);
/**
* Verify a member which starts with a common header is within the parent
@@ -75,9 +74,9 @@ int vb21_verify_common_member(const void *parent,
* member.
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb21_verify_common_subobject(const void *parent,
- uint32_t *min_offset,
- uint32_t member_offset);
+vb2_error_t vb21_verify_common_subobject(const void *parent,
+ uint32_t *min_offset,
+ uint32_t member_offset);
/**
* Unpack a key for use in verification
@@ -90,9 +89,8 @@ int vb21_verify_common_subobject(const void *parent,
* @param size Size of buffer in bytes
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb21_unpack_key(struct vb2_public_key *key,
- const uint8_t *buf,
- uint32_t size);
+vb2_error_t vb21_unpack_key(struct vb2_public_key *key, const uint8_t *buf,
+ uint32_t size);
/**
* Unpack the RSA data fields for a public key
@@ -104,9 +102,8 @@ int vb21_unpack_key(struct vb2_public_key *key,
* @param key_data Packed key data (from inside a packed key buffer)
* @param key_size Size of packed key data in bytes
*/
-int vb2_unpack_key_data(struct vb2_public_key *key,
- const uint8_t *key_data,
- uint32_t key_size);
+vb2_error_t vb2_unpack_key_data(struct vb2_public_key *key,
+ const uint8_t *key_data, uint32_t key_size);
/**
* Verify the integrity of a signature struct
@@ -114,8 +111,8 @@ int vb2_unpack_key_data(struct vb2_public_key *key,
* @param size Size of buffer containing signature struct
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb21_verify_signature(const struct vb21_signature *sig,
- uint32_t size);
+vb2_error_t vb21_verify_signature(const struct vb21_signature *sig,
+ uint32_t size);
/**
* Verify a signature against an expected hash digest.
@@ -126,10 +123,10 @@ int vb21_verify_signature(const struct vb21_signature *sig,
* @param wb Work buffer
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb21_verify_digest(const struct vb2_public_key *key,
- struct vb21_signature *sig,
- const uint8_t *digest,
- const struct vb2_workbuf *wb);
+vb2_error_t vb21_verify_digest(const struct vb2_public_key *key,
+ struct vb21_signature *sig,
+ const uint8_t *digest,
+ const struct vb2_workbuf *wb);
/**
* Verify data matches signature.
@@ -142,11 +139,10 @@ int vb21_verify_digest(const struct vb2_public_key *key,
* @param wb Work buffer
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb21_verify_data(const void *data,
- uint32_t size,
- struct vb21_signature *sig,
- const struct vb2_public_key *key,
- const struct vb2_workbuf *wb);
+vb2_error_t vb21_verify_data(const void *data, uint32_t size,
+ struct vb21_signature *sig,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *wb);
/**
* Check the sanity of a key block using a public key.
@@ -160,10 +156,9 @@ int vb21_verify_data(const void *data,
* @param wb Work buffer
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb21_verify_keyblock(struct vb21_keyblock *block,
- uint32_t size,
- const struct vb2_public_key *key,
- const struct vb2_workbuf *wb);
+vb2_error_t vb21_verify_keyblock(struct vb21_keyblock *block, uint32_t size,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *wb);
/**
* Check the sanity of a firmware preamble using a public key.
@@ -176,10 +171,10 @@ int vb21_verify_keyblock(struct vb21_keyblock *block,
* @param wb Work buffer
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb21_verify_fw_preamble(struct vb21_fw_preamble *preamble,
- uint32_t size,
- const struct vb2_public_key *key,
- const struct vb2_workbuf *wb);
+vb2_error_t vb21_verify_fw_preamble(struct vb21_fw_preamble *preamble,
+ uint32_t size,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *wb);
#ifdef __cplusplus
}
diff --git a/firmware/lib21/misc.c b/firmware/lib21/misc.c
index c1d0169c..de7d4477 100644
--- a/firmware/lib21/misc.c
+++ b/firmware/lib21/misc.c
@@ -28,15 +28,15 @@
* @param buf_ptr Destination for object pointer
* @return VB2_SUCCESS, or error code on error.
*/
-static int vb21_read_resource_object(struct vb2_context *ctx,
- enum vb2_resource_index index,
- uint32_t offset,
- struct vb2_workbuf *wb,
- void **buf_ptr)
+static vb2_error_t vb21_read_resource_object(struct vb2_context *ctx,
+ enum vb2_resource_index index,
+ uint32_t offset,
+ struct vb2_workbuf *wb,
+ void **buf_ptr)
{
struct vb21_struct_common c;
void *buf;
- int rv;
+ vb2_error_t rv;
*buf_ptr = NULL;
@@ -62,7 +62,7 @@ static int vb21_read_resource_object(struct vb2_context *ctx,
return VB2_SUCCESS;
}
-int vb21_load_fw_keyblock(struct vb2_context *ctx)
+vb2_error_t vb21_load_fw_keyblock(struct vb2_context *ctx)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
struct vb2_gbb_header *gbb = vb2_get_gbb(ctx);
@@ -74,7 +74,7 @@ int vb21_load_fw_keyblock(struct vb2_context *ctx)
struct vb2_public_key root_key;
struct vb21_keyblock *kb;
- int rv;
+ vb2_error_t rv;
vb2_workbuf_from_ctx(ctx, &wb);
@@ -155,7 +155,7 @@ int vb21_load_fw_keyblock(struct vb2_context *ctx)
return VB2_SUCCESS;
}
-int vb21_load_fw_preamble(struct vb2_context *ctx)
+vb2_error_t vb21_load_fw_preamble(struct vb2_context *ctx)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);
struct vb2_gbb_header *gbb = vb2_get_gbb(ctx);
@@ -168,7 +168,7 @@ int vb21_load_fw_preamble(struct vb2_context *ctx)
/* Preamble goes in the next unused chunk of work buffer */
struct vb21_fw_preamble *pre;
- int rv;
+ vb2_error_t rv;
vb2_workbuf_from_ctx(ctx, &wb);
diff --git a/firmware/lib21/packed_key.c b/firmware/lib21/packed_key.c
index 71248dd4..b962da9e 100644
--- a/firmware/lib21/packed_key.c
+++ b/firmware/lib21/packed_key.c
@@ -10,9 +10,8 @@
#include "2rsa.h"
#include "vb21_common.h"
-int vb2_unpack_key_data(struct vb2_public_key *key,
- const uint8_t *key_data,
- uint32_t key_size)
+vb2_error_t vb2_unpack_key_data(struct vb2_public_key *key,
+ const uint8_t *key_data, uint32_t key_size)
{
const uint32_t *buf32 = (const uint32_t *)key_data;
uint32_t expected_key_size = vb2_packed_key_size(key->sig_alg);
@@ -42,15 +41,14 @@ int vb2_unpack_key_data(struct vb2_public_key *key,
return VB2_SUCCESS;
}
-int vb21_unpack_key(struct vb2_public_key *key,
- const uint8_t *buf,
- uint32_t size)
+vb2_error_t vb21_unpack_key(struct vb2_public_key *key, const uint8_t *buf,
+ uint32_t size)
{
const struct vb21_packed_key *pkey =
(const struct vb21_packed_key *)buf;
uint32_t sig_size;
uint32_t min_offset = 0;
- int rv;
+ vb2_error_t rv;
/* Check magic number */
if (pkey->c.magic != VB21_MAGIC_PACKED_KEY)
diff --git a/firmware/stub/vboot_api_stub.c b/firmware/stub/vboot_api_stub.c
index 8d4719e9..bc2aa59f 100644
--- a/firmware/stub/vboot_api_stub.c
+++ b/firmware/stub/vboot_api_stub.c
@@ -162,7 +162,7 @@ enum VbEcBootMode_t VbGetMode(void)
return vboot_mode;
}
-int VbExLegacy(enum VbAltFwIndex_t altfw_num)
+vb2_error_t VbExLegacy(enum VbAltFwIndex_t altfw_num)
{
return 1;
}
diff --git a/futility/file_type_usbpd1.c b/futility/file_type_usbpd1.c
index 197466b7..d5dbe953 100644
--- a/futility/file_type_usbpd1.c
+++ b/futility/file_type_usbpd1.c
@@ -304,12 +304,11 @@ static void vb2_pubkey_from_usbpd1(struct vb2_public_key *key,
key->id = vb2_hash_id(hash_alg);
}
-static int vb21_sig_from_usbpd1(struct vb21_signature **sig,
- enum vb2_signature_algorithm sig_alg,
- enum vb2_hash_algorithm hash_alg,
- const uint8_t *o_sig,
- uint32_t o_sig_size,
- uint32_t data_size)
+static vb2_error_t vb21_sig_from_usbpd1(struct vb21_signature **sig,
+ enum vb2_signature_algorithm sig_alg,
+ enum vb2_hash_algorithm hash_alg,
+ const uint8_t *o_sig,
+ uint32_t o_sig_size, uint32_t data_size)
{
struct vb21_signature s = {
.c.magic = VB21_MAGIC_SIGNATURE,
@@ -367,11 +366,11 @@ static void show_usbpd1_stuff(const char *name,
/* Returns VB2_SUCCESS or random error code */
-static int try_our_own(enum vb2_signature_algorithm sig_alg,
- enum vb2_hash_algorithm hash_alg,
- const uint8_t *o_pubkey, uint32_t o_pubkey_size,
- const uint8_t *o_sig, uint32_t o_sig_size,
- const uint8_t *data, uint32_t data_size)
+static vb2_error_t try_our_own(enum vb2_signature_algorithm sig_alg,
+ enum vb2_hash_algorithm hash_alg,
+ const uint8_t *o_pubkey, uint32_t o_pubkey_size,
+ const uint8_t *o_sig, uint32_t o_sig_size,
+ const uint8_t *data, uint32_t data_size)
{
struct vb2_public_key pubkey;
struct vb21_signature *sig;
@@ -381,7 +380,7 @@ static int try_our_own(enum vb2_signature_algorithm sig_alg,
.buf = buf,
.size = sizeof(buf),
};
- int rv = VB2_ERROR_UNKNOWN;
+ vb2_error_t rv = VB2_ERROR_UNKNOWN;
vb2_pubkey_from_usbpd1(&pubkey, sig_alg, hash_alg,
o_pubkey, o_pubkey_size);
@@ -398,19 +397,19 @@ static int try_our_own(enum vb2_signature_algorithm sig_alg,
}
/* Returns VB2_SUCCESS if the image validates itself */
-static int check_self_consistency(const uint8_t *buf,
- const char *name,
- uint32_t ro_size, uint32_t rw_size,
- uint32_t ro_offset, uint32_t rw_offset,
- enum vb2_signature_algorithm sig_alg,
- enum vb2_hash_algorithm hash_alg)
+static vb2_error_t check_self_consistency(const uint8_t *buf, const char *name,
+ uint32_t ro_size, uint32_t rw_size,
+ uint32_t ro_offset,
+ uint32_t rw_offset,
+ enum vb2_signature_algorithm sig_alg,
+ enum vb2_hash_algorithm hash_alg)
{
/* Where are the important bits? */
uint32_t sig_size = vb2_rsa_sig_size(sig_alg);
uint32_t sig_offset = rw_offset + rw_size - sig_size;
uint32_t pubkey_size = usbpd1_packed_key_size(sig_alg);
uint32_t pubkey_offset = ro_offset + ro_size - pubkey_size;
- int rv;
+ vb2_error_t rv;
/* Skip stuff that obviously doesn't work */
if (sig_size > rw_size || pubkey_size > ro_size)
diff --git a/host/arch/x86/lib/crossystem_arch.c b/host/arch/x86/lib/crossystem_arch.c
index cda86e8d..68ab67db 100644
--- a/host/arch/x86/lib/crossystem_arch.c
+++ b/host/arch/x86/lib/crossystem_arch.c
@@ -442,7 +442,7 @@ static const char* VbReadMainFwType(char* dest, int size)
/* Read the recovery reason. Returns the reason code or -1 if error. */
-static int VbGetRecoveryReason(void)
+static vb2_error_t VbGetRecoveryReason(void)
{
unsigned value;
diff --git a/host/lib/crossystem.c b/host/lib/crossystem.c
index 2b13258f..c8938225 100644
--- a/host/lib/crossystem.c
+++ b/host/lib/crossystem.c
@@ -187,7 +187,7 @@ static VbBuildOption VbScanBuildOption(void)
/* Determine whether the running OS image was built for debugging.
* Returns 1 if yes, 0 if no or indeterminate. */
-static int VbGetDebugBuild(void)
+static vb2_error_t VbGetDebugBuild(void)
{
return VB_BUILD_OPTION_DEBUG == VbScanBuildOption();
}
diff --git a/host/lib/file_keys.c b/host/lib/file_keys.c
index 7df7ceb2..e47091de 100644
--- a/host/lib/file_keys.c
+++ b/host/lib/file_keys.c
@@ -21,8 +21,8 @@
#include "host_common.h"
#include "signature_digest.h"
-int DigestFile(char *input_file, enum vb2_hash_algorithm alg,
- uint8_t *digest, uint32_t digest_size)
+vb2_error_t DigestFile(char *input_file, enum vb2_hash_algorithm alg,
+ uint8_t *digest, uint32_t digest_size)
{
int input_fd, len;
uint8_t data[VB2_SHA1_BLOCK_SIZE];
diff --git a/host/lib/host_key2.c b/host/lib/host_key2.c
index 64aab1b4..b76ac2ae 100644
--- a/host/lib/host_key2.c
+++ b/host/lib/host_key2.c
@@ -25,8 +25,8 @@
#include "vboot_common.h"
enum vb2_crypto_algorithm vb2_get_crypto_algorithm(
- enum vb2_hash_algorithm hash_alg,
- enum vb2_signature_algorithm sig_alg)
+ enum vb2_hash_algorithm hash_alg,
+ enum vb2_signature_algorithm sig_alg)
{
/* Make sure algorithms are in the range supported by crypto alg */
if (sig_alg < VB2_SIG_RSA1024 || sig_alg >= VB2_SIG_ALG_COUNT)
@@ -76,8 +76,8 @@ struct vb2_private_key *vb2_read_private_key(const char *filename)
}
struct vb2_private_key *vb2_read_private_key_pem(
- const char* filename,
- enum vb2_crypto_algorithm algorithm)
+ const char* filename,
+ enum vb2_crypto_algorithm algorithm)
{
if (algorithm >= VB2_ALG_COUNT) {
VB2_DEBUG("%s() called with invalid algorithm!\n",
@@ -124,8 +124,8 @@ void vb2_free_private_key(struct vb2_private_key *key)
free(key);
}
-int vb2_write_private_key(const char *filename,
- const struct vb2_private_key *key)
+vb2_error_t vb2_write_private_key(const char *filename,
+ const struct vb2_private_key *key)
{
/* Convert back to legacy vb1 algorithm enum */
uint64_t alg = vb2_get_crypto_algorithm(key->hash_alg, key->sig_alg);
@@ -187,8 +187,8 @@ struct vb2_packed_key *vb2_alloc_packed_key(uint32_t key_size,
return key;
}
-int vb2_copy_packed_key(struct vb2_packed_key *dest,
- const struct vb2_packed_key *src)
+vb2_error_t vb2_copy_packed_key(struct vb2_packed_key *dest,
+ const struct vb2_packed_key *src)
{
if (dest->key_size < src->key_size)
return VB2_ERROR_COPY_KEY_SIZE;
@@ -260,8 +260,8 @@ struct vb2_packed_key *vb2_read_packed_keyb(const char *filename,
return key;
}
-int vb2_write_packed_key(const char *filename,
- const struct vb2_packed_key *key)
+vb2_error_t vb2_write_packed_key(const char *filename,
+ const struct vb2_packed_key *key)
{
/* Copy the key, so its data is contiguous with the header */
struct vb2_packed_key *kcopy =
@@ -274,7 +274,7 @@ int vb2_write_packed_key(const char *filename,
}
/* Write the copy, then free it */
- int rv = vb2_write_file(filename, kcopy,
+ vb2_error_t rv = vb2_write_file(filename, kcopy,
kcopy->key_offset + kcopy->key_size);
free(kcopy);
return rv;
diff --git a/host/lib/host_misc.c b/host/lib/host_misc.c
index 250ca99d..3dc6112f 100644
--- a/host/lib/host_misc.c
+++ b/host/lib/host_misc.c
@@ -99,7 +99,7 @@ int ReadFileBit(const char* filename, int bitmask)
else return (value & bitmask ? 1 : 0);
}
-int WriteFile(const char* filename, const void *data, uint64_t size)
+vb2_error_t WriteFile(const char* filename, const void *data, uint64_t size)
{
FILE *f = fopen(filename, "wb");
if (!f) {
diff --git a/host/lib/host_signature.c b/host/lib/host_signature.c
index 22e52c97..cfa40d10 100644
--- a/host/lib/host_signature.c
+++ b/host/lib/host_signature.c
@@ -28,11 +28,8 @@
* [inbuf] passed redirected to stdin, and the stdout of the command is put
* back into [outbuf]. Returns -1 on error, 0 on success.
*/
-static int sign_external(uint32_t size,
- const uint8_t *inbuf,
- uint8_t *outbuf,
- uint32_t outbufsize,
- const char *pem_file,
+static int sign_external(uint32_t size, const uint8_t *inbuf, uint8_t *outbuf,
+ uint32_t outbufsize, const char *pem_file,
const char *external_signer)
{
int rv = 0, n;
@@ -113,8 +110,7 @@ static int sign_external(uint32_t size,
return rv;
}
-struct vb2_signature *vb2_external_signature(const uint8_t *data,
- uint32_t size,
+struct vb2_signature *vb2_external_signature(const uint8_t *data, uint32_t size,
const char *key_file,
uint32_t key_algorithm,
const char *external_signer)
diff --git a/host/lib/host_signature2.c b/host/lib/host_signature2.c
index 6baff961..2105bd90 100644
--- a/host/lib/host_signature2.c
+++ b/host/lib/host_signature2.c
@@ -49,8 +49,8 @@ void vb2_init_signature(struct vb2_signature *sig, uint8_t *sig_data,
sig->data_size = data_size;
}
-int vb2_copy_signature(struct vb2_signature *dest,
- const struct vb2_signature *src)
+vb2_error_t vb2_copy_signature(struct vb2_signature *dest,
+ const struct vb2_signature *src)
{
if (dest->sig_size < src->sig_size)
return VB2_ERROR_SIG_SIZE;
diff --git a/host/lib/include/file_keys.h b/host/lib/include/file_keys.h
index b4bdd322..8176cdbf 100644
--- a/host/lib/include/file_keys.h
+++ b/host/lib/include/file_keys.h
@@ -14,7 +14,7 @@
* hash algorithm [alg] and stores it into [digest], which is of size
* [digest_size]. Returns VB2_SUCCESS, or non-zero on error.
*/
-int DigestFile(char *input_file, enum vb2_hash_algorithm alg,
- uint8_t *digest, uint32_t digest_size);
+vb2_error_t DigestFile(char *input_file, enum vb2_hash_algorithm alg,
+ uint8_t *digest, uint32_t digest_size);
#endif /* VBOOT_REFERENCE_FILE_KEYS_H_ */
diff --git a/host/lib/include/host_key.h b/host/lib/include/host_key.h
index 0040b8a2..b00a501d 100644
--- a/host/lib/include/host_key.h
+++ b/host/lib/include/host_key.h
@@ -9,6 +9,7 @@
#define VBOOT_REFERENCE_HOST_KEY_H_
#include "2crypto.h"
+#include "2return_codes.h"
struct vb2_packed_key;
struct vb2_private_key;
@@ -22,8 +23,8 @@ struct vb2_private_key;
* @return The equivalent vb1 crypto algorithm or VB2_ALG_COUNT if error.
*/
enum vb2_crypto_algorithm vb2_get_crypto_algorithm(
- enum vb2_hash_algorithm hash_alg,
- enum vb2_signature_algorithm sig_alg);
+ enum vb2_hash_algorithm hash_alg,
+ enum vb2_signature_algorithm sig_alg);
/**
* Read a private key from a .pem file.
@@ -35,8 +36,8 @@ enum vb2_crypto_algorithm vb2_get_crypto_algorithm(
* @return The private key or NULL if error. Caller must free() it.
*/
struct vb2_private_key *vb2_read_private_key_pem(
- const char *filename,
- enum vb2_crypto_algorithm algorithm);
+ const char *filename,
+ enum vb2_crypto_algorithm algorithm);
/**
* Free a private key.
@@ -53,8 +54,8 @@ void vb2_free_private_key(struct vb2_private_key *key);
*
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb2_write_private_key(const char *filename,
- const struct vb2_private_key *key);
+vb2_error_t vb2_write_private_key(const char *filename,
+ const struct vb2_private_key *key);
/**
@@ -96,8 +97,8 @@ void vb2_init_packed_key(struct vb2_packed_key *key, uint8_t *key_data,
*
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb2_copy_packed_key(struct vb2_packed_key *dest,
- const struct vb2_packed_key *src);
+vb2_error_t vb2_copy_packed_key(struct vb2_packed_key *dest,
+ const struct vb2_packed_key *src);
/**
* Read a packed key from a .vbpubk file.
@@ -141,7 +142,7 @@ struct vb2_packed_key *vb2_read_packed_keyb(const char *filename,
*
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb2_write_packed_key(const char *filename,
- const struct vb2_packed_key *key);
+vb2_error_t vb2_write_packed_key(const char *filename,
+ const struct vb2_packed_key *key);
#endif /* VBOOT_REFERENCE_HOST_KEY_H_ */
diff --git a/host/lib/include/host_misc.h b/host/lib/include/host_misc.h
index 63a38943..65949508 100644
--- a/host/lib/include/host_misc.h
+++ b/host/lib/include/host_misc.h
@@ -41,7 +41,7 @@ int ReadFileBit(const char* filename, int bitmask);
/* Writes [size] bytes of [data] to [filename].
*
* Returns 0 if success, 1 if error. */
-int WriteFile(const char* filename, const void *data, uint64_t size);
+vb2_error_t WriteFile(const char* filename, const void *data, uint64_t size);
/**
* Read data from a file into a newly allocated buffer.
@@ -53,7 +53,8 @@ int WriteFile(const char* filename, const void *data, uint64_t size);
* @param size_ptr On exit, size of data will be stored here.
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb2_read_file(const char *filename, uint8_t **data_ptr, uint32_t *size_ptr);
+vb2_error_t vb2_read_file(const char *filename, uint8_t **data_ptr,
+ uint32_t *size_ptr);
/**
* Write data to a file from a buffer.
@@ -63,7 +64,8 @@ int vb2_read_file(const char *filename, uint8_t **data_ptr, uint32_t *size_ptr);
* @param size Number of bytes of data to write
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb2_write_file(const char *filename, const void *buf, uint32_t size);
+vb2_error_t vb2_write_file(const char *filename, const void *buf,
+ uint32_t size);
/**
* Write a buffer which starts with a standard vb21_struct_common header.
@@ -74,7 +76,7 @@ int vb2_write_file(const char *filename, const void *buf, uint32_t size);
* @param buf Buffer to write
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb21_write_object(const char *filename, const void *buf);
+vb2_error_t vb21_write_object(const char *filename, const void *buf);
/**
* Round up a size to a multiple of 32 bits (4 bytes).
diff --git a/host/lib/include/host_signature.h b/host/lib/include/host_signature.h
index fce664da..682840c4 100644
--- a/host/lib/include/host_signature.h
+++ b/host/lib/include/host_signature.h
@@ -45,8 +45,8 @@ struct vb2_signature *vb2_alloc_signature(uint32_t sig_size,
* @param src Source signature
*
* @return VB2_SUCCESS, or non-zero if error. */
-int vb2_copy_signature(struct vb2_signature *dest,
- const struct vb2_signature *src);
+vb2_error_t vb2_copy_signature(struct vb2_signature *dest,
+ const struct vb2_signature *src);
/**
* Calculate a SHA-512 digest-only signature.
@@ -68,8 +68,7 @@ struct vb2_signature *vb2_sha512_signature(const uint8_t *data, uint32_t size);
* @return The signature, or NULL if error. Caller must free() it.
*/
struct vb2_signature *vb2_calculate_signature(
- const uint8_t *data, uint32_t size,
- const struct vb2_private_key *key);
+ const uint8_t *data, uint32_t size, const struct vb2_private_key *key);
/**
* Calculate a signature for the data using an external signer.
@@ -82,8 +81,7 @@ struct vb2_signature *vb2_calculate_signature(
*
* @return The signature, or NULL if error. Caller must free() it.
*/
-struct vb2_signature *vb2_external_signature(const uint8_t *data,
- uint32_t size,
+struct vb2_signature *vb2_external_signature(const uint8_t *data, uint32_t size,
const char *key_file,
uint32_t key_algorithm,
const char *external_signer);
diff --git a/host/lib21/host_fw_preamble.c b/host/lib21/host_fw_preamble.c
index ebe3ce94..7220b32e 100644
--- a/host/lib21/host_fw_preamble.c
+++ b/host/lib21/host_fw_preamble.c
@@ -16,13 +16,11 @@
#include "host_signature2.h"
#include "vb21_common.h"
-int vb21_fw_preamble_create(struct vb21_fw_preamble **fp_ptr,
- const struct vb2_private_key *signing_key,
- const struct vb21_signature **hash_list,
- uint32_t hash_count,
- uint32_t fw_version,
- uint32_t flags,
- const char *desc)
+vb2_error_t vb21_fw_preamble_create(struct vb21_fw_preamble **fp_ptr,
+ const struct vb2_private_key *signing_key,
+ const struct vb21_signature **hash_list,
+ uint32_t hash_count, uint32_t fw_version,
+ uint32_t flags, const char *desc)
{
struct vb21_fw_preamble fp = {
.c.magic = VB21_MAGIC_FW_PREAMBLE,
diff --git a/host/lib21/host_key.c b/host/lib21/host_key.c
index 76fbf285..1154bec9 100644
--- a/host/lib21/host_key.c
+++ b/host/lib21/host_key.c
@@ -138,9 +138,8 @@ void vb2_private_key_free(struct vb2_private_key *key)
free(key);
}
-int vb21_private_key_unpack(struct vb2_private_key **key_ptr,
- const uint8_t *buf,
- uint32_t size)
+vb2_error_t vb21_private_key_unpack(struct vb2_private_key **key_ptr,
+ const uint8_t *buf, uint32_t size)
{
const struct vb21_packed_private_key *pkey =
(const struct vb21_packed_private_key *)buf;
@@ -214,12 +213,12 @@ int vb21_private_key_unpack(struct vb2_private_key **key_ptr,
return VB2_SUCCESS;
}
-int vb21_private_key_read(struct vb2_private_key **key_ptr,
- const char *filename)
+vb2_error_t vb21_private_key_read(struct vb2_private_key **key_ptr,
+ const char *filename)
{
uint32_t size = 0;
uint8_t *buf = NULL;
- int rv;
+ vb2_error_t rv;
*key_ptr = NULL;
@@ -234,8 +233,8 @@ int vb21_private_key_read(struct vb2_private_key **key_ptr,
return rv;
}
-int vb2_private_key_read_pem(struct vb2_private_key **key_ptr,
- const char *filename)
+vb2_error_t vb2_private_key_read_pem(struct vb2_private_key **key_ptr,
+ const char *filename)
{
struct vb2_private_key *key;
FILE *f;
@@ -266,7 +265,8 @@ int vb2_private_key_read_pem(struct vb2_private_key **key_ptr,
return VB2_SUCCESS;
}
-int vb2_private_key_set_desc(struct vb2_private_key *key, const char *desc)
+vb2_error_t vb2_private_key_set_desc(struct vb2_private_key *key,
+ const char *desc)
{
if (key->desc)
free(key->desc);
@@ -282,8 +282,8 @@ int vb2_private_key_set_desc(struct vb2_private_key *key, const char *desc)
return VB2_SUCCESS;
}
-int vb21_private_key_write(const struct vb2_private_key *key,
- const char *filename)
+vb2_error_t vb21_private_key_write(const struct vb2_private_key *key,
+ const char *filename)
{
struct vb21_packed_private_key pkey = {
.c.magic = VB21_MAGIC_PACKED_PRIVATE_KEY,
@@ -297,7 +297,7 @@ int vb21_private_key_write(const struct vb2_private_key *key,
uint8_t *buf;
uint8_t *rsabuf = NULL;
int rsalen = 0;
- int rv;
+ vb2_error_t rv;
memcpy(&pkey.id, &key->id, sizeof(pkey.id));
@@ -338,8 +338,8 @@ int vb21_private_key_write(const struct vb2_private_key *key,
return rv ? VB2_ERROR_PRIVATE_KEY_WRITE_FILE : VB2_SUCCESS;
}
-int vb2_private_key_hash(const struct vb2_private_key **key_ptr,
- enum vb2_hash_algorithm hash_alg)
+vb2_error_t vb2_private_key_hash(const struct vb2_private_key **key_ptr,
+ enum vb2_hash_algorithm hash_alg)
{
*key_ptr = NULL;
@@ -388,8 +388,8 @@ int vb2_private_key_hash(const struct vb2_private_key **key_ptr,
}
}
-int vb2_public_key_alloc(struct vb2_public_key **key_ptr,
- enum vb2_signature_algorithm sig_alg)
+vb2_error_t vb2_public_key_alloc(struct vb2_public_key **key_ptr,
+ enum vb2_signature_algorithm sig_alg)
{
struct vb2_public_key *key;
uint32_t key_data_size = vb2_packed_key_size(sig_alg);
@@ -429,8 +429,8 @@ uint8_t *vb2_public_key_packed_data(struct vb2_public_key *key)
return (uint8_t *)(key->id + 1);
}
-int vb2_public_key_read_keyb(struct vb2_public_key **key_ptr,
- const char *filename)
+vb2_error_t vb2_public_key_read_keyb(struct vb2_public_key **key_ptr,
+ const char *filename)
{
struct vb2_public_key *key = NULL;
uint8_t *key_data, *key_buf;
@@ -475,7 +475,8 @@ int vb2_public_key_read_keyb(struct vb2_public_key **key_ptr,
return VB2_SUCCESS;
}
-int vb2_public_key_set_desc(struct vb2_public_key *key, const char *desc)
+vb2_error_t vb2_public_key_set_desc(struct vb2_public_key *key,
+ const char *desc)
{
if (key->desc)
free((void *)key->desc);
@@ -491,8 +492,8 @@ int vb2_public_key_set_desc(struct vb2_public_key *key, const char *desc)
return VB2_SUCCESS;
}
-int vb21_packed_key_read(struct vb21_packed_key **key_ptr,
- const char *filename)
+vb2_error_t vb21_packed_key_read(struct vb21_packed_key **key_ptr,
+ const char *filename)
{
struct vb2_public_key key;
uint8_t *buf;
@@ -512,8 +513,8 @@ int vb21_packed_key_read(struct vb21_packed_key **key_ptr,
return VB2_SUCCESS;
}
-int vb21_public_key_pack(struct vb21_packed_key **key_ptr,
- const struct vb2_public_key *pubk)
+vb2_error_t vb21_public_key_pack(struct vb21_packed_key **key_ptr,
+ const struct vb2_public_key *pubk)
{
struct vb21_packed_key key = {
.c.magic = VB21_MAGIC_PACKED_KEY,
@@ -571,8 +572,8 @@ int vb21_public_key_pack(struct vb21_packed_key **key_ptr,
return VB2_SUCCESS;
}
-int vb2_public_key_hash(struct vb2_public_key *key,
- enum vb2_hash_algorithm hash_alg)
+vb2_error_t vb2_public_key_hash(struct vb2_public_key *key,
+ enum vb2_hash_algorithm hash_alg)
{
switch (hash_alg) {
#if VB2_SUPPORT_SHA1
@@ -635,8 +636,8 @@ enum vb2_signature_algorithm vb2_rsa_sig_alg(struct rsa_st *rsa)
return VB2_SIG_INVALID;
}
-int vb21_public_key_write(const struct vb2_public_key *key,
- const char *filename)
+vb2_error_t vb21_public_key_write(const struct vb2_public_key *key,
+ const char *filename)
{
struct vb21_packed_key *pkey;
int ret;
diff --git a/host/lib21/host_keyblock.c b/host/lib21/host_keyblock.c
index cb8c3127..9c5959a4 100644
--- a/host/lib21/host_keyblock.c
+++ b/host/lib21/host_keyblock.c
@@ -15,12 +15,11 @@
#include "host_misc.h"
#include "host_signature2.h"
-int vb21_keyblock_create(struct vb21_keyblock **kb_ptr,
- const struct vb2_public_key *data_key,
- const struct vb2_private_key **signing_keys,
- uint32_t signing_key_count,
- uint32_t flags,
- const char *desc)
+vb2_error_t vb21_keyblock_create(struct vb21_keyblock **kb_ptr,
+ const struct vb2_public_key *data_key,
+ const struct vb2_private_key **signing_keys,
+ uint32_t signing_key_count, uint32_t flags,
+ const char *desc)
{
struct vb21_keyblock kb = {
.c.magic = VB21_MAGIC_KEYBLOCK,
diff --git a/host/lib21/host_misc.c b/host/lib21/host_misc.c
index 59c8c0a8..9d375681 100644
--- a/host/lib21/host_misc.c
+++ b/host/lib21/host_misc.c
@@ -17,7 +17,8 @@
#include "host_common.h"
#include "host_misc2.h"
-int vb2_read_file(const char *filename, uint8_t **data_ptr, uint32_t *size_ptr)
+vb2_error_t vb2_read_file(const char *filename, uint8_t **data_ptr,
+ uint32_t *size_ptr)
{
FILE *f;
uint8_t *buf;
@@ -61,7 +62,7 @@ int vb2_read_file(const char *filename, uint8_t **data_ptr, uint32_t *size_ptr)
return VB2_SUCCESS;
}
-int vb2_write_file(const char *filename, const void *buf, uint32_t size)
+vb2_error_t vb2_write_file(const char *filename, const void *buf, uint32_t size)
{
FILE *f = fopen(filename, "wb");
@@ -81,7 +82,7 @@ int vb2_write_file(const char *filename, const void *buf, uint32_t size)
return VB2_SUCCESS;
}
-int vb21_write_object(const char *filename, const void *buf)
+vb2_error_t vb21_write_object(const char *filename, const void *buf)
{
const struct vb21_struct_common *cptr = buf;
@@ -136,7 +137,7 @@ static const char *onebyte(const char *str, uint8_t *vptr)
return str;
}
-int vb2_str_to_id(const char *str, struct vb2_id *id)
+vb2_error_t vb2_str_to_id(const char *str, struct vb2_id *id)
{
uint8_t val = 0;
int i;
diff --git a/host/lib21/host_signature.c b/host/lib21/host_signature.c
index 5339b075..51320e7b 100644
--- a/host/lib21/host_signature.c
+++ b/host/lib21/host_signature.c
@@ -17,9 +17,8 @@
#include "host_signature2.h"
#include "host_misc.h"
-int vb2_digest_info(enum vb2_hash_algorithm hash_alg,
- const uint8_t **buf_ptr,
- uint32_t *size_ptr)
+vb2_error_t vb2_digest_info(enum vb2_hash_algorithm hash_alg,
+ const uint8_t **buf_ptr, uint32_t *size_ptr)
{
*buf_ptr = NULL;
*size_ptr = 0;
@@ -68,11 +67,9 @@ int vb2_digest_info(enum vb2_hash_algorithm hash_alg,
}
}
-int vb21_sign_data(struct vb21_signature **sig_ptr,
- const uint8_t *data,
- uint32_t size,
- const struct vb2_private_key *key,
- const char *desc)
+vb2_error_t vb21_sign_data(struct vb21_signature **sig_ptr, const uint8_t *data,
+ uint32_t size, const struct vb2_private_key *key,
+ const char *desc)
{
struct vb21_signature s = {
.c.magic = VB21_MAGIC_SIGNATURE,
@@ -172,9 +169,9 @@ int vb21_sign_data(struct vb21_signature **sig_ptr,
return VB2_SUCCESS;
}
-int vb21_sig_size_for_key(uint32_t *size_ptr,
- const struct vb2_private_key *key,
- const char *desc)
+vb2_error_t vb21_sig_size_for_key(uint32_t *size_ptr,
+ const struct vb2_private_key *key,
+ const char *desc)
{
uint32_t size = vb2_sig_size(key->sig_alg, key->hash_alg);
@@ -188,12 +185,12 @@ int vb21_sig_size_for_key(uint32_t *size_ptr,
return VB2_SUCCESS;
}
-int vb21_sig_size_for_keys(uint32_t *size_ptr,
- const struct vb2_private_key **key_list,
- uint32_t key_count)
+vb2_error_t vb21_sig_size_for_keys(uint32_t *size_ptr,
+ const struct vb2_private_key **key_list,
+ uint32_t key_count)
{
uint32_t total = 0, size = 0;
- int rv, i;
+ vb2_error_t rv, i;
*size_ptr = 0;
@@ -208,14 +205,13 @@ int vb21_sig_size_for_keys(uint32_t *size_ptr,
return VB2_SUCCESS;
}
-int vb21_sign_object(uint8_t *buf,
- uint32_t sig_offset,
- const struct vb2_private_key *key,
- const char *desc)
+vb2_error_t vb21_sign_object(uint8_t *buf, uint32_t sig_offset,
+ const struct vb2_private_key *key,
+ const char *desc)
{
struct vb21_struct_common *c = (struct vb21_struct_common *)buf;
struct vb21_signature *sig = NULL;
- int rv;
+ vb2_error_t rv;
rv = vb21_sign_data(&sig, buf, sig_offset, key, desc);
if (rv)
@@ -232,14 +228,13 @@ int vb21_sign_object(uint8_t *buf,
return VB2_SUCCESS;
}
-int vb21_sign_object_multiple(uint8_t *buf,
- uint32_t sig_offset,
- const struct vb2_private_key **key_list,
- uint32_t key_count)
+vb2_error_t vb21_sign_object_multiple(uint8_t *buf, uint32_t sig_offset,
+ const struct vb2_private_key **key_list,
+ uint32_t key_count)
{
struct vb21_struct_common *c = (struct vb21_struct_common *)buf;
uint32_t sig_next = sig_offset;
- int rv, i;
+ vb2_error_t rv, i;
for (i = 0; i < key_count; i++) {
struct vb21_signature *sig = NULL;
diff --git a/host/lib21/include/host_fw_preamble2.h b/host/lib21/include/host_fw_preamble2.h
index e759edc5..d0bed1ef 100644
--- a/host/lib21/include/host_fw_preamble2.h
+++ b/host/lib21/include/host_fw_preamble2.h
@@ -24,12 +24,10 @@ struct vb21_signature;
* @param desc Description for preamble, or NULL if none
* @return VB2_SUCCESS, or non-zero error code if failure.
*/
-int vb21_fw_preamble_create(struct vb21_fw_preamble **fp_ptr,
- const struct vb2_private_key *signing_key,
- const struct vb21_signature **hash_list,
- uint32_t hash_count,
- uint32_t fw_version,
- uint32_t flags,
- const char *desc);
+vb2_error_t vb21_fw_preamble_create(struct vb21_fw_preamble **fp_ptr,
+ const struct vb2_private_key *signing_key,
+ const struct vb21_signature **hash_list,
+ uint32_t hash_count, uint32_t fw_version,
+ uint32_t flags, const char *desc);
#endif /* VBOOT_REFERENCE_HOST_FW_PREAMBLE2_H_ */
diff --git a/host/lib21/include/host_key2.h b/host/lib21/include/host_key2.h
index 5ce41c06..d8a90f5f 100644
--- a/host/lib21/include/host_key2.h
+++ b/host/lib21/include/host_key2.h
@@ -9,6 +9,7 @@
#define VBOOT_REFERENCE_HOST_KEY2_H_
#include "2id.h"
+#include "2return_codes.h"
#include "2struct.h"
struct vb2_public_key;
@@ -98,9 +99,8 @@ void vb2_private_key_free(struct vb2_private_key *key);
* @param size Size of buffer in bytes
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb21_private_key_unpack(struct vb2_private_key **key_ptr,
- const uint8_t *buf,
- uint32_t size);
+vb2_error_t vb21_private_key_unpack(struct vb2_private_key **key_ptr,
+ const uint8_t *buf, uint32_t size);
/**
* Read a private key from vb21_packed_private_key format.
@@ -110,8 +110,8 @@ int vb21_private_key_unpack(struct vb2_private_key **key_ptr,
* @param filename File to read key data from.
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb21_private_key_read(struct vb2_private_key **key_ptr,
- const char *filename);
+vb2_error_t vb21_private_key_read(struct vb2_private_key **key_ptr,
+ const char *filename);
/**
* Read a private key from a .pem file.
@@ -124,8 +124,8 @@ int vb21_private_key_read(struct vb2_private_key **key_ptr,
* @param filename File to read key data from.
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_private_key_read_pem(struct vb2_private_key **key_ptr,
- const char *filename);
+vb2_error_t vb2_private_key_read_pem(struct vb2_private_key **key_ptr,
+ const char *filename);
/**
* Set the description of a private key.
@@ -134,7 +134,8 @@ int vb2_private_key_read_pem(struct vb2_private_key **key_ptr,
* @param desc Description string, or NULL if no description.
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_private_key_set_desc(struct vb2_private_key *key, const char *desc);
+vb2_error_t vb2_private_key_set_desc(struct vb2_private_key *key,
+ const char *desc);
/**
* Write a private key to vb21_packed_private_key format.
@@ -143,8 +144,8 @@ int vb2_private_key_set_desc(struct vb2_private_key *key, const char *desc);
* @param filename File to write key data to.
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb21_private_key_write(const struct vb2_private_key *key,
- const char *filename);
+vb2_error_t vb21_private_key_write(const struct vb2_private_key *key,
+ const char *filename);
/**
* Get a private key for an unsigned hash
@@ -154,8 +155,8 @@ int vb21_private_key_write(const struct vb2_private_key *key,
* @param hash_alg Hash algorithm to use
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_private_key_hash(const struct vb2_private_key **key_ptr,
- enum vb2_hash_algorithm hash_alg);
+vb2_error_t vb2_private_key_hash(const struct vb2_private_key **key_ptr,
+ enum vb2_hash_algorithm hash_alg);
/**
* Allocate a public key buffer of sufficient size for the signature algorithm.
@@ -168,8 +169,8 @@ int vb2_private_key_hash(const struct vb2_private_key **key_ptr,
* @param sig_alg Signature algorithm for key.
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_public_key_alloc(struct vb2_public_key **key_ptr,
- enum vb2_signature_algorithm sig_alg);
+vb2_error_t vb2_public_key_alloc(struct vb2_public_key **key_ptr,
+ enum vb2_signature_algorithm sig_alg);
/**
* Return the packed data for a key allocated with vb2_public_key_alloc().
@@ -202,8 +203,8 @@ void vb2_public_key_free(struct vb2_public_key *key);
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_public_key_read_keyb(struct vb2_public_key **key_ptr,
- const char *filename);
+vb2_error_t vb2_public_key_read_keyb(struct vb2_public_key **key_ptr,
+ const char *filename);
/**
* Set the description of a public key.
@@ -212,7 +213,8 @@ int vb2_public_key_read_keyb(struct vb2_public_key **key_ptr,
* @param desc Description string, or NULL if no description.
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_public_key_set_desc(struct vb2_public_key *key, const char *desc);
+vb2_error_t vb2_public_key_set_desc(struct vb2_public_key *key,
+ const char *desc);
/**
* Read a public key in vb21_packed_key format.
@@ -221,8 +223,8 @@ int vb2_public_key_set_desc(struct vb2_public_key *key, const char *desc);
* Caller is responsible for calling free() on this.
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb21_packed_key_read(struct vb21_packed_key **key_ptr,
- const char *filename);
+vb2_error_t vb21_packed_key_read(struct vb21_packed_key **key_ptr,
+ const char *filename);
/**
* Pack a public key into vb21_packed_key format.
@@ -233,8 +235,8 @@ int vb21_packed_key_read(struct vb21_packed_key **key_ptr,
* this.
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb21_public_key_pack(struct vb21_packed_key **key_ptr,
- const struct vb2_public_key *pubk);
+vb2_error_t vb21_public_key_pack(struct vb21_packed_key **key_ptr,
+ const struct vb2_public_key *pubk);
/**
* Get a public key for an unsigned hash.
@@ -243,8 +245,8 @@ int vb21_public_key_pack(struct vb21_packed_key **key_ptr,
* @param hash_alg Hash algorithm to use
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb2_public_key_hash(struct vb2_public_key *key,
- enum vb2_hash_algorithm hash_alg);
+vb2_error_t vb2_public_key_hash(struct vb2_public_key *key,
+ enum vb2_hash_algorithm hash_alg);
/**
@@ -262,7 +264,7 @@ enum vb2_signature_algorithm vb2_rsa_sig_alg(struct rsa_st *rsa);
* @param filename File to write key data to.
* @return VB2_SUCCESS, or non-zero error code if error.
*/
-int vb21_public_key_write(const struct vb2_public_key *key,
- const char *filename);
+vb2_error_t vb21_public_key_write(const struct vb2_public_key *key,
+ const char *filename);
#endif /* VBOOT_REFERENCE_HOST_KEY2_H_ */
diff --git a/host/lib21/include/host_keyblock2.h b/host/lib21/include/host_keyblock2.h
index 6abfdc98..faa51d26 100644
--- a/host/lib21/include/host_keyblock2.h
+++ b/host/lib21/include/host_keyblock2.h
@@ -25,11 +25,10 @@ struct vb21_keyblock;
* taken from the data key.
* @return VB2_SUCCESS, or non-zero error code if failure.
*/
-int vb21_keyblock_create(struct vb21_keyblock **kb_ptr,
- const struct vb2_public_key *data_key,
- const struct vb2_private_key **signing_keys,
- uint32_t signing_key_count,
- uint32_t flags,
- const char *desc);
+vb2_error_t vb21_keyblock_create(struct vb21_keyblock **kb_ptr,
+ const struct vb2_public_key *data_key,
+ const struct vb2_private_key **signing_keys,
+ uint32_t signing_key_count, uint32_t flags,
+ const char *desc);
#endif /* VBOOT_REFERENCE_HOST_KEYBLOCK2_H_ */
diff --git a/host/lib21/include/host_misc2.h b/host/lib21/include/host_misc2.h
index 5d891cad..795ebb23 100644
--- a/host/lib21/include/host_misc2.h
+++ b/host/lib21/include/host_misc2.h
@@ -21,6 +21,6 @@
* @param id Destination for binary representation
* @return VB2_SUCCESS, or non-zero if error.
*/
-int vb2_str_to_id(const char *str, struct vb2_id *id);
+vb2_error_t vb2_str_to_id(const char *str, struct vb2_id *id);
#endif /* VBOOT_REFERENCE_HOST_MISC2_H_ */
diff --git a/host/lib21/include/host_signature2.h b/host/lib21/include/host_signature2.h
index 5faf6da7..0b1784af 100644
--- a/host/lib21/include/host_signature2.h
+++ b/host/lib21/include/host_signature2.h
@@ -21,9 +21,8 @@ struct vb21_signature;
* @param size_ptr On success, contains the info size in bytes
* @return VB2_SUCCESS, or non-zero error code on failure.
*/
-int vb2_digest_info(enum vb2_hash_algorithm hash_alg,
- const uint8_t **buf_ptr,
- uint32_t *size_ptr);
+vb2_error_t vb2_digest_info(enum vb2_hash_algorithm hash_alg,
+ const uint8_t **buf_ptr, uint32_t *size_ptr);
/**
* Sign data buffer
@@ -37,11 +36,9 @@ int vb2_digest_info(enum vb2_hash_algorithm hash_alg,
* key description will be used.
* @return VB2_SUCCESS, or non-zero error code on failure.
*/
-int vb21_sign_data(struct vb21_signature **sig_ptr,
- const uint8_t *data,
- uint32_t size,
- const struct vb2_private_key *key,
- const char *desc);
+vb2_error_t vb21_sign_data(struct vb21_signature **sig_ptr, const uint8_t *data,
+ uint32_t size, const struct vb2_private_key *key,
+ const char *desc);
/**
* Calculate the signature size for a private key.
@@ -52,9 +49,9 @@ int vb21_sign_data(struct vb21_signature **sig_ptr,
* key description will be used.
* @return VB2_SUCCESS, or non-zero error code on failure.
*/
-int vb21_sig_size_for_key(uint32_t *size_ptr,
- const struct vb2_private_key *key,
- const char *desc);
+vb2_error_t vb21_sig_size_for_key(uint32_t *size_ptr,
+ const struct vb2_private_key *key,
+ const char *desc);
/**
* Calculate the total signature size for a list of keys.
@@ -64,9 +61,9 @@ int vb21_sig_size_for_key(uint32_t *size_ptr,
* @param key_count Number of keys.
* @return VB2_SUCCESS, or non-zero error code on failure.
*/
-int vb21_sig_size_for_keys(uint32_t *size_ptr,
- const struct vb2_private_key **key_list,
- uint32_t key_count);
+vb2_error_t vb21_sig_size_for_keys(uint32_t *size_ptr,
+ const struct vb2_private_key **key_list,
+ uint32_t key_count);
/**
* Sign object with a key.
@@ -78,10 +75,9 @@ int vb21_sig_size_for_keys(uint32_t *size_ptr,
* @param key Key to sign object with
* @param desc If non-null, description to use for signature
*/
-int vb21_sign_object(uint8_t *buf,
- uint32_t sig_offset,
- const struct vb2_private_key *key,
- const char *desc);
+vb2_error_t vb21_sign_object(uint8_t *buf, uint32_t sig_offset,
+ const struct vb2_private_key *key,
+ const char *desc);
/**
* Sign object with list of keys.
@@ -93,9 +89,8 @@ int vb21_sign_object(uint8_t *buf,
* @param key_list List of keys to sign object with
* @param key_count Number of keys in list
*/
-int vb21_sign_object_multiple(uint8_t *buf,
- uint32_t sig_offset,
- const struct vb2_private_key **key_list,
- uint32_t key_count);
+vb2_error_t vb21_sign_object_multiple(uint8_t *buf, uint32_t sig_offset,
+ const struct vb2_private_key **key_list,
+ uint32_t key_count);
#endif /* VBOOT_REFERENCE_HOST_SIGNATURE2_H_ */
diff --git a/tests/vb20_api_kernel_tests.c b/tests/vb20_api_kernel_tests.c
index 64fb421f..3a300ab6 100644
--- a/tests/vb20_api_kernel_tests.c
+++ b/tests/vb20_api_kernel_tests.c
@@ -152,11 +152,9 @@ static void reset_common_data(enum reset_type t)
/* Mocked functions */
-int vb2ex_read_resource(struct vb2_context *c,
- enum vb2_resource_index index,
- uint32_t offset,
- void *buf,
- uint32_t size)
+vb2_error_t vb2ex_read_resource(struct vb2_context *c,
+ enum vb2_resource_index index, uint32_t offset,
+ void *buf, uint32_t size)
{
uint8_t *rptr;
uint32_t rsize;
@@ -180,25 +178,25 @@ int vb2ex_read_resource(struct vb2_context *c,
return VB2_SUCCESS;
}
-int vb2_read_gbb_header(struct vb2_context *c, struct vb2_gbb_header *gbb)
+vb2_error_t vb2_read_gbb_header(struct vb2_context *c,
+ struct vb2_gbb_header *gbb)
{
memcpy(gbb, &mock_gbb.h, sizeof(*gbb));
return mock_read_gbb_header_retval;
}
-int vb2_load_kernel_keyblock(struct vb2_context *c)
+vb2_error_t vb2_load_kernel_keyblock(struct vb2_context *c)
{
return mock_load_kernel_keyblock_retval;
}
-int vb2_load_kernel_preamble(struct vb2_context *c)
+vb2_error_t vb2_load_kernel_preamble(struct vb2_context *c)
{
return mock_load_kernel_preamble_retval;
}
-int vb2_unpack_key_buffer(struct vb2_public_key *key,
- const uint8_t *buf,
- uint32_t size)
+vb2_error_t vb2_unpack_key_buffer(struct vb2_public_key *key,
+ const uint8_t *buf, uint32_t size)
{
const struct vb2_packed_key *k = (const struct vb2_packed_key *)buf;
@@ -207,10 +205,9 @@ int vb2_unpack_key_buffer(struct vb2_public_key *key,
return mock_unpack_key_retval;
}
-int vb2_verify_digest(const struct vb2_public_key *key,
- struct vb2_signature *sig,
- const uint8_t *digest,
- const struct vb2_workbuf *wb)
+vb2_error_t vb2_verify_digest(const struct vb2_public_key *key,
+ struct vb2_signature *sig, const uint8_t *digest,
+ const struct vb2_workbuf *wb)
{
if (memcmp(digest, (uint8_t *)sig + sig->sig_offset, sig->sig_size))
return VB2_ERROR_VDATA_VERIFY_DIGEST;
diff --git a/tests/vb20_api_tests.c b/tests/vb20_api_tests.c
index 1c96efa1..ae6a216c 100644
--- a/tests/vb20_api_tests.c
+++ b/tests/vb20_api_tests.c
@@ -38,10 +38,10 @@ static enum {
HWCRYPTO_FORBIDDEN,
} hwcrypto_state;
-static int retval_vb2_load_fw_keyblock;
-static int retval_vb2_load_fw_preamble;
-static int retval_vb2_digest_finalize;
-static int retval_vb2_verify_digest;
+static vb2_error_t retval_vb2_load_fw_keyblock;
+static vb2_error_t retval_vb2_load_fw_preamble;
+static vb2_error_t retval_vb2_digest_finalize;
+static vb2_error_t retval_vb2_verify_digest;
/* Type of test to reset for */
enum reset_type {
@@ -107,19 +107,18 @@ static void reset_common_data(enum reset_type t)
/* Mocked functions */
-int vb2_load_fw_keyblock(struct vb2_context *c)
+vb2_error_t vb2_load_fw_keyblock(struct vb2_context *c)
{
return retval_vb2_load_fw_keyblock;
}
-int vb2_load_fw_preamble(struct vb2_context *c)
+vb2_error_t vb2_load_fw_preamble(struct vb2_context *c)
{
return retval_vb2_load_fw_preamble;
}
-int vb2_unpack_key_buffer(struct vb2_public_key *key,
- const uint8_t *buf,
- uint32_t size)
+vb2_error_t vb2_unpack_key_buffer(struct vb2_public_key *key,
+ const uint8_t *buf, uint32_t size)
{
struct vb2_packed_key *k = (struct vb2_packed_key *)buf;
@@ -132,8 +131,8 @@ int vb2_unpack_key_buffer(struct vb2_public_key *key,
return VB2_SUCCESS;
}
-int vb2ex_hwcrypto_digest_init(enum vb2_hash_algorithm hash_alg,
- uint32_t data_size)
+vb2_error_t vb2ex_hwcrypto_digest_init(enum vb2_hash_algorithm hash_alg,
+ uint32_t data_size)
{
switch (hwcrypto_state) {
case HWCRYPTO_DISABLED:
@@ -149,8 +148,8 @@ int vb2ex_hwcrypto_digest_init(enum vb2_hash_algorithm hash_alg,
}
}
-int vb2ex_hwcrypto_digest_extend(const uint8_t *buf,
- uint32_t size)
+vb2_error_t vb2ex_hwcrypto_digest_extend(const uint8_t *buf,
+ uint32_t size)
{
if (hwcrypto_state != HWCRYPTO_ENABLED)
return VB2_ERROR_UNKNOWN;
@@ -164,7 +163,7 @@ static void fill_digest(uint8_t *digest, uint32_t digest_size)
memset(digest, 0x0a, digest_size);
}
-int vb2ex_hwcrypto_digest_finalize(uint8_t *digest,
+vb2_error_t vb2ex_hwcrypto_digest_finalize(uint8_t *digest,
uint32_t digest_size)
{
if (hwcrypto_state != HWCRYPTO_ENABLED)
@@ -176,7 +175,7 @@ int vb2ex_hwcrypto_digest_finalize(uint8_t *digest,
return retval_vb2_digest_finalize;
}
-int vb2_digest_init(struct vb2_digest_context *dc,
+vb2_error_t vb2_digest_init(struct vb2_digest_context *dc,
enum vb2_hash_algorithm hash_alg)
{
if (hwcrypto_state == HWCRYPTO_ENABLED)
@@ -190,9 +189,8 @@ int vb2_digest_init(struct vb2_digest_context *dc,
return VB2_SUCCESS;
}
-int vb2_digest_extend(struct vb2_digest_context *dc,
- const uint8_t *buf,
- uint32_t size)
+vb2_error_t vb2_digest_extend(struct vb2_digest_context *dc, const uint8_t *buf,
+ uint32_t size)
{
if (hwcrypto_state == HWCRYPTO_ENABLED)
return VB2_ERROR_UNKNOWN;
@@ -202,9 +200,8 @@ int vb2_digest_extend(struct vb2_digest_context *dc,
return VB2_SUCCESS;
}
-int vb2_digest_finalize(struct vb2_digest_context *dc,
- uint8_t *digest,
- uint32_t digest_size)
+vb2_error_t vb2_digest_finalize(struct vb2_digest_context *dc, uint8_t *digest,
+ uint32_t digest_size)
{
if (hwcrypto_state == HWCRYPTO_ENABLED)
return VB2_ERROR_UNKNOWN;
@@ -220,10 +217,9 @@ uint32_t vb2_rsa_sig_size(enum vb2_signature_algorithm sig_alg)
return mock_sig_size;
}
-int vb2_rsa_verify_digest(const struct vb2_public_key *key,
- uint8_t *sig,
- const uint8_t *digest,
- const struct vb2_workbuf *wb)
+vb2_error_t vb2_rsa_verify_digest(const struct vb2_public_key *key,
+ uint8_t *sig, const uint8_t *digest,
+ const struct vb2_workbuf *wb)
{
return retval_vb2_verify_digest;
}
diff --git a/tests/vb20_kernel_tests.c b/tests/vb20_kernel_tests.c
index c798f862..5490ccce 100644
--- a/tests/vb20_kernel_tests.c
+++ b/tests/vb20_kernel_tests.c
@@ -135,11 +135,9 @@ static void reset_common_data(enum reset_type t)
/* Mocked functions */
-int vb2ex_read_resource(struct vb2_context *c,
- enum vb2_resource_index index,
- uint32_t offset,
- void *buf,
- uint32_t size)
+vb2_error_t vb2ex_read_resource(struct vb2_context *c,
+ enum vb2_resource_index index, uint32_t offset,
+ void *buf, uint32_t size)
{
uint8_t *rptr;
uint32_t rsize;
@@ -167,26 +165,24 @@ int vb2ex_read_resource(struct vb2_context *c,
return VB2_SUCCESS;
}
-int vb2_unpack_key_buffer(struct vb2_public_key *key,
- const uint8_t *buf,
- uint32_t size)
+vb2_error_t vb2_unpack_key_buffer(struct vb2_public_key *key,
+ const uint8_t *buf, uint32_t size)
{
key->arrsize = 0;
return mock_unpack_key_retval;
}
-int vb2_verify_keyblock(struct vb2_keyblock *block,
- uint32_t size,
- const struct vb2_public_key *key,
- const struct vb2_workbuf *w)
+vb2_error_t vb2_verify_keyblock(struct vb2_keyblock *block, uint32_t size,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *w)
{
return mock_verify_keyblock_retval;
}
-int vb2_verify_kernel_preamble(struct vb2_kernel_preamble *preamble,
- uint32_t size,
- const struct vb2_public_key *key,
- const struct vb2_workbuf *w)
+vb2_error_t vb2_verify_kernel_preamble(struct vb2_kernel_preamble *preamble,
+ uint32_t size,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *w)
{
return mock_verify_preamble_retval;
}
diff --git a/tests/vb20_misc_tests.c b/tests/vb20_misc_tests.c
index 9716ae2a..46e3f036 100644
--- a/tests/vb20_misc_tests.c
+++ b/tests/vb20_misc_tests.c
@@ -121,11 +121,9 @@ struct vb2_gbb_header *vb2_get_gbb(struct vb2_context *c)
return &gbb;
}
-int vb2ex_read_resource(struct vb2_context *c,
- enum vb2_resource_index index,
- uint32_t offset,
- void *buf,
- uint32_t size)
+vb2_error_t vb2ex_read_resource(struct vb2_context *c,
+ enum vb2_resource_index index, uint32_t offset,
+ void *buf, uint32_t size)
{
uint8_t *rptr;
uint32_t rsize;
@@ -153,26 +151,24 @@ int vb2ex_read_resource(struct vb2_context *c,
return VB2_SUCCESS;
}
-int vb2_unpack_key_buffer(struct vb2_public_key *key,
- const uint8_t *buf,
- uint32_t size)
+vb2_error_t vb2_unpack_key_buffer(struct vb2_public_key *key,
+ const uint8_t *buf, uint32_t size)
{
key->arrsize = 0;
return mock_unpack_key_retval;
}
-int vb2_verify_keyblock(struct vb2_keyblock *block,
- uint32_t size,
- const struct vb2_public_key *key,
- const struct vb2_workbuf *wb)
+vb2_error_t vb2_verify_keyblock(struct vb2_keyblock *block, uint32_t size,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *wb)
{
return mock_verify_keyblock_retval;
}
-int vb2_verify_fw_preamble(struct vb2_fw_preamble *preamble,
- uint32_t size,
- const struct vb2_public_key *key,
- const struct vb2_workbuf *wb)
+vb2_error_t vb2_verify_fw_preamble(struct vb2_fw_preamble *preamble,
+ uint32_t size,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *wb)
{
return mock_verify_preamble_retval;
}
diff --git a/tests/vb20_verify_fw.c b/tests/vb20_verify_fw.c
index 5fd232a5..850d4b01 100644
--- a/tests/vb20_verify_fw.c
+++ b/tests/vb20_verify_fw.c
@@ -20,11 +20,9 @@ const char *body_fname;
* Local implementation which reads resources from individual files. Could be
* more elegant and read from bios.bin, if we understood the fmap.
*/
-int vb2ex_read_resource(struct vb2_context *c,
- enum vb2_resource_index index,
- uint32_t offset,
- void *buf,
- uint32_t size)
+vb2_error_t vb2ex_read_resource(struct vb2_context *c,
+ enum vb2_resource_index index, uint32_t offset,
+ void *buf, uint32_t size)
{
const char *fname;
FILE *f;
@@ -60,7 +58,7 @@ int vb2ex_read_resource(struct vb2_context *c,
return got_size == size ? VB2_SUCCESS : VB2_ERROR_UNKNOWN;
}
-int vb2ex_tpm_clear_owner(struct vb2_context *c)
+vb2_error_t vb2ex_tpm_clear_owner(struct vb2_context *c)
{
// TODO: implement
return VB2_SUCCESS;
@@ -86,13 +84,13 @@ static void save_if_needed(struct vb2_context *c)
/**
* Verify firmware body
*/
-static int hash_body(struct vb2_context *c)
+static vb2_error_t hash_body(struct vb2_context *c)
{
uint32_t expect_size;
uint8_t block[8192];
uint32_t size;
FILE *f;
- int rv;
+ vb2_error_t rv;
/* Open the body data */
f = fopen(body_fname, "rb");
@@ -148,7 +146,7 @@ int main(int argc, char *argv[])
{
struct vb2_context ctx;
uint8_t workbuf[16384] __attribute__ ((aligned (VB2_WORKBUF_ALIGN)));
- int rv;
+ vb2_error_t rv;
if (argc < 4) {
print_help(argv[0]);
diff --git a/tests/vb21_api_tests.c b/tests/vb21_api_tests.c
index cbe61086..53177957 100644
--- a/tests/vb21_api_tests.c
+++ b/tests/vb21_api_tests.c
@@ -50,9 +50,9 @@ static enum {
static struct vb2_digest_context hwcrypto_emulation_dc;
-static int retval_hwcrypto;
-static int retval_vb21_load_fw_keyblock;
-static int retval_vb21_load_fw_preamble;
+static vb2_error_t retval_hwcrypto;
+static vb2_error_t retval_vb21_load_fw_keyblock;
+static vb2_error_t retval_vb21_load_fw_preamble;
/* Type of test to reset for */
enum reset_type {
@@ -124,18 +124,18 @@ static void reset_common_data(enum reset_type t)
/* Mocked functions */
-int vb21_load_fw_keyblock(struct vb2_context *c)
+vb2_error_t vb21_load_fw_keyblock(struct vb2_context *c)
{
return retval_vb21_load_fw_keyblock;
}
-int vb21_load_fw_preamble(struct vb2_context *c)
+vb2_error_t vb21_load_fw_preamble(struct vb2_context *c)
{
return retval_vb21_load_fw_preamble;
}
-int vb2ex_hwcrypto_digest_init(enum vb2_hash_algorithm hash_alg,
- uint32_t data_size)
+vb2_error_t vb2ex_hwcrypto_digest_init(enum vb2_hash_algorithm hash_alg,
+ uint32_t data_size)
{
vb2_digest_init(&hwcrypto_emulation_dc, hash_alg);
@@ -153,8 +153,7 @@ int vb2ex_hwcrypto_digest_init(enum vb2_hash_algorithm hash_alg,
}
}
-int vb2ex_hwcrypto_digest_extend(const uint8_t *buf,
- uint32_t size)
+vb2_error_t vb2ex_hwcrypto_digest_extend(const uint8_t *buf, uint32_t size)
{
vb2_digest_extend(&hwcrypto_emulation_dc, buf, size);
@@ -164,8 +163,8 @@ int vb2ex_hwcrypto_digest_extend(const uint8_t *buf,
return retval_hwcrypto;
}
-int vb2ex_hwcrypto_digest_finalize(uint8_t *digest,
- uint32_t digest_size)
+vb2_error_t vb2ex_hwcrypto_digest_finalize(uint8_t *digest,
+ uint32_t digest_size)
{
vb2_digest_finalize(&hwcrypto_emulation_dc, digest, digest_size);
diff --git a/tests/vb21_misc_tests.c b/tests/vb21_misc_tests.c
index db7cd775..37c0ea3a 100644
--- a/tests/vb21_misc_tests.c
+++ b/tests/vb21_misc_tests.c
@@ -126,11 +126,9 @@ struct vb2_gbb_header *vb2_get_gbb(struct vb2_context *c)
return &gbb;
}
-int vb2ex_read_resource(struct vb2_context *c,
- enum vb2_resource_index index,
- uint32_t offset,
- void *buf,
- uint32_t size)
+vb2_error_t vb2ex_read_resource(struct vb2_context *c,
+ enum vb2_resource_index index, uint32_t offset,
+ void *buf, uint32_t size)
{
uint8_t *rptr;
uint32_t rsize;
@@ -158,25 +156,23 @@ int vb2ex_read_resource(struct vb2_context *c,
return VB2_SUCCESS;
}
-int vb21_unpack_key(struct vb2_public_key *key,
- const uint8_t *buf,
- uint32_t size)
+vb2_error_t vb21_unpack_key(struct vb2_public_key *key, const uint8_t *buf,
+ uint32_t size)
{
return mock_unpack_key_retval;
}
-int vb21_verify_keyblock(struct vb21_keyblock *block,
- uint32_t size,
- const struct vb2_public_key *key,
- const struct vb2_workbuf *wb)
+vb2_error_t vb21_verify_keyblock(struct vb21_keyblock *block, uint32_t size,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *wb)
{
return mock_verify_keyblock_retval;
}
-int vb21_verify_fw_preamble(struct vb21_fw_preamble *preamble,
- uint32_t size,
- const struct vb2_public_key *key,
- const struct vb2_workbuf *wb)
+vb2_error_t vb21_verify_fw_preamble(struct vb21_fw_preamble *preamble,
+ uint32_t size,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *wb)
{
return mock_verify_preamble_retval;
}
diff --git a/tests/vb2_api_tests.c b/tests/vb2_api_tests.c
index 144102a6..b4db22b8 100644
--- a/tests/vb2_api_tests.c
+++ b/tests/vb2_api_tests.c
@@ -36,10 +36,10 @@ static const uint8_t mock_hwid_digest[VB2_GBB_HWID_DIGEST_SIZE] = {
/* Mocked function data */
static int force_dev_mode;
-static int retval_vb2_fw_parse_gbb;
-static int retval_vb2_check_dev_switch;
-static int retval_vb2_check_tpm_clear;
-static int retval_vb2_select_fw_slot;
+static vb2_error_t retval_vb2_fw_parse_gbb;
+static vb2_error_t retval_vb2_check_dev_switch;
+static vb2_error_t retval_vb2_check_tpm_clear;
+static vb2_error_t retval_vb2_select_fw_slot;
/* Type of test to reset for */
enum reset_type {
@@ -78,24 +78,24 @@ struct vb2_gbb_header *vb2_get_gbb(struct vb2_context *c)
return &gbb;
}
-int vb2_fw_parse_gbb(struct vb2_context *c)
+vb2_error_t vb2_fw_parse_gbb(struct vb2_context *c)
{
return retval_vb2_fw_parse_gbb;
}
-int vb2_check_dev_switch(struct vb2_context *c)
+vb2_error_t vb2_check_dev_switch(struct vb2_context *c)
{
if (force_dev_mode)
sd->flags |= VB2_SD_FLAG_DEV_MODE_ENABLED;
return retval_vb2_check_dev_switch;
}
-int vb2_check_tpm_clear(struct vb2_context *c)
+vb2_error_t vb2_check_tpm_clear(struct vb2_context *c)
{
return retval_vb2_check_tpm_clear;
}
-int vb2_select_fw_slot(struct vb2_context *c)
+vb2_error_t vb2_select_fw_slot(struct vb2_context *c)
{
return retval_vb2_select_fw_slot;
}
diff --git a/tests/vb2_gbb_tests.c b/tests/vb2_gbb_tests.c
index a7ff9b35..92d617aa 100644
--- a/tests/vb2_gbb_tests.c
+++ b/tests/vb2_gbb_tests.c
@@ -62,11 +62,9 @@ struct vb2_gbb_header *vb2_get_gbb(struct vb2_context *c)
return gbb;
}
-int vb2ex_read_resource(struct vb2_context *c,
- enum vb2_resource_index index,
- uint32_t offset,
- void *buf,
- uint32_t size)
+vb2_error_t vb2ex_read_resource(struct vb2_context *c,
+ enum vb2_resource_index index, uint32_t offset,
+ void *buf, uint32_t size)
{
uint8_t *rptr;
uint32_t rsize;
diff --git a/tests/vb2_misc_tests.c b/tests/vb2_misc_tests.c
index 85a6e697..a9f82531 100644
--- a/tests/vb2_misc_tests.c
+++ b/tests/vb2_misc_tests.c
@@ -57,11 +57,9 @@ struct vb2_gbb_header *vb2_get_gbb(struct vb2_context *c)
return &gbb;
}
-int vb2ex_read_resource(struct vb2_context *c,
- enum vb2_resource_index index,
- uint32_t offset,
- void *buf,
- uint32_t size)
+vb2_error_t vb2ex_read_resource(struct vb2_context *c,
+ enum vb2_resource_index index, uint32_t offset,
+ void *buf, uint32_t size)
{
if (index != mock_resource_index)
return VB2_ERROR_EX_READ_RESOURCE_INDEX;
@@ -73,7 +71,7 @@ int vb2ex_read_resource(struct vb2_context *c,
return VB2_SUCCESS;
}
-int vb2ex_tpm_clear_owner(struct vb2_context *c)
+vb2_error_t vb2ex_tpm_clear_owner(struct vb2_context *c)
{
mock_tpm_clear_called++;
diff --git a/tests/vboot_api_kernel2_tests.c b/tests/vboot_api_kernel2_tests.c
index f37913c4..56e8727a 100644
--- a/tests/vboot_api_kernel2_tests.c
+++ b/tests/vboot_api_kernel2_tests.c
@@ -180,7 +180,7 @@ uint32_t VbExGetSwitches(uint32_t request_mask)
return result;
}
-int VbExLegacy(enum VbAltFwIndex_t _altfw_num)
+vb2_error_t VbExLegacy(enum VbAltFwIndex_t _altfw_num)
{
vbexlegacy_called++;
altfw_num = _altfw_num;
@@ -234,7 +234,7 @@ int vb2_audio_looping(void)
return 1;
}
-uint32_t VbTryLoadKernel(struct vb2_context *c, uint32_t get_info_flags)
+vb2_error_t VbTryLoadKernel(struct vb2_context *c, uint32_t get_info_flags)
{
return vbtlk_retval + get_info_flags;
}
@@ -248,7 +248,7 @@ vb2_error_t VbDisplayScreen(struct vb2_context *c, uint32_t screen, int force,
return VBERROR_SUCCESS;
}
-uint32_t SetVirtualDevMode(int val)
+vb2_error_t SetVirtualDevMode(int val)
{
virtdev_set = val;
return virtdev_retval;
@@ -262,7 +262,7 @@ vb2_error_t VbExSetVendorData(const char *vendor_data_value)
return VBERROR_SUCCESS;
}
-int vb2ex_tpm_set_mode(enum vb2_tpm_mode mode_val)
+vb2_error_t vb2ex_tpm_set_mode(enum vb2_tpm_mode mode_val)
{
tpm_set_mode_called = 1;
/*
diff --git a/tests/vboot_api_kernel4_tests.c b/tests/vboot_api_kernel4_tests.c
index e466baf9..8ed46200 100644
--- a/tests/vboot_api_kernel4_tests.c
+++ b/tests/vboot_api_kernel4_tests.c
@@ -127,7 +127,7 @@ uint32_t RollbackFwmpRead(struct RollbackSpaceFwmp *fwmp)
return rfr_retval;
}
-uint32_t VbTryLoadKernel(struct vb2_context *c, uint32_t get_info_flags)
+vb2_error_t VbTryLoadKernel(struct vb2_context *c, uint32_t get_info_flags)
{
shared->kernel_version_tpm = new_version;
@@ -182,7 +182,7 @@ uint32_t VbExGetSwitches(uint32_t request_mask)
return 0;
}
-int vb2ex_tpm_set_mode(enum vb2_tpm_mode mode_val)
+vb2_error_t vb2ex_tpm_set_mode(enum vb2_tpm_mode mode_val)
{
return VB2_SUCCESS;
}
diff --git a/tests/vboot_api_kernel5_tests.c b/tests/vboot_api_kernel5_tests.c
index 1f4e6cd9..a0833fd9 100644
--- a/tests/vboot_api_kernel5_tests.c
+++ b/tests/vboot_api_kernel5_tests.c
@@ -114,37 +114,32 @@ struct vb2_gbb_header *vb2_get_gbb(struct vb2_context *c)
return &gbb;
}
-int vb2ex_read_resource(struct vb2_context *c,
- enum vb2_resource_index index,
- uint32_t offset,
- void *buf,
- uint32_t size)
+vb2_error_t vb2ex_read_resource(struct vb2_context *c,
+ enum vb2_resource_index index, uint32_t offset,
+ void *buf, uint32_t size)
{
memset(buf, 0, size);
return VB2_SUCCESS;
}
-int vb2_gbb_read_root_key(struct vb2_context *c,
- struct vb2_packed_key **keyp,
- uint32_t *size,
- struct vb2_workbuf *wb)
+vb2_error_t vb2_gbb_read_root_key(struct vb2_context *c,
+ struct vb2_packed_key **keyp, uint32_t *size,
+ struct vb2_workbuf *wb)
{
*keyp = &mock_key;
return VB2_SUCCESS;
}
-int vb2_gbb_read_recovery_key(struct vb2_context *c,
- struct vb2_packed_key **keyp,
- uint32_t *size,
- struct vb2_workbuf *wb)
+vb2_error_t vb2_gbb_read_recovery_key(struct vb2_context *c,
+ struct vb2_packed_key **keyp,
+ uint32_t *size, struct vb2_workbuf *wb)
{
*keyp = &mock_key;
return VB2_SUCCESS;
}
-int vb2_unpack_key_buffer(struct vb2_public_key *key,
- const uint8_t *buf,
- uint32_t size)
+vb2_error_t vb2_unpack_key_buffer(struct vb2_public_key *key,
+ const uint8_t *buf, uint32_t size)
{
if (--unpack_key_fail == 0)
return VB2_ERROR_MOCK;
@@ -152,10 +147,9 @@ int vb2_unpack_key_buffer(struct vb2_public_key *key,
return VB2_SUCCESS;
}
-int vb2_verify_keyblock(struct vb2_keyblock *block,
- uint32_t size,
- const struct vb2_public_key *key,
- const struct vb2_workbuf *wb)
+vb2_error_t vb2_verify_keyblock(struct vb2_keyblock *block, uint32_t size,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *wb)
{
hash_only_check = 0;
@@ -167,9 +161,9 @@ int vb2_verify_keyblock(struct vb2_keyblock *block,
return VB2_SUCCESS;
}
-int vb2_verify_keyblock_hash(const struct vb2_keyblock *block,
- uint32_t size,
- const struct vb2_workbuf *wb)
+vb2_error_t vb2_verify_keyblock_hash(const struct vb2_keyblock *block,
+ uint32_t size,
+ const struct vb2_workbuf *wb)
{
hash_only_check = 1;
@@ -181,10 +175,10 @@ int vb2_verify_keyblock_hash(const struct vb2_keyblock *block,
return VB2_SUCCESS;
}
-int vb2_verify_kernel_preamble(struct vb2_kernel_preamble *preamble,
- uint32_t size,
- const struct vb2_public_key *key,
- const struct vb2_workbuf *wb)
+vb2_error_t vb2_verify_kernel_preamble(struct vb2_kernel_preamble *preamble,
+ uint32_t size,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *wb)
{
if (preamble_verify_fail)
return VB2_ERROR_MOCK;
@@ -194,11 +188,10 @@ int vb2_verify_kernel_preamble(struct vb2_kernel_preamble *preamble,
return VB2_SUCCESS;
}
-int vb2_verify_data(const uint8_t *data,
- uint32_t size,
- struct vb2_signature *sig,
- const struct vb2_public_key *key,
- const struct vb2_workbuf *wb)
+vb2_error_t vb2_verify_data(const uint8_t *data, uint32_t size,
+ struct vb2_signature *sig,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *wb)
{
if (verify_data_fail)
return VB2_ERROR_MOCK;
diff --git a/tests/vboot_api_kernel6_tests.c b/tests/vboot_api_kernel6_tests.c
index dde977b3..7e2a7d40 100644
--- a/tests/vboot_api_kernel6_tests.c
+++ b/tests/vboot_api_kernel6_tests.c
@@ -27,7 +27,7 @@ static void ResetMocks(void)
}
/* Mocks */
-uint32_t SetVirtualDevMode(int val)
+vb2_error_t SetVirtualDevMode(int val)
{
if (virtual_dev_mode_fail)
return VBERROR_SIMULATED;
diff --git a/tests/vboot_detach_menu_tests.c b/tests/vboot_detach_menu_tests.c
index cba297b8..37ab65ff 100644
--- a/tests/vboot_detach_menu_tests.c
+++ b/tests/vboot_detach_menu_tests.c
@@ -176,7 +176,7 @@ uint32_t VbExGetSwitches(uint32_t request_mask)
return 0;
}
-int VbExLegacy(enum VbAltFwIndex_t _altfw_num)
+vb2_error_t VbExLegacy(enum VbAltFwIndex_t _altfw_num)
{
vbexlegacy_called++;
altfw_num = _altfw_num;
@@ -247,7 +247,7 @@ vb2_error_t VbExBeep(uint32_t msec, uint32_t frequency)
return VBERROR_SUCCESS;
}
-uint32_t SetVirtualDevMode(int val)
+vb2_error_t SetVirtualDevMode(int val)
{
virtdev_set = val;
return virtdev_retval;
diff --git a/tests/vboot_kernel_tests.c b/tests/vboot_kernel_tests.c
index 56efbf36..ad0a9f6d 100644
--- a/tests/vboot_kernel_tests.c
+++ b/tests/vboot_kernel_tests.c
@@ -193,36 +193,32 @@ struct vb2_gbb_header *vb2_get_gbb(struct vb2_context *c)
return &gbb;
}
-int vb2ex_read_resource(struct vb2_context *c,
- enum vb2_resource_index index,
- uint32_t offset,
- void *buf,
- uint32_t size)
+vb2_error_t vb2ex_read_resource(struct vb2_context *c,
+ enum vb2_resource_index index, uint32_t offset,
+ void *buf, uint32_t size)
{
memset(buf, 0, size);
return VB2_SUCCESS;
}
-int vb2_gbb_read_root_key(struct vb2_context *c,
- struct vb2_packed_key **keyp,
- uint32_t *size,
- struct vb2_workbuf *wb)
+vb2_error_t vb2_gbb_read_root_key(struct vb2_context *c,
+ struct vb2_packed_key **keyp, uint32_t *size,
+ struct vb2_workbuf *wb)
{
*keyp = &mock_key;
return VB2_SUCCESS;
}
-int vb2_gbb_read_recovery_key(struct vb2_context *c,
- struct vb2_packed_key **keyp,
- uint32_t *size,
- struct vb2_workbuf *wb)
+vb2_error_t vb2_gbb_read_recovery_key(struct vb2_context *c,
+ struct vb2_packed_key **keyp,
+ uint32_t *size, struct vb2_workbuf *wb)
{
*keyp = &mock_key;
return VB2_SUCCESS;
}
vb2_error_t VbExDiskRead(VbExDiskHandle_t h, uint64_t lba_start,
- uint64_t lba_count, void *buffer)
+ uint64_t lba_count, void *buffer)
{
LOGCALL("VbExDiskRead(h, %d, %d)\n", (int)lba_start, (int)lba_count);
@@ -236,7 +232,7 @@ vb2_error_t VbExDiskRead(VbExDiskHandle_t h, uint64_t lba_start,
}
vb2_error_t VbExDiskWrite(VbExDiskHandle_t h, uint64_t lba_start,
- uint64_t lba_count, const void *buffer)
+ uint64_t lba_count, const void *buffer)
{
LOGCALL("VbExDiskWrite(h, %d, %d)\n", (int)lba_start, (int)lba_count);
@@ -278,9 +274,8 @@ void GetCurrentKernelUniqueGuid(GptData *gpt, void *dest)
memcpy(dest, fake_guid, sizeof(fake_guid));
}
-int vb2_unpack_key_buffer(struct vb2_public_key *key,
- const uint8_t *buf,
- uint32_t size)
+vb2_error_t vb2_unpack_key_buffer(struct vb2_public_key *key,
+ const uint8_t *buf, uint32_t size)
{
if (--unpack_key_fail == 0)
return VB2_ERROR_MOCK;
@@ -288,10 +283,9 @@ int vb2_unpack_key_buffer(struct vb2_public_key *key,
return VB2_SUCCESS;
}
-int vb2_verify_keyblock(struct vb2_keyblock *block,
- uint32_t size,
- const struct vb2_public_key *key,
- const struct vb2_workbuf *wb)
+vb2_error_t vb2_verify_keyblock(struct vb2_keyblock *block, uint32_t size,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *wb)
{
if (key_block_verify_fail >= 1)
return VB2_ERROR_MOCK;
@@ -301,9 +295,9 @@ int vb2_verify_keyblock(struct vb2_keyblock *block,
return VB2_SUCCESS;
}
-int vb2_verify_keyblock_hash(const struct vb2_keyblock *block,
- uint32_t size,
- const struct vb2_workbuf *wb)
+vb2_error_t vb2_verify_keyblock_hash(const struct vb2_keyblock *block,
+ uint32_t size,
+ const struct vb2_workbuf *wb)
{
if (key_block_verify_fail >= 2)
return VB2_ERROR_MOCK;
@@ -313,9 +307,8 @@ int vb2_verify_keyblock_hash(const struct vb2_keyblock *block,
return VB2_SUCCESS;
}
-int vb2_verify_kernel_preamble(struct vb2_kernel_preamble *preamble,
- uint32_t size,
- const struct vb2_public_key *key,
+vb2_error_t vb2_verify_kernel_preamble(struct vb2_kernel_preamble *preamble,
+ uint32_t size, const struct vb2_public_key *key,
const struct vb2_workbuf *wb)
{
if (preamble_verify_fail)
@@ -326,11 +319,10 @@ int vb2_verify_kernel_preamble(struct vb2_kernel_preamble *preamble,
return VB2_SUCCESS;
}
-int vb2_verify_data(const uint8_t *data,
- uint32_t size,
- struct vb2_signature *sig,
- const struct vb2_public_key *key,
- const struct vb2_workbuf *wb)
+vb2_error_t vb2_verify_data(const uint8_t *data, uint32_t size,
+ struct vb2_signature *sig,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *wb)
{
if (verify_data_fail)
return VB2_ERROR_MOCK;
@@ -338,11 +330,9 @@ int vb2_verify_data(const uint8_t *data,
return VB2_SUCCESS;
}
-int vb2_digest_buffer(const uint8_t *buf,
- uint32_t size,
- enum vb2_hash_algorithm hash_alg,
- uint8_t *digest,
- uint32_t digest_size)
+vb2_error_t vb2_digest_buffer(const uint8_t *buf, uint32_t size,
+ enum vb2_hash_algorithm hash_alg, uint8_t *digest,
+ uint32_t digest_size)
{
memcpy(digest, mock_digest, sizeof(mock_digest));
return VB2_SUCCESS;
diff --git a/tests/verify_kernel.c b/tests/verify_kernel.c
index 269fe733..4f6f2bb3 100644
--- a/tests/verify_kernel.c
+++ b/tests/verify_kernel.c
@@ -27,7 +27,7 @@ static VbSharedDataHeader *shared = (VbSharedDataHeader *)shared_data;
static LoadKernelParams params;
vb2_error_t VbExDiskRead(VbExDiskHandle_t handle, uint64_t lba_start,
- uint64_t lba_count, void *buffer)
+ uint64_t lba_count, void *buffer)
{
if (handle != (VbExDiskHandle_t)1)
return VBERROR_UNKNOWN;
@@ -41,7 +41,7 @@ vb2_error_t VbExDiskRead(VbExDiskHandle_t handle, uint64_t lba_start,
}
vb2_error_t VbExDiskWrite(VbExDiskHandle_t handle, uint64_t lba_start,
- uint64_t lba_count, const void *buffer)
+ uint64_t lba_count, const void *buffer)
{
if (handle != (VbExDiskHandle_t)1)
return VBERROR_UNKNOWN;
@@ -64,7 +64,7 @@ int main(int argc, char *argv[])
{
struct vb2_packed_key *kernkey;
uint64_t disk_bytes = 0;
- int rv;
+ vb2_error_t rv;
if (argc < 3) {
print_help(argv[0]);