[PATCH v2 3/5] scripts: rockchip: add helper for updating hash
Michael Tretter
m.tretter at pengutronix.de
Tue Aug 5 00:33:48 PDT 2025
The idb contains a flag for the used hash type. Use the flag to
determine the used hash function and update the hash accordingly.
Signed-off-by: Michael Tretter <m.tretter at pengutronix.de>
---
Changes in v2:
- Drop double negation in flag check
---
scripts/rkimage.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/scripts/rkimage.c b/scripts/rkimage.c
index 4c972746cdabbc831b0b5c0024e840c81b1c1120..be2267aa38b505312c131638d743b42faaf8978c 100644
--- a/scripts/rkimage.c
+++ b/scripts/rkimage.c
@@ -42,6 +42,17 @@ static void sha512(const void *buf, int len, void *out)
EVP_MD_CTX_free(md_ctx);
}
+static void idb_hash(struct newidb *idb)
+{
+ unsigned char *idbu8 = (void *)idb;
+ size_t size = 1536;
+
+ if (idb->flags & NEWIDB_FLAGS_SHA256)
+ sha256(idbu8, size, idbu8 + size);
+ else if (idb->flags & NEWIDB_FLAGS_SHA512)
+ sha512(idbu8, size, idbu8 + size);
+}
+
typedef enum {
HASH_TYPE_SHA256 = 1,
HASH_TYPE_SHA512 = 2,
@@ -62,7 +73,6 @@ static int create_newidb(struct newidb *idb)
bool keep_cert = false;
int image_offset;
int i;
- unsigned char *idbu8 = (void *)idb;
idb->magic = NEWIDB_MAGIC;
idb->n_files = (n_code << 16) | (1 << 7) | (1 << 8);
@@ -98,10 +108,7 @@ static int create_newidb(struct newidb *idb)
}
- if (hash_type == HASH_TYPE_SHA256)
- sha256(idbu8, 1536, idbu8 + 1536);
- else if (hash_type == HASH_TYPE_SHA512)
- sha512(idbu8, 1536, idbu8 + 1536);
+ idb_hash(idb);
return 0;
}
--
2.39.5
More information about the barebox
mailing list