Skip to content

Commit 7cdb50c

Browse files
committed
bootutil: Replace bootutil_verify_img with bootutil_verify_sig
With small changes the bootutil_verify_sig can now be used for the same purpose as bootutil_verify_img. Signed-off-by: Dominik Ermel <[email protected]>
1 parent 85aecf6 commit 7cdb50c

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

boot/bootutil/src/bootutil_priv.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,13 @@ struct boot_sector_buffer {
281281
#endif
282282
};
283283

284-
/* The function is intended for verification of image hash against
285-
* provided signature.
284+
/* The function is intended for verification of message hash against
285+
* provided signature. If MCUBOOT_SIGN_PURE is enabled the function
286+
* expects msg to point to image to verify signature over, and mlen
287+
* is image size; otherwise msg is expected to be pointer to hash of
288+
* an image and mlen to length of the hash.
286289
*/
287-
fih_ret bootutil_verify_sig(uint8_t *hash, uint32_t hlen, uint8_t *sig,
290+
fih_ret bootutil_verify_sig(uint8_t *msg, uint32_t mlen, uint8_t *sig,
288291
size_t slen, uint8_t key_id);
289292

290293
/* The function is intended for direct verification of image

boot/bootutil/src/image_ed25519.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,28 +141,30 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
141141
FIH_RET(fih_rc);
142142
}
143143

144-
/* Hash signature verification function.
145-
* Verifies hash against provided signature.
146-
* The function verifies that hash is of expected size and then
147-
* calls bootutil_verify to do the signature verification.
144+
/* Signature verification function.
145+
* Verifies message with provided signature.
146+
* When compiled without MCUBOOT_SIGN_PURE, the function expects
147+
* msg to be hash of expected size.
148148
*/
149149
fih_ret
150-
bootutil_verify_sig(uint8_t *hash, uint32_t hlen,
150+
bootutil_verify_sig(uint8_t *msg, uint32_t mlen,
151151
uint8_t *sig, size_t slen,
152152
uint8_t key_id)
153153
{
154154
FIH_DECLARE(fih_rc, FIH_FAILURE);
155155

156156
BOOT_LOG_DBG("bootutil_verify_sig: ED25519 key_id %d", (int)key_id);
157157

158-
if (hlen != IMAGE_HASH_SIZE) {
159-
BOOT_LOG_DBG("bootutil_verify_sig: expected hlen %d, got %d",
160-
IMAGE_HASH_SIZE, hlen);
158+
#if !defined(MCUBOOT_SIGN_PURE)
159+
if (mlen != IMAGE_HASH_SIZE) {
160+
BOOT_LOG_DBG("bootutil_verify_sig: expected hash len %d, got %d",
161+
IMAGE_HASH_SIZE, mlen);
161162
FIH_SET(fih_rc, FIH_FAILURE);
162163
goto out;
163164
}
165+
#endif
164166

165-
FIH_CALL(bootutil_verify, fih_rc, hash, IMAGE_HASH_SIZE, sig,
167+
FIH_CALL(bootutil_verify, fih_rc, msg, mlen, sig,
166168
slen, key_id);
167169

168170
out:

boot/bootutil/src/image_validate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ bootutil_img_validate(struct boot_loader_state *state,
422422
* a device to memory. The pointer is beginning of image in flash,
423423
* so offset of area, the range is header + image + protected tlvs.
424424
*/
425-
FIH_CALL(bootutil_verify_img, valid_signature, (void *)(base + flash_area_get_off(fap)),
425+
FIH_CALL(bootutil_verify_sig, valid_signature, (void *)(base + flash_area_get_off(fap)),
426426
hdr->ih_hdr_size + hdr->ih_img_size + hdr->ih_protect_tlv_size,
427427
buf, len, key_id);
428428
#endif

0 commit comments

Comments
 (0)