From ba540e79eca794b6051effe54a2e34650c48a77a Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Fri, 5 Mar 2021 10:30:19 +0100 Subject: 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 --- common/image-fit.c | 8 +------- 1 file changed, 1 insertion(+), 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); -- cgit v1.2.3