summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeremy Condra <gcondra@google.com>2014-05-17 05:16:12 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-05-17 05:16:14 +0000
commitf55c8e93e08b81b5f265a90640f7809d344411ca (patch)
tree09263e201b72890d04dc196ded563758189c638a
parente37d9e33c4f9e2631c293fdb585e81350f6c727f (diff)
parent792cc086ff2a004af82f061147392445caeb879a (diff)
downloadextras-f55c8e93e08b81b5f265a90640f7809d344411ca.tar.gz
Merge "verity: Move build_verity_tree.cpp to use BN_* for hex conversion."
-rw-r--r--verity/build_verity_tree.cpp18
1 files changed, 6 insertions, 12 deletions
diff --git a/verity/build_verity_tree.cpp b/verity/build_verity_tree.cpp
index b993ef6d..1c3815d7 100644
--- a/verity/build_verity_tree.cpp
+++ b/verity/build_verity_tree.cpp
@@ -150,23 +150,17 @@ int main(int argc, char **argv)
memcpy(salt, optarg, salt_size);
break;
case 'A': {
- size_t len = strlen(optarg);
- if (len % 2 != 0) {
- FATAL("hex salt must be multiple of 2 characters long\n");
+ BIGNUM *bn = NULL;
+ if(!BN_hex2bn(&bn, optarg)) {
+ FATAL("failed to convert salt from hex\n");
}
- salt_size = len / 2;
+ salt_size = BN_num_bytes(bn);
salt = new unsigned char[salt_size]();
if (salt == NULL) {
FATAL("failed to allocate memory for salt\n");
}
- for (size_t i = 0; i < salt_size; i++) {
- char buf[3] = {optarg[2*i], optarg[2*i+1], 0};
- char *endptr;
- unsigned long hex = strtoul(optarg + 2*i, &endptr, 16);
- if (endptr != buf + 2 || hex > 0xff) {
- FATAL("malformed hex salt\n");
- }
- salt[i] = hex;
+ if((size_t)BN_bn2bin(bn, salt) != salt_size) {
+ FATAL("failed to convert salt to bytes\n");
}
}
break;