Skip to content

Commit b2e2182

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 17e3e7e commit b2e2182

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
@@ -87,10 +87,9 @@ bootutil_import_key(uint8_t **cp, uint8_t *end)
8787
* The function does key import and checks whether signature is
8888
* of expected length.
8989
*/
90-
static fih_ret
91-
bootutil_verify(uint8_t *buf, uint32_t blen,
92-
uint8_t *sig, size_t slen,
93-
uint8_t key_id)
90+
fih_ret
91+
bootutil_verify_sig(uint8_t *msg, uint32_t mlen, uint8_t *sig, size_t slen,
92+
uint8_t key_id)
9493
{
9594
int rc;
9695
FIH_DECLARE(fih_rc, FIH_FAILURE);
@@ -99,10 +98,18 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
9998
uint8_t *end;
10099
#endif
101100

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

104111
if (slen != EDDSA_SIGNATURE_LENGTH) {
105-
BOOT_LOG_DBG("bootutil_verify: expected slen %d, got %u",
112+
BOOT_LOG_DBG("bootutil_verify_sig: expected slen %d, got %u",
106113
EDDSA_SIGNATURE_LENGTH, (unsigned int)slen);
107114
FIH_SET(fih_rc, FIH_FAILURE);
108115
goto out;
@@ -115,7 +122,7 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
115122
#if !defined(MCUBOOT_KEY_IMPORT_BYPASS_ASN)
116123
rc = bootutil_import_key(&pubkey, end);
117124
if (rc) {
118-
BOOT_LOG_DBG("bootutil_verify: import key failed %d", rc);
125+
BOOT_LOG_DBG("bootutil_verify_sig: import key failed %d", rc);
119126
FIH_SET(fih_rc, FIH_FAILURE);
120127
goto out;
121128
}
@@ -125,7 +132,7 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
125132
* There is no check whether this is the correct key,
126133
* here, by the algorithm selected.
127134
*/
128-
BOOT_LOG_DBG("bootutil_verify: bypass ASN1");
135+
BOOT_LOG_DBG("bootutil_verify_sig: bypass ASN1");
129136
if (*bootutil_keys[key_id].len < NUM_ED25519_BYTES) {
130137
FIH_SET(fih_rc, FIH_FAILURE);
131138
goto out;
@@ -136,7 +143,7 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
136143

137144
#endif
138145

139-
rc = ED25519_verify(buf, blen, sig, pubkey);
146+
rc = ED25519_verify(msg, mlen, sig, pubkey);
140147

141148
if (rc == 0) {
142149
/* if verify returns 0, there was an error. */
@@ -150,34 +157,4 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
150157
FIH_RET(fih_rc);
151158
}
152159

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.
157-
*/
158-
fih_ret
159-
bootutil_verify_sig(uint8_t *msg, uint32_t mlen,
160-
uint8_t *sig, size_t slen,
161-
uint8_t key_id)
162-
{
163-
FIH_DECLARE(fih_rc, FIH_FAILURE);
164-
165-
BOOT_LOG_DBG("bootutil_verify_sig: ED25519 key_id %d", (int)key_id);
166-
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);
171-
FIH_SET(fih_rc, FIH_FAILURE);
172-
goto out;
173-
}
174-
#endif
175-
176-
FIH_CALL(bootutil_verify, fih_rc, msg, mlen, sig,
177-
slen, key_id);
178-
179-
out:
180-
FIH_RET(fih_rc);
181-
}
182-
183160
#endif /* MCUBOOT_SIGN_ED25519 */

0 commit comments

Comments
 (0)