Skip to content

Commit 30860cf

Browse files
committed
[nrf fromtree] 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. (cherry picked from commit 7cec4af) Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
1 parent 669034e commit 30860cf

3 files changed

Lines changed: 18 additions & 13 deletions

File tree

boot/bootutil/src/bootutil_priv.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,13 @@ struct boot_sector_buffer {
302302
#endif
303303
};
304304

305-
/* The function is intended for verification of image hash against
306-
* provided signature.
305+
/* The function is intended for verification of message hash against
306+
* provided signature. If MCUBOOT_SIGN_PURE is enabled the function
307+
* expects msg to point to image to verify signature over, and mlen
308+
* is image size; otherwise msg is expected to be pointer to hash of
309+
* an image and mlen to length of the hash.
307310
*/
308-
fih_ret bootutil_verify_sig(uint8_t *hash, uint32_t hlen, uint8_t *sig,
311+
fih_ret bootutil_verify_sig(uint8_t *msg, uint32_t mlen, uint8_t *sig,
309312
size_t slen, uint8_t key_id);
310313

311314
/* 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
@@ -150,28 +150,30 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
150150
FIH_RET(fih_rc);
151151
}
152152

153-
/* Hash signature verification function.
154-
* Verifies hash against provided signature.
155-
* The function verifies that hash is of expected size and then
156-
* calls bootutil_verify to do the signature verification.
153+
/* Signature verification function.
154+
* Verifies message with provided signature.
155+
* When compiled without MCUBOOT_SIGN_PURE, the function expects
156+
* msg to be hash of expected size.
157157
*/
158158
fih_ret
159-
bootutil_verify_sig(uint8_t *hash, uint32_t hlen,
159+
bootutil_verify_sig(uint8_t *msg, uint32_t mlen,
160160
uint8_t *sig, size_t slen,
161161
uint8_t key_id)
162162
{
163163
FIH_DECLARE(fih_rc, FIH_FAILURE);
164164

165165
BOOT_LOG_DBG("bootutil_verify_sig: ED25519 key_id %d", (int)key_id);
166166

167-
if (hlen != IMAGE_HASH_SIZE) {
168-
BOOT_LOG_DBG("bootutil_verify_sig: expected hlen %d, got %d",
169-
IMAGE_HASH_SIZE, hlen);
167+
#if !defined(MCUBOOT_SIGN_PURE)
168+
if (mlen != IMAGE_HASH_SIZE) {
169+
BOOT_LOG_DBG("bootutil_verify_sig: expected hash len %d, got %d",
170+
IMAGE_HASH_SIZE, mlen);
170171
FIH_SET(fih_rc, FIH_FAILURE);
171172
goto out;
172173
}
174+
#endif
173175

174-
FIH_CALL(bootutil_verify, fih_rc, hash, IMAGE_HASH_SIZE, sig,
176+
FIH_CALL(bootutil_verify, fih_rc, msg, mlen, sig,
175177
slen, key_id);
176178

177179
out:

boot/bootutil/src/image_validate.c

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

0 commit comments

Comments
 (0)