summaryrefslogtreecommitdiff
path: root/verity/build_verity_tree_main.cpp
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2018-06-26 11:57:13 -0700
committerTianjie Xu <xunchang@google.com>2018-07-24 11:12:26 -0700
commitc231d50d694a7275dbcd6876be36a64095e0baf4 (patch)
treea070065c85df4db6f2c70d5cd67c11d745cbe436 /verity/build_verity_tree_main.cpp
parent295c3e1c044434edd878c8a2708d136387f4965c (diff)
downloadextras-c231d50d694a7275dbcd6876be36a64095e0baf4.tar.gz
Add support of more hash algorithms for verity tree builder
Currently, verified boot 1.0 is using SHA256 to compute the hash tree while AVB is using SHA1. We should support at least these two hash functionss in the HashTreeBuilder and command line parser. And we can potentially add more algorithms in the future. Bug: 25170618 Test: unit tests pass Change-Id: I5f6dc8a545c0cef75acbbc2044959e8100f9f842
Diffstat (limited to 'verity/build_verity_tree_main.cpp')
-rw-r--r--verity/build_verity_tree_main.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/verity/build_verity_tree_main.cpp b/verity/build_verity_tree_main.cpp
index 9eaaa79e..76164cc5 100644
--- a/verity/build_verity_tree_main.cpp
+++ b/verity/build_verity_tree_main.cpp
@@ -52,6 +52,7 @@ int main(int argc, char** argv) {
bool sparse = false;
uint64_t calculate_size = 0;
bool verbose = false;
+ std::string hash_algorithm;
while (1) {
constexpr struct option long_options[] = {
@@ -61,8 +62,10 @@ int main(int argc, char** argv) {
{"sparse", no_argument, nullptr, 'S'},
{"verity-size", required_argument, nullptr, 's'},
{"verbose", no_argument, nullptr, 'v'},
+ {"hash-algorithm", required_argument, nullptr, 0},
{nullptr, 0, nullptr, 0}};
- int c = getopt_long(argc, argv, "a:A:hSs:v", long_options, nullptr);
+ int option_index;
+ int c = getopt_long(argc, argv, "a:A:hSs:v", long_options, &option_index);
if (c < 0) {
break;
}
@@ -102,6 +105,12 @@ int main(int argc, char** argv) {
case 'v':
verbose = true;
break;
+ case 0: {
+ std::string option = long_options[option_index].name;
+ if (option == "hash-algorithm") {
+ hash_algorithm = optarg;
+ }
+ } break;
case '?':
usage();
return 1;
@@ -113,7 +122,13 @@ int main(int argc, char** argv) {
argc -= optind;
argv += optind;
- HashTreeBuilder builder(kBlockSize);
+ auto hash_function = hash_algorithm.empty()
+ ? EVP_sha256()
+ : HashTreeBuilder::HashFunction(hash_algorithm);
+ if (hash_function == nullptr) {
+ return 1;
+ }
+ HashTreeBuilder builder(kBlockSize, hash_function);
if (calculate_size) {
if (argc != 0) {