diff options
author | Joel Kitching <kitching@google.com> | 2019-07-31 14:12:30 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-08-13 04:36:52 +0000 |
commit | e6700f4c70fe72850ae4f3f5df19c9281ebcefc8 (patch) | |
tree | 0f2abff7be99bc140e288058fb2eeab6f8bb8b64 /firmware/lib20 | |
parent | a5afd01feb0b4b45adbcd8ab38ab8a2ef2a2ef67 (diff) | |
download | vboot-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>
Diffstat (limited to 'firmware/lib20')
-rw-r--r-- | firmware/lib20/api.c | 16 | ||||
-rw-r--r-- | firmware/lib20/api_kernel.c | 24 | ||||
-rw-r--r-- | firmware/lib20/common.c | 35 | ||||
-rw-r--r-- | firmware/lib20/include/vb2_common.h | 65 | ||||
-rw-r--r-- | firmware/lib20/kernel.c | 24 | ||||
-rw-r--r-- | firmware/lib20/misc.c | 8 | ||||
-rw-r--r-- | firmware/lib20/packed_key.c | 11 |
7 files changed, 87 insertions, 96 deletions
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; |