summaryrefslogtreecommitdiff
path: root/host/lib
diff options
context:
space:
mode:
authorJoel Kitching <kitching@google.com>2019-12-12 14:45:29 +0800
committerCommit Bot <commit-bot@chromium.org>2020-02-11 02:04:10 +0000
commit166840277a2d4806fa0d89980b3501090441d5ed (patch)
tree66a0245aea8b0ae841143e13dfb69eb651d09522 /host/lib
parent9e39b7452393486d1a37ff9eee61906452f5d4f7 (diff)
downloadvboot-166840277a2d4806fa0d89980b3501090441d5ed.tar.gz
vboot: move vboot 2.1 functions and structs into host code
These structs and functions need to stick around for futility to use, but they are no longer supported in firmware code. Rename host/lib21/include/* files to end in 21 instead of 2. BUG=b:124141368, chromium:968464 TEST=make clean && make runtests BRANCH=none Change-Id: I01e181e2f03553d60724fbdc826f5ada63777303 Cq-Depend: chromium:1969172 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1963621 Reviewed-by: Julius Werner <jwerner@chromium.org> Tested-by: Joel Kitching <kitching@chromium.org> Commit-Queue: Joel Kitching <kitching@chromium.org>
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/host_common.c2
-rw-r--r--host/lib/host_key2.c33
-rw-r--r--host/lib/host_keyblock.c2
-rw-r--r--host/lib/host_signature.c2
-rw-r--r--host/lib/host_signature2.c4
-rw-r--r--host/lib/include/host_common.h2
-rw-r--r--host/lib/include/host_key.h14
-rw-r--r--host/lib/signature_digest.c2
-rw-r--r--host/lib/util_misc.c2
9 files changed, 54 insertions, 9 deletions
diff --git a/host/lib/host_common.c b/host/lib/host_common.c
index 1833c62d..00f9100e 100644
--- a/host/lib/host_common.c
+++ b/host/lib/host_common.c
@@ -11,7 +11,7 @@
#include "2rsa.h"
#include "2sysincludes.h"
#include "host_common.h"
-#include "host_key2.h"
+#include "host_key21.h"
#include "utility.h"
#include "vb2_common.h"
diff --git a/host/lib/host_key2.c b/host/lib/host_key2.c
index 5849cf76..6984c67f 100644
--- a/host/lib/host_key2.c
+++ b/host/lib/host_key2.c
@@ -16,7 +16,7 @@
#include "2sha.h"
#include "2sysincludes.h"
#include "host_common.h"
-#include "host_key2.h"
+#include "host_key21.h"
#include "host_key.h"
#include "host_misc.h"
#include "vb2_common.h"
@@ -296,3 +296,34 @@ vb2_error_t vb2_packed_key_looks_ok(const struct vb2_packed_key *key,
return VB2_SUCCESS;
}
+
+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);
+
+ /* Make sure buffer is the correct length */
+ if (!expected_key_size || expected_key_size != key_size) {
+ VB2_DEBUG("Wrong key size for algorithm\n");
+ return VB2_ERROR_UNPACK_KEY_SIZE;
+ }
+
+ /* Check for alignment */
+ if (!vb2_aligned(buf32, sizeof(uint32_t)))
+ return VB2_ERROR_UNPACK_KEY_ALIGN;
+
+ key->arrsize = buf32[0];
+
+ /* Sanity check key array size */
+ if (key->arrsize * sizeof(uint32_t) != vb2_rsa_sig_size(key->sig_alg))
+ return VB2_ERROR_UNPACK_KEY_ARRAY_SIZE;
+
+ key->n0inv = buf32[1];
+
+ /* Arrays point inside the key data */
+ key->n = buf32 + 2;
+ key->rr = buf32 + 2 + key->arrsize;
+
+ return VB2_SUCCESS;
+}
diff --git a/host/lib/host_keyblock.c b/host/lib/host_keyblock.c
index 522e87a9..a7dbedef 100644
--- a/host/lib/host_keyblock.c
+++ b/host/lib/host_keyblock.c
@@ -14,7 +14,7 @@
#include "2rsa.h"
#include "2sha.h"
#include "host_common.h"
-#include "host_key2.h"
+#include "host_key21.h"
#include "host_keyblock.h"
#include "host_key.h"
#include "vb2_common.h"
diff --git a/host/lib/host_signature.c b/host/lib/host_signature.c
index 8cea9f4a..db536c6e 100644
--- a/host/lib/host_signature.c
+++ b/host/lib/host_signature.c
@@ -20,7 +20,7 @@
#include "2sha.h"
#include "2sysincludes.h"
#include "host_common.h"
-#include "host_signature2.h"
+#include "host_signature21.h"
#include "vb2_common.h"
/* Invoke [external_signer] command with [pem_file] as an argument, contents of
diff --git a/host/lib/host_signature2.c b/host/lib/host_signature2.c
index 6bc900dd..f7caa71f 100644
--- a/host/lib/host_signature2.c
+++ b/host/lib/host_signature2.c
@@ -20,8 +20,8 @@
#include "2sha.h"
#include "file_keys.h"
#include "host_common.h"
-#include "host_key2.h"
-#include "host_signature2.h"
+#include "host_key21.h"
+#include "host_signature21.h"
#include "vb2_common.h"
struct vb2_signature *vb2_alloc_signature(uint32_t sig_size,
diff --git a/host/lib/include/host_common.h b/host/lib/include/host_common.h
index 7fde53ba..5fcc5c52 100644
--- a/host/lib/include/host_common.h
+++ b/host/lib/include/host_common.h
@@ -9,7 +9,7 @@
#define VBOOT_REFERENCE_HOST_COMMON_H_
#include "host_key.h"
-#include "host_key2.h"
+#include "host_key21.h"
#include "host_keyblock.h"
#include "host_misc.h"
#include "host_signature.h"
diff --git a/host/lib/include/host_key.h b/host/lib/include/host_key.h
index 26792720..9b594c62 100644
--- a/host/lib/include/host_key.h
+++ b/host/lib/include/host_key.h
@@ -11,6 +11,7 @@
#include "2crypto.h"
#include "2return_codes.h"
+struct vb2_public_key;
struct vb2_packed_key;
struct vb2_private_key;
@@ -146,4 +147,17 @@ struct vb2_packed_key *vb2_read_packed_keyb(const char *filename,
vb2_error_t vb2_write_packed_key(const char *filename,
const struct vb2_packed_key *key);
+/**
+ * Unpack the RSA data fields for a public key
+ *
+ * This is called by vb21_unpack_key() to extract the arrays from a packed key.
+ * These elements of *key will point inside the key_data buffer.
+ *
+ * @param key Destination key for RSA data fields
+ * @param key_data Packed key data (from inside a packed key buffer)
+ * @param key_size Size of packed key data in bytes
+ */
+vb2_error_t vb2_unpack_key_data(struct vb2_public_key *key,
+ const uint8_t *key_data, uint32_t key_size);
+
#endif /* VBOOT_REFERENCE_HOST_KEY_H_ */
diff --git a/host/lib/signature_digest.c b/host/lib/signature_digest.c
index b480798d..f6be00a3 100644
--- a/host/lib/signature_digest.c
+++ b/host/lib/signature_digest.c
@@ -14,7 +14,7 @@
#include "2sha.h"
#include "2sysincludes.h"
#include "host_common.h"
-#include "host_signature2.h"
+#include "host_signature21.h"
#include "signature_digest.h"
uint8_t* PrependDigestInfo(enum vb2_hash_algorithm hash_alg, uint8_t* digest)
diff --git a/host/lib/util_misc.c b/host/lib/util_misc.c
index 8b9388a4..c99947f0 100644
--- a/host/lib/util_misc.c
+++ b/host/lib/util_misc.c
@@ -17,7 +17,7 @@
#include "2sha.h"
#include "2sysincludes.h"
#include "host_common.h"
-#include "host_key2.h"
+#include "host_key21.h"
#include "openssl_compat.h"
#include "util_misc.h"
#include "vb2_common.h"