@@ -83,20 +83,27 @@ 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 ,
88- uint8_t * sig , size_t slen ,
89- uint8_t key_id )
86+ fih_ret
87+ bootutil_verify_sig (uint8_t * msg , uint32_t mlen , uint8_t * sig , size_t slen ,
88+ uint8_t key_id )
9089{
9190 int rc ;
9291 FIH_DECLARE (fih_rc , FIH_FAILURE );
9392 uint8_t * pubkey ;
9493 uint8_t * end ;
9594
96- BOOT_LOG_DBG ("bootutil_verify: ED25519 key_id %d" , (int )key_id );
95+ BOOT_LOG_DBG ("bootutil_verify_sig: ED25519 key_id %d" , (int )key_id );
96+
97+ #if !defined(MCUBOOT_SIGN_PURE )
98+ if (mlen != IMAGE_HASH_SIZE ) {
99+ BOOT_LOG_DBG ("bootutil_verify_sig: expected hash len %d, got %d" ,
100+ IMAGE_HASH_SIZE , mlen );
101+ goto out ;
102+ }
103+ #endif
97104
98105 if (slen != EDDSA_SIGNATURE_LENGTH ) {
99- BOOT_LOG_DBG ("bootutil_verify : expected slen %d, got %u" ,
106+ BOOT_LOG_DBG ("bootutil_verify_sig : expected slen %d, got %u" ,
100107 EDDSA_SIGNATURE_LENGTH , (unsigned int )slen );
101108 FIH_SET (fih_rc , FIH_FAILURE );
102109 goto out ;
@@ -108,7 +115,7 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
108115#if !defined(MCUBOOT_KEY_IMPORT_BYPASS_ASN )
109116 rc = bootutil_import_key (& pubkey , end );
110117 if (rc ) {
111- BOOT_LOG_DBG ("bootutil_verify : import key failed %d" , rc );
118+ BOOT_LOG_DBG ("bootutil_verify_sig : import key failed %d" , rc );
112119 FIH_SET (fih_rc , FIH_FAILURE );
113120 goto out ;
114121 }
@@ -118,7 +125,7 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
118125 * There is no check whether this is the correct key,
119126 * here, by the algorithm selected.
120127 */
121- BOOT_LOG_DBG ("bootutil_verify : bypass ASN1" );
128+ BOOT_LOG_DBG ("bootutil_verify_sig : bypass ASN1" );
122129 if (* bootutil_keys [key_id ].len < NUM_ED25519_BYTES ) {
123130 FIH_SET (fih_rc , FIH_FAILURE );
124131 goto out ;
@@ -127,7 +134,7 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
127134 pubkey = end - NUM_ED25519_BYTES ;
128135#endif
129136
130- rc = ED25519_verify (buf , blen , sig , pubkey );
137+ rc = ED25519_verify (msg , mlen , sig , pubkey );
131138
132139 if (rc == 0 ) {
133140 /* if verify returns 0, there was an error. */
@@ -141,34 +148,4 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
141148 FIH_RET (fih_rc );
142149}
143150
144- /* Signature verification function.
145- * Verifies message with provided signature.
146- * When compiled without MCUBOOT_SIGN_PURE, the function 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-
174151#endif /* MCUBOOT_SIGN_ED25519 */
0 commit comments