diff options
author | Randall Spangler <rspangler@chromium.org> | 2016-10-18 15:09:21 -0700 |
---|---|---|
committer | Randall Spangler <rspangler@chromium.org> | 2016-11-06 02:34:03 +0000 |
commit | 6e3931d1f609fc23b3ca8c7f6e563926e4f38b69 (patch) | |
tree | a026366a822ad7300b2b76a14c8e5df77305e564 | |
parent | 559a110f33b7ebe8d950f1c2de6b3b89791f862b (diff) | |
download | vboot-6e3931d1f609fc23b3ca8c7f6e563926e4f38b69.tar.gz |
vboot: Add vb2_unpack_key_buffer
Previously, vb2_unpack_key() actually unpacked a key buffer. Callers
that had a vb2_packed_key had to typecast it back to a uint8_t buffer to
unpack it. Rename vb2_unpack_key() to vb2_unpack_key_buffer(), and make
vb2_unpack_key() unpack a vb2_packed_key.
BUG=chromium:611535
BRANCH=none
TEST=make runtests; emerge-kevin coreboot depthcharge;
emerge-samus and boot it
Change-Id: I9ee38a819c59cc58a72ead78cf5ddf3d0f301ae7
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/400906
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r-- | firmware/2lib/include/2return_codes.h | 15 | ||||
-rw-r--r-- | firmware/lib/vboot_api_kernel.c | 13 | ||||
-rw-r--r-- | firmware/lib/vboot_kernel.c | 12 | ||||
-rw-r--r-- | firmware/lib20/api.c | 4 | ||||
-rw-r--r-- | firmware/lib20/api_kernel.c | 2 | ||||
-rw-r--r-- | firmware/lib20/include/vb2_common.h | 20 | ||||
-rw-r--r-- | firmware/lib20/kernel.c | 4 | ||||
-rw-r--r-- | firmware/lib20/misc.c | 4 | ||||
-rw-r--r-- | firmware/lib20/packed_key.c | 18 | ||||
-rw-r--r-- | futility/cmd_show.c | 17 | ||||
-rw-r--r-- | futility/cmd_vbutil_firmware.c | 6 | ||||
-rw-r--r-- | futility/cmd_vbutil_keyblock.c | 4 | ||||
-rw-r--r-- | futility/vb1_helper.c | 14 | ||||
-rw-r--r-- | host/lib/host_key.c | 4 | ||||
-rw-r--r-- | tests/vb20_api_kernel_tests.c | 2 | ||||
-rw-r--r-- | tests/vb20_api_tests.c | 2 | ||||
-rw-r--r-- | tests/vb20_common2_tests.c | 35 | ||||
-rw-r--r-- | tests/vb20_common3_tests.c | 8 | ||||
-rw-r--r-- | tests/vb20_kernel_tests.c | 2 | ||||
-rw-r--r-- | tests/vb20_misc_tests.c | 2 | ||||
-rw-r--r-- | tests/vb20_rsa_padding_tests.c | 4 | ||||
-rw-r--r-- | tests/vboot_api_kernel5_tests.c | 2 | ||||
-rw-r--r-- | tests/vboot_kernel_tests.c | 2 | ||||
-rw-r--r-- | utility/verify_data.c | 3 |
24 files changed, 101 insertions, 98 deletions
diff --git a/firmware/2lib/include/2return_codes.h b/firmware/2lib/include/2return_codes.h index 27b80d16..d03b0739 100644 --- a/firmware/2lib/include/2return_codes.h +++ b/firmware/2lib/include/2return_codes.h @@ -161,16 +161,16 @@ enum vb2_return_code { /* Member data outside parent in vb2_verify_member_inside() */ VB2_ERROR_INSIDE_DATA_OUTSIDE, - /* Unsupported signature algorithm in vb2_unpack_key() */ + /* Unsupported signature algorithm in vb2_unpack_key_buffer() */ VB2_ERROR_UNPACK_KEY_SIG_ALGORITHM, /* 0x150008 */ - /* Bad key size in vb2_unpack_key() */ + /* Bad key size in vb2_unpack_key_buffer() */ VB2_ERROR_UNPACK_KEY_SIZE, - /* Bad key alignment in vb2_unpack_key() */ + /* Bad key alignment in vb2_unpack_key_buffer() */ VB2_ERROR_UNPACK_KEY_ALIGN, - /* Bad key array size in vb2_unpack_key() */ + /* Bad key array size in vb2_unpack_key_buffer() */ VB2_ERROR_UNPACK_KEY_ARRAY_SIZE, /* Bad algorithm in vb2_verify_data() */ @@ -194,7 +194,7 @@ enum vb2_return_code { */ VB2_ERROR_VDATA_DIGEST_SIZE, - /* Unsupported hash algorithm in vb2_unpack_key() */ + /* Unsupported hash algorithm in vb2_unpack_key_buffer() */ VB2_ERROR_UNPACK_KEY_HASH_ALGORITHM, /* Member data overlaps member header */ @@ -256,9 +256,12 @@ enum vb2_return_code { /* Key algorithm doesn't match signature algorithm */ VB2_ERROR_VDATA_ALGORITHM_MISMATCH, - /* Bad magic number in vb2_unpack_key() */ + /* Bad magic number in vb2_unpack_key_buffer() */ VB2_ERROR_UNPACK_KEY_MAGIC, + /* Null public key buffer passed to vb2_unpack_key_buffer() */ + VB2_ERROR_UNPACK_KEY_BUFFER, + /********************************************************************** * Keyblock verification errors (all in vb2_verify_keyblock()) */ diff --git a/firmware/lib/vboot_api_kernel.c b/firmware/lib/vboot_api_kernel.c index f264fb7f..549df24f 100644 --- a/firmware/lib/vboot_api_kernel.c +++ b/firmware/lib/vboot_api_kernel.c @@ -1417,10 +1417,9 @@ VbError_t VbVerifyMemoryBootImage(VbCommonParams *cparams, } else { /* Unpack kernel subkey */ struct vb2_public_key kernel_subkey2; - if (VB2_SUCCESS != vb2_unpack_key(&kernel_subkey2, - (const uint8_t *)kernel_subkey, - kernel_subkey->key_offset + - kernel_subkey->key_size)) { + if (VB2_SUCCESS != + vb2_unpack_key(&kernel_subkey2, + (struct vb2_packed_key *)kernel_subkey)) { VBDEBUG(("Unable to unpack kernel subkey\n")); goto fail; } @@ -1450,11 +1449,7 @@ VbError_t VbVerifyMemoryBootImage(VbCommonParams *cparams, /* Get key for preamble/data verification from the key block. */ struct vb2_public_key data_key2; - if (VB2_SUCCESS != - vb2_unpack_key(&data_key2, - (const uint8_t *)&keyblock2->data_key, - keyblock2->data_key.key_offset + - keyblock2->data_key.key_size)) { + if (VB2_SUCCESS != vb2_unpack_key(&data_key2, &keyblock2->data_key)) { VBDEBUG(("Unable to unpack kernel data key\n")); goto fail; } diff --git a/firmware/lib/vboot_kernel.c b/firmware/lib/vboot_kernel.c index 65792e92..e599dd2c 100644 --- a/firmware/lib/vboot_kernel.c +++ b/firmware/lib/vboot_kernel.c @@ -159,10 +159,9 @@ VbError_t LoadKernel(LoadKernelParams *params, VbCommonParams *cparams) /* Unpack kernel subkey */ struct vb2_public_key kernel_subkey2; - if (VB2_SUCCESS != vb2_unpack_key(&kernel_subkey2, - (const uint8_t *)kernel_subkey, - kernel_subkey->key_offset + - kernel_subkey->key_size)) { + if (VB2_SUCCESS != + vb2_unpack_key(&kernel_subkey2, + (struct vb2_packed_key *)kernel_subkey)) { VBDEBUG(("Unable to unpack kernel subkey\n")); goto bad_gpt; } @@ -334,10 +333,7 @@ VbError_t LoadKernel(LoadKernelParams *params, VbCommonParams *cparams) /* Get key for preamble/data verification from the key block. */ struct vb2_public_key data_key2; if (VB2_SUCCESS != - vb2_unpack_key(&data_key2, - (const uint8_t *)&keyblock2->data_key, - keyblock2->data_key.key_offset + - keyblock2->data_key.key_size)) { + vb2_unpack_key(&data_key2, &keyblock2->data_key)) { VBDEBUG(("Unable to unpack kernel data key\n")); shpart->check_result = VBSD_LKP_CHECK_DATA_KEY_PARSE; goto bad_kernel; diff --git a/firmware/lib20/api.c b/firmware/lib20/api.c index 7c253457..327a25c9 100644 --- a/firmware/lib20/api.c +++ b/firmware/lib20/api.c @@ -96,7 +96,7 @@ int vb2api_init_hash(struct vb2_context *ctx, uint32_t tag, uint32_t *size) if (!sd->workbuf_data_key_size) return VB2_ERROR_API_INIT_HASH_DATA_KEY; - rv = vb2_unpack_key(&key, + rv = vb2_unpack_key_buffer(&key, ctx->workbuf + sd->workbuf_data_key_offset, sd->workbuf_data_key_size); if (rv) @@ -186,7 +186,7 @@ int vb2api_check_hash_get_digest(struct vb2_context *ctx, void *digest_out, if (!sd->workbuf_data_key_size) return VB2_ERROR_API_CHECK_HASH_DATA_KEY; - rv = vb2_unpack_key(&key, + rv = vb2_unpack_key_buffer(&key, ctx->workbuf + sd->workbuf_data_key_offset, sd->workbuf_data_key_size); if (rv) diff --git a/firmware/lib20/api_kernel.c b/firmware/lib20/api_kernel.c index 0c8b598b..ee5c41a9 100644 --- a/firmware/lib20/api_kernel.c +++ b/firmware/lib20/api_kernel.c @@ -213,7 +213,7 @@ int vb2api_verify_kernel_data(struct vb2_context *ctx, if (!sd->workbuf_data_key_size) return VB2_ERROR_API_VERIFY_KDATA_KEY; - rv = vb2_unpack_key(&key, + rv = vb2_unpack_key_buffer(&key, ctx->workbuf + sd->workbuf_data_key_offset, sd->workbuf_data_key_size); if (rv) diff --git a/firmware/lib20/include/vb2_common.h b/firmware/lib20/include/vb2_common.h index 536fbbb0..96deb51a 100644 --- a/firmware/lib20/include/vb2_common.h +++ b/firmware/lib20/include/vb2_common.h @@ -78,7 +78,7 @@ int vb2_verify_packed_key_inside(const void *parent, const struct vb2_packed_key *key); /** - * Unpack a vboot1-format key for use in verification + * Unpack a vboot1-format key buffer for use in verification * * The elements of the unpacked key will point into the source buffer, so don't * free the source buffer until you're done with the key. @@ -88,9 +88,23 @@ int vb2_verify_packed_key_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); + +/** + * Unpack a vboot1-format key for use in verification + * + * The elements of the unpacked key will point into the source packed key, so + * don't free the source until you're done with the public key. + * + * @param key Destintion for unpacked key + * @param packed_key Source packed 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 uint8_t *buf, - uint32_t size); + const struct vb2_packed_key *packed_key); /** * Verify a signature against an expected hash digest. diff --git a/firmware/lib20/kernel.c b/firmware/lib20/kernel.c index 809e1b66..f5632e58 100644 --- a/firmware/lib20/kernel.c +++ b/firmware/lib20/kernel.c @@ -122,7 +122,7 @@ int vb2_load_kernel_keyblock(struct vb2_context *ctx) /* Unpack the kernel key */ key_data = ctx->workbuf + sd->workbuf_kernel_key_offset; key_size = sd->workbuf_kernel_key_size; - rv = vb2_unpack_key(&kernel_key, key_data, key_size); + rv = vb2_unpack_key_buffer(&kernel_key, key_data, key_size); if (rv) return rv; @@ -374,7 +374,7 @@ int vb2_load_kernel_preamble(struct vb2_context *ctx) if (!sd->workbuf_data_key_size) return VB2_ERROR_KERNEL_PREAMBLE2_DATA_KEY; - rv = vb2_unpack_key(&data_key, key_data, key_size); + rv = vb2_unpack_key_buffer(&data_key, key_data, key_size); if (rv) return rv; diff --git a/firmware/lib20/misc.c b/firmware/lib20/misc.c index dee6b139..cbe894c9 100644 --- a/firmware/lib20/misc.c +++ b/firmware/lib20/misc.c @@ -94,7 +94,7 @@ int vb2_load_fw_keyblock(struct vb2_context *ctx) return rv; /* Unpack the root key */ - rv = vb2_unpack_key(&root_key, key_data, key_size); + rv = vb2_unpack_key_buffer(&root_key, key_data, key_size); if (rv) return rv; @@ -212,7 +212,7 @@ int vb2_load_fw_preamble(struct vb2_context *ctx) if (!sd->workbuf_data_key_size) return VB2_ERROR_FW_PREAMBLE2_DATA_KEY; - rv = vb2_unpack_key(&data_key, key_data, key_size); + rv = vb2_unpack_key_buffer(&data_key, key_data, key_size); if (rv) return rv; diff --git a/firmware/lib20/packed_key.c b/firmware/lib20/packed_key.c index 4baf97ce..48f11116 100644 --- a/firmware/lib20/packed_key.c +++ b/firmware/lib20/packed_key.c @@ -23,9 +23,9 @@ int vb2_verify_packed_key_inside(const void *parent, key->key_offset, key->key_size); } -int vb2_unpack_key(struct vb2_public_key *key, - const uint8_t *buf, - uint32_t size) +int 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; @@ -75,3 +75,15 @@ int vb2_unpack_key(struct vb2_public_key *key, return VB2_SUCCESS; } + +int vb2_unpack_key(struct vb2_public_key *key, + const struct vb2_packed_key *packed_key) +{ + if (!packed_key) + return VB2_ERROR_UNPACK_KEY_BUFFER; + + return vb2_unpack_key_buffer(key, + (const uint8_t *)packed_key, + packed_key->key_offset + + packed_key->key_size); +} diff --git a/futility/cmd_show.c b/futility/cmd_show.c index 91c24d0b..bfe668cc 100644 --- a/futility/cmd_show.c +++ b/futility/cmd_show.c @@ -177,8 +177,9 @@ int ft_show_fw_preamble(const char *name, uint8_t *buf, uint32_t len, if (state) { if (!sign_key && state->rootkey.is_valid && - VB2_SUCCESS == vb2_unpack_key(&root_key, state->rootkey.buf, - state->rootkey.len)) { + VB2_SUCCESS == vb2_unpack_key_buffer(&root_key, + state->rootkey.buf, + state->rootkey.len)) { /* BIOS should have a rootkey in the GBB */ sign_key = &root_key; } @@ -201,10 +202,7 @@ int ft_show_fw_preamble(const char *name, uint8_t *buf, uint32_t len, retval = 1; struct vb2_public_key data_key; - if (VB2_SUCCESS != - vb2_unpack_key(&data_key, (const uint8_t *)&keyblock->data_key, - keyblock->data_key.key_offset + - keyblock->data_key.key_size)) { + if (VB2_SUCCESS != vb2_unpack_key(&data_key, &keyblock->data_key)) { fprintf(stderr, "Error parsing data key in %s\n", name); return 1; } @@ -308,10 +306,7 @@ int ft_show_kernel_preamble(const char *name, uint8_t *buf, uint32_t len, retval = 1; struct vb2_public_key data_key; - if (VB2_SUCCESS != - vb2_unpack_key(&data_key, (const uint8_t *)&keyblock->data_key, - keyblock->data_key.key_offset + - keyblock->data_key.key_size)) { + if (VB2_SUCCESS != vb2_unpack_key(&data_key, &keyblock->data_key)) { fprintf(stderr, "Error parsing data key in %s\n", name); return 1; } @@ -510,7 +505,7 @@ static int do_show(int argc, char *argv[]) } if (VB2_SUCCESS != - vb2_unpack_key(&pubk2, pubkbuf, len)) { + vb2_unpack_key_buffer(&pubk2, pubkbuf, len)) { fprintf(stderr, "Error unpacking %s\n", optarg); errorcnt++; break; diff --git a/futility/cmd_vbutil_firmware.c b/futility/cmd_vbutil_firmware.c index 3bf3492b..ef1148ed 100644 --- a/futility/cmd_vbutil_firmware.c +++ b/futility/cmd_vbutil_firmware.c @@ -211,7 +211,7 @@ static int do_verify(const char *infile, const char *signpubkey, fprintf(stderr, "Error reading signpubkey.\n"); goto verify_cleanup; } - if (VB2_SUCCESS != vb2_unpack_key(&sign_key, pubkbuf, pubklen)) { + if (VB2_SUCCESS != vb2_unpack_key_buffer(&sign_key, pubkbuf, pubklen)) { fprintf(stderr, "Error unpacking signpubkey.\n"); goto verify_cleanup; } @@ -254,9 +254,7 @@ static int do_verify(const char *infile, const char *signpubkey, struct vb2_public_key data_key; if (VB2_SUCCESS != - vb2_unpack_key(&data_key, (const uint8_t *)&keyblock->data_key, - keyblock->data_key.key_offset + - keyblock->data_key.key_size)) { + vb2_unpack_key(&data_key, &keyblock->data_key)) { fprintf(stderr, "Error parsing data key.\n"); goto verify_cleanup; } diff --git a/futility/cmd_vbutil_keyblock.c b/futility/cmd_vbutil_keyblock.c index bb8d62ac..f79b8ea8 100644 --- a/futility/cmd_vbutil_keyblock.c +++ b/futility/cmd_vbutil_keyblock.c @@ -189,9 +189,7 @@ static int Unpack(const char *infile, const char *datapubkey, return 1; } struct vb2_public_key key; - if (VB2_SUCCESS != - vb2_unpack_key(&key, (uint8_t *)sign_key, - sign_key->key_offset + sign_key->key_size)) { + if (VB2_SUCCESS != vb2_unpack_key(&key, sign_key)) { fprintf(stderr, "vbutil_keyblock: Error reading signpubkey.\n"); return 1; diff --git a/futility/vb1_helper.c b/futility/vb1_helper.c index 83acba59..fb9022f0 100644 --- a/futility/vb1_helper.c +++ b/futility/vb1_helper.c @@ -501,11 +501,7 @@ int VerifyKernelBlob(uint8_t *kernel_blob, if (signpub_key) { struct vb2_public_key pubkey; - if (VB2_SUCCESS != - vb2_unpack_key(&pubkey, - (uint8_t *)signpub_key, - signpub_key->key_offset + - signpub_key->key_size)) { + if (VB2_SUCCESS != vb2_unpack_key(&pubkey, signpub_key)) { fprintf(stderr, "Error unpacking signing key.\n"); goto done; } @@ -568,9 +564,7 @@ int VerifyKernelBlob(uint8_t *kernel_blob, } struct vb2_public_key pubkey; - if (VB2_SUCCESS != - vb2_unpack_key(&pubkey, (uint8_t *)data_key, - data_key->key_offset + data_key->key_size)) { + if (VB2_SUCCESS != vb2_unpack_key(&pubkey, data_key)) { fprintf(stderr, "Error parsing data key.\n"); goto done; } @@ -743,9 +737,7 @@ enum futil_file_type ft_recognize_vblock1(uint8_t *buf, uint32_t len) /* Try unpacking the data key from the keyblock */ struct vb2_public_key data_key; if (VB2_SUCCESS != - vb2_unpack_key(&data_key, (const uint8_t *)&keyblock->data_key, - keyblock->data_key.key_offset + - keyblock->data_key.key_size)) { + vb2_unpack_key(&data_key, &keyblock->data_key)) { /* It looks like a bad keyblock, but still a keyblock */ free(buf2); return FILE_TYPE_KEYBLOCK; diff --git a/host/lib/host_key.c b/host/lib/host_key.c index 10efc766..499fe2d0 100644 --- a/host/lib/host_key.c +++ b/host/lib/host_key.c @@ -25,7 +25,9 @@ int packed_key_looks_ok(const struct vb2_packed_key *key, uint32_t size) { struct vb2_public_key pubkey; - if (VB2_SUCCESS != vb2_unpack_key(&pubkey, (const uint8_t *)key, size)) + if (VB2_SUCCESS != vb2_unpack_key_buffer(&pubkey, + (const uint8_t *)key, + size)) return 0; if (key->key_version > VB2_MAX_KEY_VERSION) { diff --git a/tests/vb20_api_kernel_tests.c b/tests/vb20_api_kernel_tests.c index 0c8cb59a..212ad931 100644 --- a/tests/vb20_api_kernel_tests.c +++ b/tests/vb20_api_kernel_tests.c @@ -194,7 +194,7 @@ int vb2_load_kernel_preamble(struct vb2_context *ctx) return mock_load_kernel_preamble_retval; } -int vb2_unpack_key(struct vb2_public_key *key, +int vb2_unpack_key_buffer(struct vb2_public_key *key, const uint8_t *buf, uint32_t size) { diff --git a/tests/vb20_api_tests.c b/tests/vb20_api_tests.c index f0bc98bf..a7efca9b 100644 --- a/tests/vb20_api_tests.c +++ b/tests/vb20_api_tests.c @@ -117,7 +117,7 @@ int vb2_load_fw_preamble(struct vb2_context *ctx) return retval_vb2_load_fw_preamble; } -int vb2_unpack_key(struct vb2_public_key *key, +int vb2_unpack_key_buffer(struct vb2_public_key *key, const uint8_t *buf, uint32_t size) { diff --git a/tests/vb20_common2_tests.c b/tests/vb20_common2_tests.c index 00861e58..61e28d1a 100644 --- a/tests/vb20_common2_tests.c +++ b/tests/vb20_common2_tests.c @@ -35,44 +35,49 @@ static void test_unpack_key(const struct vb2_packed_key *key1) struct vb2_packed_key *key = (struct vb2_packed_key *)buf; memcpy(key, key1, size); - TEST_SUCC(vb2_unpack_key(&pubk, buf, size), "vb2_unpack_key() ok"); + TEST_SUCC(vb2_unpack_key_buffer(&pubk, buf, size), + "vb2_unpack_key_buffer() ok"); TEST_EQ(pubk.sig_alg, vb2_crypto_to_signature(key->algorithm), - "vb2_unpack_key() sig_alg"); + "vb2_unpack_key_buffer() sig_alg"); TEST_EQ(pubk.hash_alg, vb2_crypto_to_hash(key->algorithm), - "vb2_unpack_key() hash_alg"); + "vb2_unpack_key_buffer() hash_alg"); memcpy(key, key1, size); key->algorithm = VB2_ALG_COUNT; - TEST_EQ(vb2_unpack_key(&pubk, buf, size), + TEST_EQ(vb2_unpack_key_buffer(&pubk, buf, size), VB2_ERROR_UNPACK_KEY_SIG_ALGORITHM, - "vb2_unpack_key() invalid algorithm"); + "vb2_unpack_key_buffer() invalid algorithm"); memcpy(key, key1, size); key->key_size--; - TEST_EQ(vb2_unpack_key(&pubk, buf, size), + TEST_EQ(vb2_unpack_key_buffer(&pubk, buf, size), VB2_ERROR_UNPACK_KEY_SIZE, - "vb2_unpack_key() invalid size"); + "vb2_unpack_key_buffer() invalid size"); memcpy(key, key1, size); key->key_offset++; - TEST_EQ(vb2_unpack_key(&pubk, buf, size + 1), + TEST_EQ(vb2_unpack_key_buffer(&pubk, buf, size + 1), VB2_ERROR_UNPACK_KEY_ALIGN, - "vb2_unpack_key() unaligned data"); + "vb2_unpack_key_buffer() unaligned data"); memcpy(key, key1, size); *(uint32_t *)(buf + key->key_offset) /= 2; - TEST_EQ(vb2_unpack_key(&pubk, buf, size), + TEST_EQ(vb2_unpack_key_buffer(&pubk, buf, size), VB2_ERROR_UNPACK_KEY_ARRAY_SIZE, - "vb2_unpack_key() invalid key array size"); + "vb2_unpack_key_buffer() invalid key array size"); memcpy(key, key1, size); - TEST_EQ(vb2_unpack_key(&pubk, buf, size - 1), + TEST_EQ(vb2_unpack_key_buffer(&pubk, buf, size - 1), VB2_ERROR_INSIDE_DATA_OUTSIDE, - "vb2_unpack_key() buffer too small"); + "vb2_unpack_key_buffer() buffer too small"); free(key); + + TEST_EQ(vb2_unpack_key(&pubk, NULL), + VB2_ERROR_UNPACK_KEY_BUFFER, + "vb2_unpack_key_() buffer NULL"); } static void test_verify_data(const struct vb2_packed_key *key1, @@ -82,7 +87,6 @@ static void test_verify_data(const struct vb2_packed_key *key1, __attribute__ ((aligned (VB2_WORKBUF_ALIGN))); struct vb2_workbuf wb; - uint32_t pubkey_size = key1->key_offset + key1->key_size; struct vb2_public_key pubk, pubk_orig; uint32_t sig_total_size = sig->sig_offset + sig->sig_size; struct vb2_signature *sig2; @@ -92,8 +96,7 @@ static void test_verify_data(const struct vb2_packed_key *key1, /* Allocate signature copy for tests */ sig2 = (struct vb2_signature *)malloc(sig_total_size); - TEST_EQ(vb2_unpack_key(&pubk, (uint8_t *)key1, pubkey_size), - 0, "vb2_verify_data() unpack key"); + TEST_SUCC(vb2_unpack_key(&pubk, key1), "vb2_verify_data() unpack key"); pubk_orig = pubk; memcpy(sig2, sig, sig_total_size); diff --git a/tests/vb20_common3_tests.c b/tests/vb20_common3_tests.c index e5538673..b5ad1ebe 100644 --- a/tests/vb20_common3_tests.c +++ b/tests/vb20_common3_tests.c @@ -216,8 +216,7 @@ static void test_verify_fw_preamble(struct vb2_packed_key *public_key, /* Create a dummy signature */ struct vb2_signature *body_sig = vb2_alloc_signature(56, 78); - TEST_SUCC(vb2_unpack_key(&rsa, (uint8_t *)public_key, - public_key->key_offset + public_key->key_size), + TEST_SUCC(vb2_unpack_key(&rsa, public_key), "vb2_verify_fw_preamble() prereq key"); hdr = vb2_create_fw_preamble(0x1234, kernel_subkey, body_sig, @@ -359,8 +358,7 @@ static void test_verify_kernel_preamble( /* Create a dummy signature */ struct vb2_signature *body_sig = vb2_alloc_signature(56, 0x214000); - TEST_SUCC(vb2_unpack_key(&rsa, (uint8_t *)public_key, - public_key->key_offset + public_key->key_size), + TEST_SUCC(vb2_unpack_key(&rsa, public_key), "vb2_verify_kernel_preamble() prereq key"); struct vb2_kernel_preamble *hdr = @@ -563,7 +561,7 @@ int test_permutation(int signing_key_algorithm, int data_key_algorithm, /* Unpack public key */ struct vb2_public_key signing_public_key2; if (VB2_SUCCESS != - vb2_unpack_key(&signing_public_key2, + vb2_unpack_key_buffer(&signing_public_key2, (uint8_t *)signing_public_key, signing_public_key->key_offset + signing_public_key->key_size)) { diff --git a/tests/vb20_kernel_tests.c b/tests/vb20_kernel_tests.c index 2304b321..2823050e 100644 --- a/tests/vb20_kernel_tests.c +++ b/tests/vb20_kernel_tests.c @@ -167,7 +167,7 @@ int vb2ex_read_resource(struct vb2_context *ctx, return VB2_SUCCESS; } -int vb2_unpack_key(struct vb2_public_key *key, +int vb2_unpack_key_buffer(struct vb2_public_key *key, const uint8_t *buf, uint32_t size) { diff --git a/tests/vb20_misc_tests.c b/tests/vb20_misc_tests.c index e3a5123f..2156e919 100644 --- a/tests/vb20_misc_tests.c +++ b/tests/vb20_misc_tests.c @@ -146,7 +146,7 @@ int vb2ex_read_resource(struct vb2_context *ctx, return VB2_SUCCESS; } -int vb2_unpack_key(struct vb2_public_key *key, +int vb2_unpack_key_buffer(struct vb2_public_key *key, const uint8_t *buf, uint32_t size) { diff --git a/tests/vb20_rsa_padding_tests.c b/tests/vb20_rsa_padding_tests.c index dbfdc38f..7c1df6a5 100644 --- a/tests/vb20_rsa_padding_tests.c +++ b/tests/vb20_rsa_padding_tests.c @@ -114,9 +114,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Couldn't read RSA public key for the test.\n"); return 1; } - - if (VB2_SUCCESS != vb2_unpack_key(&k2, (const uint8_t *)pk, - pk->key_offset + pk->key_size)) { + if (VB2_SUCCESS != vb2_unpack_key(&k2, pk)) { fprintf(stderr, "Couldn't unpack RSA public key.\n"); free(pk); return 1; diff --git a/tests/vboot_api_kernel5_tests.c b/tests/vboot_api_kernel5_tests.c index 8633f7e7..077c07a4 100644 --- a/tests/vboot_api_kernel5_tests.c +++ b/tests/vboot_api_kernel5_tests.c @@ -96,7 +96,7 @@ static void copy_kbh(void) } /* Mocks */ -int vb2_unpack_key(struct vb2_public_key *key, +int vb2_unpack_key_buffer(struct vb2_public_key *key, const uint8_t *buf, uint32_t size) { diff --git a/tests/vboot_kernel_tests.c b/tests/vboot_kernel_tests.c index 057e2dd3..21ee895b 100644 --- a/tests/vboot_kernel_tests.c +++ b/tests/vboot_kernel_tests.c @@ -243,7 +243,7 @@ void GetCurrentKernelUniqueGuid(GptData *gpt, void *dest) memcpy(dest, fake_guid, sizeof(fake_guid)); } -int vb2_unpack_key(struct vb2_public_key *key, +int vb2_unpack_key_buffer(struct vb2_public_key *key, const uint8_t *buf, uint32_t size) { diff --git a/utility/verify_data.c b/utility/verify_data.c index a3ab277a..50eeb9d2 100644 --- a/utility/verify_data.c +++ b/utility/verify_data.c @@ -97,8 +97,7 @@ int main(int argc, char* argv[]) } struct vb2_public_key k2; - if (VB2_SUCCESS != vb2_unpack_key(&k2, (const uint8_t *)pk, - pk->key_offset + pk->key_size)) { + if (VB2_SUCCESS != vb2_unpack_key(&k2, pk)) { fprintf(stderr, "Can't unpack RSA public key.\n"); goto error; } |