@@ -83,8 +83,8 @@ bootutil_import_key(uint8_t **cp, uint8_t *end)
8383 * The function does key import and checks whether signature is
8484 * of expected length.
8585 */
86- static fih_ret
87- bootutil_verify (uint8_t * buf , uint32_t blen ,
86+ fih_ret
87+ bootutil_verify_sig (uint8_t * msg , uint32_t mlen ,
8888 uint8_t * sig , size_t slen ,
8989 uint8_t key_id )
9090{
@@ -93,10 +93,18 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
9393 uint8_t * pubkey ;
9494 uint8_t * end ;
9595
96- BOOT_LOG_DBG ("bootutil_verify: ED25519 key_id %d" , (int )key_id );
96+ BOOT_LOG_DBG ("bootutil_verify_sig: ED25519 key_id %d" , (int )key_id );
97+
98+ #if !defined(MCUBOOT_SIGN_PURE )
99+ if (mlen != IMAGE_HASH_SIZE ) {
100+ BOOT_LOG_DBG ("bootutil_verify_sig: expected hash len %d, got %d" ,
101+ IMAGE_HASH_SIZE , mlen );
102+ goto out ;
103+ }
104+ #endif
97105
98106 if (slen != EDDSA_SIGNATURE_LENGTH ) {
99- BOOT_LOG_DBG ("bootutil_verify : expected slen %d, got %u" ,
107+ BOOT_LOG_DBG ("bootutil_verify_sig : expected slen %d, got %u" ,
100108 EDDSA_SIGNATURE_LENGTH , (unsigned int )slen );
101109 FIH_SET (fih_rc , FIH_FAILURE );
102110 goto out ;
@@ -108,7 +116,7 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
108116#if !defined(MCUBOOT_KEY_IMPORT_BYPASS_ASN )
109117 rc = bootutil_import_key (& pubkey , end );
110118 if (rc ) {
111- BOOT_LOG_DBG ("bootutil_verify : import key failed %d" , rc );
119+ BOOT_LOG_DBG ("bootutil_verify_sig : import key failed %d" , rc );
112120 FIH_SET (fih_rc , FIH_FAILURE );
113121 goto out ;
114122 }
@@ -118,7 +126,7 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
118126 * There is no check whether this is the correct key,
119127 * here, by the algorithm selected.
120128 */
121- BOOT_LOG_DBG ("bootutil_verify : bypass ASN1" );
129+ BOOT_LOG_DBG ("bootutil_verify_sig : bypass ASN1" );
122130 if (* bootutil_keys [key_id ].len < NUM_ED25519_BYTES ) {
123131 FIH_SET (fih_rc , FIH_FAILURE );
124132 goto out ;
@@ -127,7 +135,7 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
127135 pubkey = end - NUM_ED25519_BYTES ;
128136#endif
129137
130- rc = ED25519_verify (buf , blen , sig , pubkey );
138+ rc = ED25519_verify (msg , mlen , sig , pubkey );
131139
132140 if (rc == 0 ) {
133141 /* if verify returns 0, there was an error. */
@@ -141,34 +149,4 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
141149 FIH_RET (fih_rc );
142150}
143151
144- /* Signature verification function.
145- * Verifies message with provided signature.
146- * When compiled without MCUBOOT_SIGN_PURE, the funciton expects
147- * msg to be hash of expected size.
148- */
149- fih_ret
150- bootutil_verify_sig (uint8_t * msg , uint32_t mlen ,
151- uint8_t * sig , size_t slen ,
152- uint8_t key_id )
153- {
154- FIH_DECLARE (fih_rc , FIH_FAILURE );
155-
156- BOOT_LOG_DBG ("bootutil_verify_sig: ED25519 key_id %d" , (int )key_id );
157-
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 );
162- FIH_SET (fih_rc , FIH_FAILURE );
163- goto out ;
164- }
165- #endif
166-
167- FIH_CALL (bootutil_verify , fih_rc , msg , mlen , sig ,
168- slen , key_id );
169-
170- out :
171- FIH_RET (fih_rc );
172- }
173-
174152#endif /* MCUBOOT_SIGN_ED25519 */
0 commit comments