summaryrefslogtreecommitdiff
path: root/tests/vb21_common_tests.c
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2016-05-25 16:42:44 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-07-26 17:31:54 -0700
commitca7251286655fe8865d0089bfc23b42ffececbf3 (patch)
tree438e449305363449da687cf635cd35decba023e9 /tests/vb21_common_tests.c
parent2afa87360d3a4c357e4bb2d37fdff9cdefbe0ffc (diff)
downloadvboot-ca7251286655fe8865d0089bfc23b42ffececbf3.tar.gz
vboot: Disambiguate vb2.1 structs and functions
Futility needs to link against both vboot1/vboot2.0 and vboot2.1 functions. This was easy in the past because it did (vboot1 + vboot2.1) and there's no overlap. In replacing vboot1 function calls and structs with vboot2.0, now there are symbol collisions between vboot2.0 and vboot2.1. For example, both of them use a struct called vb2_signature, but the structs are defined differently. Functions which operate on those structs also overload. Rename the vb2.1 structs to start with vb21_ instead of vb2_. Do the same for vb2.1 functions which operate on vb2.1 data. BUG=chromium:611535 BRANCH=none TEST=make runtests Change-Id: I24defd87cbd9ef64239faf1a8e98ab2372d27539 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/347458 Reviewed-by: Daisuke Nojiri <dnojiri@google.com>
Diffstat (limited to 'tests/vb21_common_tests.c')
-rw-r--r--tests/vb21_common_tests.c292
1 files changed, 147 insertions, 145 deletions
diff --git a/tests/vb21_common_tests.c b/tests/vb21_common_tests.c
index eb943bc1..a971fd20 100644
--- a/tests/vb21_common_tests.c
+++ b/tests/vb21_common_tests.c
@@ -8,7 +8,7 @@
#include "2sysincludes.h"
#include "2common.h"
#include "2rsa.h"
-#include "vb2_common.h"
+#include "vb21_common.h"
#include "host_fw_preamble2.h"
#include "host_key2.h"
#include "host_keyblock2.h"
@@ -30,21 +30,21 @@ static void test_struct_packing(void)
TEST_EQ(EXPECTED_ID_SIZE,
sizeof(struct vb2_id),
"sizeof(vb2_id)");
- TEST_EQ(EXPECTED_VB2_STRUCT_COMMON_SIZE,
- sizeof(struct vb2_struct_common),
- "sizeof(vb2_struct_common)");
- TEST_EQ(EXPECTED_VB2_PACKED_KEY_SIZE,
- sizeof(struct vb2_packed_key),
- "sizeof(vb2_packed_key)");
- TEST_EQ(EXPECTED_VB2_SIGNATURE_SIZE,
- sizeof(struct vb2_signature),
- "sizeof(vb2_signature)");
- TEST_EQ(EXPECTED_VB2_KEYBLOCK_SIZE,
- sizeof(struct vb2_keyblock),
- "sizeof(vb2_keyblock)");
- TEST_EQ(EXPECTED_VB2_FW_PREAMBLE_SIZE,
- sizeof(struct vb2_fw_preamble),
- "sizeof(vb2_fw_preamble)");
+ TEST_EQ(EXPECTED_VB21_STRUCT_COMMON_SIZE,
+ sizeof(struct vb21_struct_common),
+ "sizeof(vb21_struct_common)");
+ TEST_EQ(EXPECTED_VB21_PACKED_KEY_SIZE,
+ sizeof(struct vb21_packed_key),
+ "sizeof(vb21_packed_key)");
+ TEST_EQ(EXPECTED_VB21_SIGNATURE_SIZE,
+ sizeof(struct vb21_signature),
+ "sizeof(vb21_signature)");
+ TEST_EQ(EXPECTED_VB21_KEYBLOCK_SIZE,
+ sizeof(struct vb21_keyblock),
+ "sizeof(vb21_keyblock)");
+ TEST_EQ(EXPECTED_VB21_FW_PREAMBLE_SIZE,
+ sizeof(struct vb21_fw_preamble),
+ "sizeof(vb21_fw_preamble)");
}
/**
@@ -52,10 +52,10 @@ static void test_struct_packing(void)
*/
static void test_common_header_functions(void)
{
- uint8_t cbuf[sizeof(struct vb2_struct_common) + 128];
+ uint8_t cbuf[sizeof(struct vb21_struct_common) + 128];
uint8_t cbufgood[sizeof(cbuf)];
- struct vb2_struct_common *c = (struct vb2_struct_common *)cbuf;
- struct vb2_struct_common *c2;
+ struct vb21_struct_common *c = (struct vb21_struct_common *)cbuf;
+ struct vb21_struct_common *c2;
const char test_desc[32] = "test desc";
uint32_t desc_end, m;
@@ -65,125 +65,125 @@ static void test_common_header_functions(void)
memcpy(cbuf + c->fixed_size, test_desc, sizeof(test_desc));
desc_end = c->fixed_size + c->desc_size;
- c2 = (struct vb2_struct_common *)(cbuf + desc_end);
+ c2 = (struct vb21_struct_common *)(cbuf + desc_end);
c2->total_size = c->total_size - desc_end;
c2->fixed_size = sizeof(*c2);
c2->desc_size = 0;
/* Description helper */
- TEST_EQ(0, strcmp(vb2_common_desc(c), test_desc), "vb2_common_desc()");
- TEST_EQ(0, strcmp(vb2_common_desc(c2), ""), "vb2_common_desc() empty");
+ TEST_EQ(0, strcmp(vb21_common_desc(c), test_desc), "vb21_common_desc()");
+ TEST_EQ(0, strcmp(vb21_common_desc(c2), ""), "vb21_common_desc() empty");
- TEST_SUCC(vb2_verify_common_header(cbuf, sizeof(cbuf)),
- "vb2_verify_common_header() good");
+ TEST_SUCC(vb21_verify_common_header(cbuf, sizeof(cbuf)),
+ "vb21_verify_common_header() good");
memcpy(cbufgood, cbuf, sizeof(cbufgood));
memcpy(cbuf, cbufgood, sizeof(cbuf));
c->total_size += 4;
- TEST_EQ(vb2_verify_common_header(cbuf, sizeof(cbuf)),
+ TEST_EQ(vb21_verify_common_header(cbuf, sizeof(cbuf)),
VB2_ERROR_COMMON_TOTAL_SIZE,
- "vb2_verify_common_header() total size");
+ "vb21_verify_common_header() total size");
memcpy(cbuf, cbufgood, sizeof(cbuf));
c->fixed_size = c->total_size + 4;
- TEST_EQ(vb2_verify_common_header(cbuf, sizeof(cbuf)),
+ TEST_EQ(vb21_verify_common_header(cbuf, sizeof(cbuf)),
VB2_ERROR_COMMON_FIXED_SIZE,
- "vb2_verify_common_header() fixed size");
+ "vb21_verify_common_header() fixed size");
memcpy(cbuf, cbufgood, sizeof(cbuf));
c->desc_size = c->total_size - c->fixed_size + 4;
- TEST_EQ(vb2_verify_common_header(cbuf, sizeof(cbuf)),
+ TEST_EQ(vb21_verify_common_header(cbuf, sizeof(cbuf)),
VB2_ERROR_COMMON_DESC_SIZE,
- "vb2_verify_common_header() desc size");
+ "vb21_verify_common_header() desc size");
memcpy(cbuf, cbufgood, sizeof(cbuf));
c->total_size--;
- TEST_EQ(vb2_verify_common_header(cbuf, sizeof(cbuf)),
+ TEST_EQ(vb21_verify_common_header(cbuf, sizeof(cbuf)),
VB2_ERROR_COMMON_TOTAL_UNALIGNED,
- "vb2_verify_common_header() total unaligned");
+ "vb21_verify_common_header() total unaligned");
memcpy(cbuf, cbufgood, sizeof(cbuf));
c->fixed_size++;
- TEST_EQ(vb2_verify_common_header(cbuf, sizeof(cbuf)),
+ TEST_EQ(vb21_verify_common_header(cbuf, sizeof(cbuf)),
VB2_ERROR_COMMON_FIXED_UNALIGNED,
- "vb2_verify_common_header() fixed unaligned");
+ "vb21_verify_common_header() fixed unaligned");
memcpy(cbuf, cbufgood, sizeof(cbuf));
c->desc_size--;
- TEST_EQ(vb2_verify_common_header(cbuf, sizeof(cbuf)),
+ TEST_EQ(vb21_verify_common_header(cbuf, sizeof(cbuf)),
VB2_ERROR_COMMON_DESC_UNALIGNED,
- "vb2_verify_common_header() desc unaligned");
+ "vb21_verify_common_header() desc unaligned");
memcpy(cbuf, cbufgood, sizeof(cbuf));
c->desc_size = -4;
- TEST_EQ(vb2_verify_common_header(cbuf, sizeof(cbuf)),
+ TEST_EQ(vb21_verify_common_header(cbuf, sizeof(cbuf)),
VB2_ERROR_COMMON_DESC_WRAPS,
- "vb2_verify_common_header() desc wraps");
+ "vb21_verify_common_header() desc wraps");
memcpy(cbuf, cbufgood, sizeof(cbuf));
cbuf[desc_end - 1] = 1;
- TEST_EQ(vb2_verify_common_header(cbuf, sizeof(cbuf)),
+ TEST_EQ(vb21_verify_common_header(cbuf, sizeof(cbuf)),
VB2_ERROR_COMMON_DESC_TERMINATOR,
- "vb2_verify_common_header() desc not terminated");
+ "vb21_verify_common_header() desc not terminated");
/* Member checking function */
memcpy(cbuf, cbufgood, sizeof(cbuf));
m = 0;
- TEST_SUCC(vb2_verify_common_member(cbuf, &m, c->total_size - 8, 4),
- "vb2_verify_common_member()");
+ TEST_SUCC(vb21_verify_common_member(cbuf, &m, c->total_size - 8, 4),
+ "vb21_verify_common_member()");
TEST_EQ(m, c->total_size - 4, " new minimum");
m = desc_end;
- TEST_SUCC(vb2_verify_common_member(cbuf, &m, desc_end, 4),
- "vb2_verify_common_member() good offset");
+ TEST_SUCC(vb21_verify_common_member(cbuf, &m, desc_end, 4),
+ "vb21_verify_common_member() good offset");
TEST_EQ(m, desc_end + 4, " new minimum");
m = 0;
- TEST_EQ(vb2_verify_common_member(cbuf, &m, c->total_size - 8, -4),
+ TEST_EQ(vb21_verify_common_member(cbuf, &m, c->total_size - 8, -4),
VB2_ERROR_COMMON_MEMBER_WRAPS,
- "vb2_verify_common_member() wraps");
+ "vb21_verify_common_member() wraps");
m = 0;
- TEST_EQ(vb2_verify_common_member(cbuf, &m, c->total_size - 7, 4),
+ TEST_EQ(vb21_verify_common_member(cbuf, &m, c->total_size - 7, 4),
VB2_ERROR_COMMON_MEMBER_UNALIGNED,
- "vb2_verify_common_member() offset unaligned");
+ "vb21_verify_common_member() offset unaligned");
m = 0;
- TEST_EQ(vb2_verify_common_member(cbuf, &m, c->total_size - 8, 5),
+ TEST_EQ(vb21_verify_common_member(cbuf, &m, c->total_size - 8, 5),
VB2_ERROR_COMMON_MEMBER_UNALIGNED,
- "vb2_verify_common_member() size unaligned");
+ "vb21_verify_common_member() size unaligned");
m = 0;
- TEST_EQ(vb2_verify_common_member(cbuf, &m, desc_end - 4, 4),
+ TEST_EQ(vb21_verify_common_member(cbuf, &m, desc_end - 4, 4),
VB2_ERROR_COMMON_MEMBER_OVERLAP,
- "vb2_verify_common_member() overlap");
+ "vb21_verify_common_member() overlap");
m = desc_end + 4;
- TEST_EQ(vb2_verify_common_member(cbuf, &m, desc_end, 4),
+ TEST_EQ(vb21_verify_common_member(cbuf, &m, desc_end, 4),
VB2_ERROR_COMMON_MEMBER_OVERLAP,
- "vb2_verify_common_member() overlap 2");
+ "vb21_verify_common_member() overlap 2");
m = 0;
- TEST_EQ(vb2_verify_common_member(cbuf, &m, c->total_size - 4, 8),
+ TEST_EQ(vb21_verify_common_member(cbuf, &m, c->total_size - 4, 8),
VB2_ERROR_COMMON_MEMBER_SIZE,
- "vb2_verify_common_member() size");
+ "vb21_verify_common_member() size");
/* Subobject checking */
m = 0;
- TEST_SUCC(vb2_verify_common_subobject(cbuf, &m, desc_end),
- "vb2_verify_common_subobject() good offset");
+ TEST_SUCC(vb21_verify_common_subobject(cbuf, &m, desc_end),
+ "vb21_verify_common_subobject() good offset");
TEST_EQ(m, sizeof(cbuf), " new minimum");
m = desc_end + 4;
- TEST_EQ(vb2_verify_common_subobject(cbuf, &m, desc_end),
+ TEST_EQ(vb21_verify_common_subobject(cbuf, &m, desc_end),
VB2_ERROR_COMMON_MEMBER_OVERLAP,
- "vb2_verify_common_subobject() overlap");
+ "vb21_verify_common_subobject() overlap");
m = 0;
c2->total_size += 4;
- TEST_EQ(vb2_verify_common_subobject(cbuf, &m, desc_end),
+ TEST_EQ(vb21_verify_common_subobject(cbuf, &m, desc_end),
VB2_ERROR_COMMON_TOTAL_SIZE,
- "vb2_verify_common_subobject() size");
+ "vb21_verify_common_subobject() size");
}
/**
@@ -217,7 +217,7 @@ static void test_sig_size(void)
*/
static void test_verify_hash(void)
{
- struct vb2_signature *sig;
+ struct vb21_signature *sig;
const struct vb2_private_key *prik;
struct vb2_public_key pubk;
uint8_t workbuf[VB2_VERIFY_DATA_WORKBUF_BYTES]
@@ -232,16 +232,17 @@ static void test_verify_hash(void)
"create hash key");
/* Create the signature */
- TEST_SUCC(vb2_sign_data(&sig, test_data, sizeof(test_data), prik, NULL),
+ TEST_SUCC(vb21_sign_data(&sig, test_data, sizeof(test_data),
+ prik, NULL),
"create hash sig");
- TEST_SUCC(vb2_verify_data(test_data, sizeof(test_data),
- sig, &pubk, &wb),
- "vb2_verify_data() hash ok");
+ TEST_SUCC(vb21_verify_data(test_data, sizeof(test_data),
+ sig, &pubk, &wb),
+ "vb21_verify_data() hash ok");
*((uint8_t *)sig + sig->sig_offset) ^= 0xab;
- TEST_EQ(vb2_verify_data(test_data, sizeof(test_data), sig, &pubk, &wb),
- VB2_ERROR_VDATA_VERIFY_DIGEST, "vb2_verify_data() hash bad");
+ TEST_EQ(vb21_verify_data(test_data, sizeof(test_data), sig, &pubk, &wb),
+ VB2_ERROR_VDATA_VERIFY_DIGEST, "vb21_verify_data() hash bad");
free(sig);
}
@@ -254,8 +255,8 @@ static void test_verify_keyblock(void)
const char desc[16] = "test keyblock";
const struct vb2_private_key *prik[2];
struct vb2_public_key pubk, pubk2, pubk3;
- struct vb2_signature *sig;
- struct vb2_keyblock *kbuf;
+ struct vb21_signature *sig;
+ struct vb21_keyblock *kbuf;
uint32_t buf_size;
uint8_t *buf, *buf2;
@@ -276,7 +277,7 @@ static void test_verify_keyblock(void)
"create private key 2");
/* Create the test keyblock */
- TEST_SUCC(vb2_keyblock_create(&kbuf, &pubk3, prik, 2, 0x4321, desc),
+ TEST_SUCC(vb21_keyblock_create(&kbuf, &pubk3, prik, 2, 0x4321, desc),
"create keyblock");
buf = (uint8_t *)kbuf;
@@ -287,86 +288,86 @@ static void test_verify_keyblock(void)
memcpy(buf2, buf, buf_size);
vb2_workbuf_init(&wb, workbuf, sizeof(workbuf));
- kbuf = (struct vb2_keyblock *)buf;
+ kbuf = (struct vb21_keyblock *)buf;
- TEST_SUCC(vb2_verify_keyblock(kbuf, buf_size, &pubk, &wb),
- "vb2_verify_keyblock()");
+ TEST_SUCC(vb21_verify_keyblock(kbuf, buf_size, &pubk, &wb),
+ "vb21_verify_keyblock()");
memcpy(buf, buf2, buf_size);
- TEST_SUCC(vb2_verify_keyblock(kbuf, buf_size, &pubk2, &wb),
- "vb2_verify_keyblock() key 2");
+ TEST_SUCC(vb21_verify_keyblock(kbuf, buf_size, &pubk2, &wb),
+ "vb21_verify_keyblock() key 2");
memcpy(buf, buf2, buf_size);
- TEST_EQ(vb2_verify_keyblock(kbuf, buf_size, &pubk3, &wb),
+ TEST_EQ(vb21_verify_keyblock(kbuf, buf_size, &pubk3, &wb),
VB2_ERROR_KEYBLOCK_SIG_ID,
- "vb2_verify_keyblock() key not present");
+ "vb21_verify_keyblock() key not present");
memcpy(buf, buf2, buf_size);
- kbuf->c.magic = VB2_MAGIC_PACKED_KEY;
- TEST_EQ(vb2_verify_keyblock(kbuf, buf_size, &pubk, &wb),
+ kbuf->c.magic = VB21_MAGIC_PACKED_KEY;
+ TEST_EQ(vb21_verify_keyblock(kbuf, buf_size, &pubk, &wb),
VB2_ERROR_KEYBLOCK_MAGIC,
- "vb2_verify_keyblock() magic");
+ "vb21_verify_keyblock() magic");
memcpy(buf, buf2, buf_size);
kbuf->c.fixed_size++;
- TEST_EQ(vb2_verify_keyblock(kbuf, buf_size, &pubk, &wb),
+ TEST_EQ(vb21_verify_keyblock(kbuf, buf_size, &pubk, &wb),
VB2_ERROR_COMMON_FIXED_UNALIGNED,
- "vb2_verify_keyblock() header");
+ "vb21_verify_keyblock() header");
memcpy(buf, buf2, buf_size);
kbuf->c.struct_version_major++;
- TEST_EQ(vb2_verify_keyblock(kbuf, buf_size, &pubk, &wb),
+ TEST_EQ(vb21_verify_keyblock(kbuf, buf_size, &pubk, &wb),
VB2_ERROR_KEYBLOCK_HEADER_VERSION,
- "vb2_verify_keyblock() major version");
+ "vb21_verify_keyblock() major version");
memcpy(buf, buf2, buf_size);
kbuf->c.struct_version_minor++;
/* That changes the signature, so resign the keyblock */
- vb2_sign_data(&sig, buf, kbuf->sig_offset, prik[0], NULL);
+ vb21_sign_data(&sig, buf, kbuf->sig_offset, prik[0], NULL);
memcpy(buf + kbuf->sig_offset, sig, sig->c.total_size);
free(sig);
- TEST_SUCC(vb2_verify_keyblock(kbuf, buf_size, &pubk, &wb),
- "vb2_verify_keyblock() minor version");
+ TEST_SUCC(vb21_verify_keyblock(kbuf, buf_size, &pubk, &wb),
+ "vb21_verify_keyblock() minor version");
memcpy(buf, buf2, buf_size);
kbuf->c.fixed_size -= 4;
kbuf->c.desc_size += 4;
- TEST_EQ(vb2_verify_keyblock(kbuf, buf_size, &pubk, &wb),
+ TEST_EQ(vb21_verify_keyblock(kbuf, buf_size, &pubk, &wb),
VB2_ERROR_KEYBLOCK_SIZE,
- "vb2_verify_keyblock() header size");
+ "vb21_verify_keyblock() header size");
memcpy(buf, buf2, buf_size);
kbuf->key_offset = kbuf->c.total_size - 4;
- TEST_EQ(vb2_verify_keyblock(kbuf, buf_size, &pubk, &wb),
+ TEST_EQ(vb21_verify_keyblock(kbuf, buf_size, &pubk, &wb),
VB2_ERROR_COMMON_MEMBER_SIZE,
- "vb2_verify_keyblock() data key outside");
+ "vb21_verify_keyblock() data key outside");
memcpy(buf, buf2, buf_size);
- sig = (struct vb2_signature *)(buf + kbuf->sig_offset);
+ sig = (struct vb21_signature *)(buf + kbuf->sig_offset);
sig->data_size--;
- TEST_EQ(vb2_verify_keyblock(kbuf, buf_size, &pubk, &wb),
+ TEST_EQ(vb21_verify_keyblock(kbuf, buf_size, &pubk, &wb),
VB2_ERROR_KEYBLOCK_SIGNED_SIZE,
- "vb2_verify_keyblock() signed wrong size");
+ "vb21_verify_keyblock() signed wrong size");
memcpy(buf, buf2, buf_size);
- sig = (struct vb2_signature *)(buf + kbuf->sig_offset);
+ sig = (struct vb21_signature *)(buf + kbuf->sig_offset);
sig->c.total_size = kbuf->c.total_size - 4;
- TEST_EQ(vb2_verify_keyblock(kbuf, buf_size, &pubk, &wb),
+ TEST_EQ(vb21_verify_keyblock(kbuf, buf_size, &pubk, &wb),
VB2_ERROR_COMMON_TOTAL_SIZE,
- "vb2_verify_keyblock() key outside keyblock");
+ "vb21_verify_keyblock() key outside keyblock");
memcpy(buf, buf2, buf_size);
- sig = (struct vb2_signature *)(buf + kbuf->sig_offset);
+ sig = (struct vb21_signature *)(buf + kbuf->sig_offset);
sig->c.struct_version_major++;
- TEST_EQ(vb2_verify_keyblock(kbuf, buf_size, &pubk, &wb),
+ TEST_EQ(vb21_verify_keyblock(kbuf, buf_size, &pubk, &wb),
VB2_ERROR_SIG_VERSION,
- "vb2_verify_keyblock() corrupt key");
+ "vb21_verify_keyblock() corrupt key");
memcpy(buf, buf2, buf_size);
kbuf->c.struct_version_minor++;
- TEST_EQ(vb2_verify_keyblock(kbuf, buf_size, &pubk, &wb),
+ TEST_EQ(vb21_verify_keyblock(kbuf, buf_size, &pubk, &wb),
VB2_ERROR_VDATA_VERIFY_DIGEST,
- "vb2_verify_keyblock() corrupt");
+ "vb21_verify_keyblock() corrupt");
free(buf);
free(buf2);
@@ -379,10 +380,10 @@ static void test_verify_fw_preamble(void)
{
const char desc[16] = "test preamble";
const struct vb2_private_key *prikhash;
- struct vb2_signature *hashes[3];
+ struct vb21_signature *hashes[3];
struct vb2_public_key pubk;
- struct vb2_signature *sig;
- struct vb2_fw_preamble *pre;
+ struct vb21_signature *sig;
+ struct vb21_fw_preamble *pre;
uint32_t buf_size;
uint8_t *buf, *buf2;
@@ -392,7 +393,7 @@ static void test_verify_fw_preamble(void)
/*
* Preambles will usually be signed with a real key not a bare hash,
- * but the call to vb2_verify_data() inside the preamble check is the
+ * but the call to vb21_verify_data() inside the preamble check is the
* same (and its functionality is verified separately), and using a
* bare hash here saves us from needing to have a private key to do
* this test.
@@ -403,20 +404,21 @@ static void test_verify_fw_preamble(void)
"Create private hash key");
/* Create some signatures */
- TEST_SUCC(vb2_sign_data(hashes + 0, test_data, sizeof(test_data),
+ TEST_SUCC(vb21_sign_data(hashes + 0, test_data, sizeof(test_data),
prikhash, "Hash 1"),
"Hash 1");
- TEST_SUCC(vb2_sign_data(hashes + 1, test_data2, sizeof(test_data2),
+ TEST_SUCC(vb21_sign_data(hashes + 1, test_data2, sizeof(test_data2),
prikhash, "Hash 2"),
"Hash 2");
- TEST_SUCC(vb2_sign_data(hashes + 2, test_data3, sizeof(test_data3),
+ TEST_SUCC(vb21_sign_data(hashes + 2, test_data3, sizeof(test_data3),
prikhash, "Hash 3"),
"Hash 3");
/* Test good preamble */
- TEST_SUCC(vb2_fw_preamble_create(&pre, prikhash,
- (const struct vb2_signature **)hashes,
- 3, 0x1234, 0x5678, desc),
+ TEST_SUCC(vb21_fw_preamble_create(
+ &pre, prikhash,
+ (const struct vb21_signature **)hashes,
+ 3, 0x1234, 0x5678, desc),
"Create preamble good");
buf = (uint8_t *)pre;
@@ -427,84 +429,84 @@ static void test_verify_fw_preamble(void)
memcpy(buf2, buf, buf_size);
vb2_workbuf_init(&wb, workbuf, sizeof(workbuf));
- pre = (struct vb2_fw_preamble *)buf;
+ pre = (struct vb21_fw_preamble *)buf;
- TEST_SUCC(vb2_verify_fw_preamble(pre, buf_size, &pubk, &wb),
- "vb2_verify_fw_preamble()");
+ TEST_SUCC(vb21_verify_fw_preamble(pre, buf_size, &pubk, &wb),
+ "vb21_verify_fw_preamble()");
memcpy(buf, buf2, buf_size);
- pre->c.magic = VB2_MAGIC_PACKED_KEY;
- TEST_EQ(vb2_verify_fw_preamble(pre, buf_size, &pubk, &wb),
+ pre->c.magic = VB21_MAGIC_PACKED_KEY;
+ TEST_EQ(vb21_verify_fw_preamble(pre, buf_size, &pubk, &wb),
VB2_ERROR_PREAMBLE_MAGIC,
- "vb2_verify_fw_preamble() magic");
+ "vb21_verify_fw_preamble() magic");
memcpy(buf, buf2, buf_size);
pre->c.fixed_size++;
- TEST_EQ(vb2_verify_fw_preamble(pre, buf_size, &pubk, &wb),
+ TEST_EQ(vb21_verify_fw_preamble(pre, buf_size, &pubk, &wb),
VB2_ERROR_COMMON_FIXED_UNALIGNED,
- "vb2_verify_fw_preamble() header");
+ "vb21_verify_fw_preamble() header");
memcpy(buf, buf2, buf_size);
pre->c.struct_version_major++;
- TEST_EQ(vb2_verify_fw_preamble(pre, buf_size, &pubk, &wb),
+ TEST_EQ(vb21_verify_fw_preamble(pre, buf_size, &pubk, &wb),
VB2_ERROR_PREAMBLE_HEADER_VERSION,
- "vb2_verify_fw_preamble() major version");
+ "vb21_verify_fw_preamble() major version");
memcpy(buf, buf2, buf_size);
pre->c.struct_version_minor++;
/* That changes the signature, so resign the fw_preamble */
- vb2_sign_data(&sig, buf, pre->sig_offset, prikhash, NULL);
+ vb21_sign_data(&sig, buf, pre->sig_offset, prikhash, NULL);
memcpy(buf + pre->sig_offset, sig, sig->c.total_size);
free(sig);
- TEST_SUCC(vb2_verify_fw_preamble(pre, buf_size, &pubk, &wb),
- "vb2_verify_fw_preamble() minor version");
+ TEST_SUCC(vb21_verify_fw_preamble(pre, buf_size, &pubk, &wb),
+ "vb21_verify_fw_preamble() minor version");
memcpy(buf, buf2, buf_size);
pre->c.fixed_size -= 4;
pre->c.desc_size += 4;
- TEST_EQ(vb2_verify_fw_preamble(pre, buf_size, &pubk, &wb),
+ TEST_EQ(vb21_verify_fw_preamble(pre, buf_size, &pubk, &wb),
VB2_ERROR_PREAMBLE_SIZE,
- "vb2_verify_fw_preamble() header size");
+ "vb21_verify_fw_preamble() header size");
memcpy(buf, buf2, buf_size);
- sig = (struct vb2_signature *)(buf + pre->hash_offset);
+ sig = (struct vb21_signature *)(buf + pre->hash_offset);
sig->c.total_size += pre->c.total_size;
- TEST_EQ(vb2_verify_fw_preamble(pre, buf_size, &pubk, &wb),
+ TEST_EQ(vb21_verify_fw_preamble(pre, buf_size, &pubk, &wb),
VB2_ERROR_COMMON_TOTAL_SIZE,
- "vb2_verify_fw_preamble() hash size");
+ "vb21_verify_fw_preamble() hash size");
memcpy(buf, buf2, buf_size);
- sig = (struct vb2_signature *)(buf + pre->hash_offset);
+ sig = (struct vb21_signature *)(buf + pre->hash_offset);
sig->sig_size /= 2;
- TEST_EQ(vb2_verify_fw_preamble(pre, buf_size, &pubk, &wb),
+ TEST_EQ(vb21_verify_fw_preamble(pre, buf_size, &pubk, &wb),
VB2_ERROR_SIG_SIZE,
- "vb2_verify_fw_preamble() hash integrity");
+ "vb21_verify_fw_preamble() hash integrity");
memcpy(buf, buf2, buf_size);
pre->hash_count++;
- TEST_EQ(vb2_verify_fw_preamble(pre, buf_size, &pubk, &wb),
+ TEST_EQ(vb21_verify_fw_preamble(pre, buf_size, &pubk, &wb),
VB2_ERROR_COMMON_MEMBER_OVERLAP,
- "vb2_verify_fw_preamble() hash count");
+ "vb21_verify_fw_preamble() hash count");
memcpy(buf, buf2, buf_size);
- sig = (struct vb2_signature *)(buf + pre->sig_offset);
+ sig = (struct vb21_signature *)(buf + pre->sig_offset);
sig->c.total_size += 4;
- TEST_EQ(vb2_verify_fw_preamble(pre, buf_size, &pubk, &wb),
+ TEST_EQ(vb21_verify_fw_preamble(pre, buf_size, &pubk, &wb),
VB2_ERROR_COMMON_TOTAL_SIZE,
- "vb2_verify_fw_preamble() sig inside");
+ "vb21_verify_fw_preamble() sig inside");
memcpy(buf, buf2, buf_size);
- sig = (struct vb2_signature *)(buf + pre->sig_offset);
+ sig = (struct vb21_signature *)(buf + pre->sig_offset);
buf[pre->sig_offset + sig->sig_offset]++;
- TEST_EQ(vb2_verify_fw_preamble(pre, buf_size, &pubk, &wb),
+ TEST_EQ(vb21_verify_fw_preamble(pre, buf_size, &pubk, &wb),
VB2_ERROR_VDATA_VERIFY_DIGEST,
- "vb2_verify_fw_preamble() sig corrupt");
+ "vb21_verify_fw_preamble() sig corrupt");
memcpy(buf, buf2, buf_size);
pre->flags++;
- TEST_EQ(vb2_verify_fw_preamble(pre, buf_size, &pubk, &wb),
+ TEST_EQ(vb21_verify_fw_preamble(pre, buf_size, &pubk, &wb),
VB2_ERROR_VDATA_VERIFY_DIGEST,
- "vb2_verify_fw_preamble() preamble corrupt");
+ "vb21_verify_fw_preamble() preamble corrupt");
free(buf);
free(buf2);