summaryrefslogtreecommitdiff
path: root/tests/vb2_host_key_tests.c
diff options
context:
space:
mode:
authorJoel Kitching <kitching@google.com>2019-10-07 15:28:43 +0800
committerCommit Bot <commit-bot@chromium.org>2019-12-25 22:33:00 +0000
commit582453dd62a9616a95a19b42a36f6adb8988e329 (patch)
tree1b65180b07771eef688cac73b23dbc0dafe082a1 /tests/vb2_host_key_tests.c
parent80c1a85a87e589ed74962cad98f4892dbe6a3283 (diff)
downloadvboot-582453dd62a9616a95a19b42a36f6adb8988e329.tar.gz
vboot: fix up some host key functions for host_key2.cfactory-excelsior-12812.B
Deprecate: PublicKeyInit --> vb2_init_packed_key PublicKeyCopy --> vb2_copy_packed_key Rename: packed_key_looks_ok --> vb2_packed_key_looks_ok Move vb2_packed_key_looks_ok from host_key.c to host_key2.c. Move tests/vboot_common_tests.c to tests/vb2_host_key_tests.c. Remove firmware/lib/vboot_common.c. Remove host/lib/host_key.c. BUG=b:124141368, chromium:968464 TEST=make clean && make runtests BRANCH=none Change-Id: I627b2af0416ac69460f9860614a69cad8bdb76a7 Signed-off-by: Joel Kitching <kitching@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1844597 Tested-by: Joel Kitching <kitching@chromium.org> Reviewed-by: Joel Kitching <kitching@chromium.org> Commit-Queue: Joel Kitching <kitching@chromium.org>
Diffstat (limited to 'tests/vb2_host_key_tests.c')
-rw-r--r--tests/vb2_host_key_tests.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/vb2_host_key_tests.c b/tests/vb2_host_key_tests.c
new file mode 100644
index 00000000..82dd3572
--- /dev/null
+++ b/tests/vb2_host_key_tests.c
@@ -0,0 +1,68 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Tests for host library vboot2 key functions
+ */
+
+#include "2common.h"
+#include "host_common.h"
+#include "test_common.h"
+
+/* Public key utility functions */
+static void public_key_tests(void)
+{
+ struct vb2_packed_key k[3];
+ struct vb2_packed_key j[5];
+
+ /* Fill some bits of the public key data */
+ memset(j, 0, sizeof(j));
+ memset(k, 0x42, sizeof(k));
+ k[1].key_size = 12345;
+ k[2].key_version = 67;
+
+ vb2_init_packed_key(k, (uint8_t*)(k + 1),
+ 2 * sizeof(struct vb2_packed_key));
+ TEST_EQ(k->key_offset, sizeof(struct vb2_packed_key),
+ "vb2_init_packed_key key_offset");
+ TEST_EQ(k->key_size, 2 * sizeof(struct vb2_packed_key),
+ "vb2_init_packed_key key_size");
+ TEST_EQ(k->algorithm, VB2_ALG_COUNT, "vb2_init_packed_key algorithm");
+ TEST_EQ(k->key_version, 0, "vb2_init_packed_key key_version");
+
+ /* Set algorithm and version, so we can tell if they get copied */
+ k->algorithm = 3;
+ k->key_version = 21;
+
+ /* Copying to a smaller destination should fail */
+ vb2_init_packed_key(j, (uint8_t*)(j + 1),
+ 2 * sizeof(struct vb2_packed_key) - 1);
+ TEST_NEQ(0, vb2_copy_packed_key(j, k), "vb2_copy_packed_key too small");
+
+ /* Copying to same or larger size should succeed */
+ vb2_init_packed_key(j, (uint8_t*)(j + 2),
+ 2 * sizeof(struct vb2_packed_key) + 1);
+ TEST_EQ(0, vb2_copy_packed_key(j, k), "vb2_copy_packed_key same");
+ /* Offset in destination shouldn't have been modified */
+ TEST_EQ(j->key_offset, 2 * sizeof(struct vb2_packed_key),
+ "vb2_copy_packed_key key_offset");
+ /* Size should have been reduced to match the source */
+ TEST_EQ(k->key_size, 2 * sizeof(struct vb2_packed_key),
+ "vb2_copy_packed_key key_size");
+ /* Other fields should have been copied */
+ TEST_EQ(k->algorithm, j->algorithm, "vb2_copy_packed_key algorithm");
+ TEST_EQ(k->key_version, j->key_version,
+ "vb2_copy_packed_key key_version");
+ /* Data should have been copied */
+ TEST_EQ(0,
+ memcmp(vb2_packed_key_data(k),
+ vb2_packed_key_data(j), k->key_size),
+ "vb2_copy_packed_key data");
+}
+
+int main(int argc, char* argv[])
+{
+ public_key_tests();
+
+ return gTestSuccess ? 0 : 255;
+}