Skip to content

Commit e4bd1b3

Browse files
committed
[nrf fromtree] bootutil: ed25519 psa: Merge bootutil_verify_sig and bootutil_verify
Reduce layers of calls. Modified on cherry-pick. (cherry picked from commit 3f69203) Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
1 parent cc2350d commit e4bd1b3

1 file changed

Lines changed: 16 additions & 39 deletions

File tree

boot/bootutil/src/image_ed25519.c

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,9 @@ bootutil_import_key(uint8_t **cp, uint8_t *end)
9090
* The function does key import and checks whether signature is
9191
* of expected length.
9292
*/
93-
static fih_ret
94-
bootutil_verify(uint8_t *buf, uint32_t blen,
95-
uint8_t *sig, size_t slen,
96-
uint8_t key_id)
93+
fih_ret
94+
bootutil_verify_sig(uint8_t *msg, uint32_t mlen, uint8_t *sig, size_t slen,
95+
uint8_t key_id)
9796
{
9897
int rc;
9998
FIH_DECLARE(fih_rc, FIH_FAILURE);
@@ -102,10 +101,18 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
102101
uint8_t *end;
103102
#endif
104103

105-
BOOT_LOG_DBG("bootutil_verify: ED25519 key_id %d", (int)key_id);
104+
BOOT_LOG_DBG("bootutil_verify_sig: ED25519 key_id %d", (int)key_id);
105+
106+
#if !defined(MCUBOOT_SIGN_PURE)
107+
if (mlen != IMAGE_HASH_SIZE) {
108+
BOOT_LOG_DBG("bootutil_verify_sig: expected hash len %d, got %d",
109+
IMAGE_HASH_SIZE, mlen);
110+
goto out;
111+
}
112+
#endif
106113

107114
if (slen != EDDSA_SIGNATURE_LENGTH) {
108-
BOOT_LOG_DBG("bootutil_verify: expected slen %d, got %u",
115+
BOOT_LOG_DBG("bootutil_verify_sig: expected slen %d, got %u",
109116
EDDSA_SIGNATURE_LENGTH, (unsigned int)slen);
110117
FIH_SET(fih_rc, FIH_FAILURE);
111118
goto out;
@@ -129,7 +136,7 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
129136
#if !defined(MCUBOOT_KEY_IMPORT_BYPASS_ASN)
130137
rc = bootutil_import_key(&pubkey, end);
131138
if (rc) {
132-
BOOT_LOG_DBG("bootutil_verify: import key failed %d", rc);
139+
BOOT_LOG_DBG("bootutil_verify_sig: import key failed %d", rc);
133140
FIH_SET(fih_rc, FIH_FAILURE);
134141
goto out;
135142
}
@@ -139,7 +146,7 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
139146
* There is no check whether this is the correct key,
140147
* here, by the algorithm selected.
141148
*/
142-
BOOT_LOG_DBG("bootutil_verify: bypass ASN1");
149+
BOOT_LOG_DBG("bootutil_verify_sig: bypass ASN1");
143150
if (*bootutil_keys[key_id].len < NUM_ED25519_BYTES) {
144151
FIH_SET(fih_rc, FIH_FAILURE);
145152
goto out;
@@ -150,7 +157,7 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
150157

151158
#endif
152159

153-
rc = ED25519_verify(buf, blen, sig, pubkey);
160+
rc = ED25519_verify(msg, mlen, sig, pubkey);
154161

155162
if (rc == 0) {
156163
/* if verify returns 0, there was an error. */
@@ -164,34 +171,4 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
164171
FIH_RET(fih_rc);
165172
}
166173

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.
171-
*/
172-
fih_ret
173-
bootutil_verify_sig(uint8_t *msg, uint32_t mlen,
174-
uint8_t *sig, size_t slen,
175-
uint8_t key_id)
176-
{
177-
FIH_DECLARE(fih_rc, FIH_FAILURE);
178-
179-
BOOT_LOG_DBG("bootutil_verify_sig: ED25519 key_id %d", (int)key_id);
180-
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);
185-
FIH_SET(fih_rc, FIH_FAILURE);
186-
goto out;
187-
}
188-
#endif
189-
190-
FIH_CALL(bootutil_verify, fih_rc, msg, mlen, sig,
191-
slen, key_id);
192-
193-
out:
194-
FIH_RET(fih_rc);
195-
}
196-
197174
#endif /* MCUBOOT_SIGN_ED25519 */

0 commit comments

Comments
 (0)