Skip to content

Commit db4eff8

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 b709feb commit db4eff8

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
@@ -164,28 +164,30 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
164164
FIH_RET(fih_rc);
165165
}
166166

167-
/* Hash signature verification function.
168-
* Verifies hash against provided signature.
169-
* The function verifies that hash is of expected size and then
170-
* calls bootutil_verify to do the signature verification.
167+
/* Signature verification function.
168+
* Verifies message with provided signature.
169+
* When compiled without MCUBOOT_SIGN_PURE, the function expects
170+
* msg to be hash of expected size.
171171
*/
172172
fih_ret
173-
bootutil_verify_sig(uint8_t *hash, uint32_t hlen,
173+
bootutil_verify_sig(uint8_t *msg, uint32_t mlen,
174174
uint8_t *sig, size_t slen,
175175
uint8_t key_id)
176176
{
177177
FIH_DECLARE(fih_rc, FIH_FAILURE);
178178

179179
BOOT_LOG_DBG("bootutil_verify_sig: ED25519 key_id %d", (int)key_id);
180180

181-
if (hlen != IMAGE_HASH_SIZE) {
182-
BOOT_LOG_DBG("bootutil_verify_sig: expected hlen %d, got %d",
183-
IMAGE_HASH_SIZE, hlen);
181+
#if !defined(MCUBOOT_SIGN_PURE)
182+
if (mlen != IMAGE_HASH_SIZE) {
183+
BOOT_LOG_DBG("bootutil_verify_sig: expected hash len %d, got %d",
184+
IMAGE_HASH_SIZE, mlen);
184185
FIH_SET(fih_rc, FIH_FAILURE);
185186
goto out;
186187
}
188+
#endif
187189

188-
FIH_CALL(bootutil_verify, fih_rc, hash, IMAGE_HASH_SIZE, sig,
190+
FIH_CALL(bootutil_verify, fih_rc, msg, mlen, sig,
189191
slen, key_id);
190192

191193
out:

boot/bootutil/src/image_validate.c

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

0 commit comments

Comments
 (0)