summaryrefslogtreecommitdiff
path: root/futility
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2020-03-10 23:27:10 -0700
committerCommit Bot <commit-bot@chromium.org>2020-04-06 18:54:38 +0000
commitb1c6ef3892c4e36a1375249ce4494959d2457011 (patch)
tree2c584a236674c6d57c8064aec663d728e31812d6 /futility
parent509a887c5a89530e9748241625ad3cb25f5de3c5 (diff)
downloadvboot-b1c6ef3892c4e36a1375249ce4494959d2457011.tar.gz
Rewrite algorithm type parsers and make them globally available
There is some code strewn around between futility and the vb21-specific part of hostlib to allow parsing of textual algorithm names to vboot enums, but it is somewhat disorganized and not written in a super efficient way. This patch rewrites it and centralizes all the algorithm mapping stuff under 2crypto.c so it can be a single source of truth for all of vboot. (String parsing routines still need to stay in hostlib since not all firmware targets support things like stroul() and strcasecmp().) BRANCH=None BUG=None TEST=make runtests Signed-off-by: Julius Werner <jwerner@chromium.org> Change-Id: I719b2499992a6e4395a29231bc8b9a7680c5b174 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/2099447 Reviewed-by: Joel Kitching <kitching@chromium.org> Commit-Queue: Joel Kitching <kitching@chromium.org>
Diffstat (limited to 'futility')
-rw-r--r--futility/cmd_create.c14
-rw-r--r--futility/cmd_sign.c13
-rw-r--r--futility/futility_options.h3
-rw-r--r--futility/vb2_helper.c27
4 files changed, 17 insertions, 40 deletions
diff --git a/futility/cmd_create.c b/futility/cmd_create.c
index 2f7a8d5f..aca1d4c0 100644
--- a/futility/cmd_create.c
+++ b/futility/cmd_create.c
@@ -23,6 +23,7 @@
#include "openssl_compat.h"
#include "util_misc.h"
#include "vb2_common.h"
+#include "vboot_host.h"
/* Command line options */
enum {
@@ -55,7 +56,7 @@ static const struct option long_opts[] = {
static void print_help(int argc, char *argv[])
{
- const struct vb2_text_vs_enum *entry;
+ enum vb2_hash_algorithm alg;
printf("\n"
"Usage: " MYNAME " %s [options] <INFILE> [<BASENAME>]\n", argv[0]);
@@ -67,10 +68,13 @@ static void print_help(int argc, char *argv[])
" --version <number> Key version (default %d)\n"
" --hash_alg <number> Hashing algorithm to use:\n",
DEFAULT_VERSION);
- for (entry = vb2_text_vs_hash; entry->name; entry++)
- printf(" %d / %s%s\n",
- entry->num, entry->name,
- entry->num == VB2_HASH_SHA256 ? " (default)" : "");
+ for (alg = 0; alg < VB2_HASH_ALG_COUNT; alg++) {
+ const char *name = vb2_get_hash_algorithm_name(alg);
+ if (strcmp(name, VB2_INVALID_ALG_NAME) != 0)
+ printf(" %d / %s%s\n",
+ alg, name,
+ alg == VB2_HASH_SHA256 ? " (default)" : "");
+ }
printf(
" --id <id> Identifier for this keypair (vb21 only)\n"
" --desc <text> Human-readable description (vb21 only)\n"
diff --git a/futility/cmd_sign.c b/futility/cmd_sign.c
index 980e6d12..c95b8c97 100644
--- a/futility/cmd_sign.c
+++ b/futility/cmd_sign.c
@@ -423,7 +423,7 @@ static void print_help_kern_preamble(int argc, char *argv[])
static void print_help_usbpd1(int argc, char *argv[])
{
- const struct vb2_text_vs_enum *entry;
+ enum vb2_hash_algorithm algo;
printf("\n"
"Usage: " MYNAME " %s --type %s [options] INFILE [OUTFILE]\n"
@@ -450,10 +450,13 @@ static void print_help_usbpd1(int argc, char *argv[])
argv[0],
futil_file_type_name(FILE_TYPE_USBPD1),
futil_file_type_desc(FILE_TYPE_USBPD1));
- for (entry = vb2_text_vs_hash; entry->name; entry++)
- printf(" %d / %s%s\n",
- entry->num, entry->name,
- entry->num == VB2_HASH_SHA256 ? " (default)" : "");
+ for (algo = 0; algo < VB2_HASH_ALG_COUNT; algo++) {
+ const char *name = vb2_get_hash_algorithm_name(algo);
+ if (strcmp(name, VB2_INVALID_ALG_NAME) != 0)
+ printf(" %d / %s%s\n",
+ algo, name,
+ algo == VB2_HASH_SHA256 ? " (default)" : "");
+ }
printf("\n"
"The size and offset assumptions can be overridden. "
"All numbers are in bytes.\n"
diff --git a/futility/futility_options.h b/futility/futility_options.h
index a3bdd650..a79505c3 100644
--- a/futility/futility_options.h
+++ b/futility/futility_options.h
@@ -67,7 +67,4 @@ struct sign_option_s {
};
extern struct sign_option_s sign_option;
-/* Return true if hash_alg was identified, either by name or number */
-int vb2_lookup_hash_alg(const char *str, enum vb2_hash_algorithm *alg);
-
#endif /* VBOOT_REFERENCE_FUTILITY_OPTIONS_H_ */
diff --git a/futility/vb2_helper.c b/futility/vb2_helper.c
index fb0362ae..4d676a68 100644
--- a/futility/vb2_helper.c
+++ b/futility/vb2_helper.c
@@ -20,33 +20,6 @@
#include "openssl_compat.h"
#include "util_misc.h"
-int vb2_lookup_hash_alg(const char *str, enum vb2_hash_algorithm *alg)
-{
- const struct vb2_text_vs_enum *entry;
- uint32_t val;
- char *e;
-
- /* try string first */
- entry = vb2_lookup_by_name(vb2_text_vs_hash, str);
- if (entry) {
- *alg = entry->num;
- return 1;
- }
-
- /* fine, try number */
- val = strtoul(str, &e, 0);
- if (!*str || (e && *e))
- /* that's not a number */
- return 0;
-
- if (!vb2_lookup_by_num(vb2_text_vs_hash, val))
- /* That's not a valid alg */
- return 0;
-
- *alg = val;
- return 1;
-}
-
enum futil_file_type ft_recognize_vb21_key(uint8_t *buf, uint32_t len)
{
struct vb2_public_key pubkey;