summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2021-03-05 10:30:19 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2021-07-30 19:50:36 +0200
commitba540e79eca794b6051effe54a2e34650c48a77a (patch)
tree16001f99b8b069e8cde52f334ca3ef1ac33a7dc6 /common
parenta3337563c705bc8e0cf32f910b3e9e3c43d962ff (diff)
downloadbarebox-ba540e79eca794b6051effe54a2e34650c48a77a.tar.gz
barebox-ba540e79eca794b6051effe54a2e34650c48a77a.tar.xz
fit: Use digest_verify() to verify hashes
Use digest_verify() to verify hashes rather than open code it. This simplifies the code a bit. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r--common/image-fit.c8
1 files changed, 1 insertions, 7 deletions
diff --git a/common/image-fit.c b/common/image-fit.c
index c1a34a4405..38a372ff52 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -371,7 +371,6 @@ static int fit_verify_hash(struct fit_handle *handle, struct device_node *image,
struct digest *d;
const char *algo;
const char *value_read;
- char *value_calc;
int hash_len, ret;
struct device_node *hash;
@@ -418,13 +417,10 @@ static int fit_verify_hash(struct fit_handle *handle, struct device_node *image,
goto err_digest_free;
}
- value_calc = xmalloc(hash_len);
-
digest_init(d);
digest_update(d, data, data_len);
- digest_final(d, value_calc);
- if (memcmp(value_read, value_calc, hash_len)) {
+ if (digest_verify(d, value_read)) {
pr_info("%s: hash BAD\n", hash->full_name);
ret = -EBADMSG;
} else {
@@ -432,8 +428,6 @@ static int fit_verify_hash(struct fit_handle *handle, struct device_node *image,
ret = 0;
}
- free(value_calc);
-
err_digest_free:
digest_free(d);