summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Boichat <drinkcat@google.com>2017-02-07 16:23:10 +0800
committerchrome-bot <chrome-bot@chromium.org>2017-02-11 02:42:01 -0800
commit0bde10afbfa8753521b1d10d89b5409d4d1ad1f2 (patch)
tree61fbd66b44983c206c329bc1b4fc81fbbf5d12a2
parentd02ae3899c1644bc9f866cb0b0f7e9d6f5842e8f (diff)
downloadvboot-0bde10afbfa8753521b1d10d89b5409d4d1ad1f2.tar.gz
signature_digest/SignatureDigest: convert vb2_crypto to hash algorithm
We were passing the wrong value to PrependDigestInfo. Let's also refactor the function a little bit. BRANCH=none BUG=chromium:689371 TEST=make gentestcases; git status => no change Change-Id: I0244c3f3de05b33b7ddd21e93a266faf34f2c239 Reviewed-on: https://chromium-review.googlesource.com/439086 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--host/lib/signature_digest.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/host/lib/signature_digest.c b/host/lib/signature_digest.c
index 025a9ffe..7f309b18 100644
--- a/host/lib/signature_digest.c
+++ b/host/lib/signature_digest.c
@@ -40,14 +40,19 @@ uint8_t* SignatureDigest(const uint8_t* buf, uint64_t len,
uint8_t* info_digest = NULL;
uint8_t digest[VB2_SHA512_DIGEST_SIZE]; /* Longest digest */
+ enum vb2_hash_algorithm hash_alg;
if (algorithm >= VB2_ALG_COUNT) {
- fprintf(stderr, "SignatureDigest(): "
- "Called with invalid algorithm!\n");
- } else if (VB2_SUCCESS ==
- vb2_digest_buffer(buf, len, vb2_crypto_to_hash(algorithm),
- digest, sizeof(digest))) {
- info_digest = PrependDigestInfo(algorithm, digest);
+ fprintf(stderr,
+ "SignatureDigest(): Called with invalid algorithm!\n");
+ return NULL;
+ }
+
+ hash_alg = vb2_crypto_to_hash(algorithm);
+
+ if (VB2_SUCCESS == vb2_digest_buffer(buf, len, hash_alg,
+ digest, sizeof(digest))) {
+ info_digest = PrependDigestInfo(hash_alg, digest);
}
return info_digest;
}