@@ -114,7 +114,7 @@ extern const struct bootutil_key bootutil_enc_key;
114114int
115115boot_decrypt_key (const uint8_t * buf , uint8_t * enckey )
116116{
117- uint8_t derived_key [BOOTUTIL_CRYPTO_AES_CTR_KEY_SIZE + BOOTUTIL_CRYPTO_SHA256_DIGEST_SIZE ];
117+ uint8_t derived_key [BOOT_ENC_KEY_SIZE + BOOTUTIL_CRYPTO_SHA256_DIGEST_SIZE ];
118118 uint8_t * cp ;
119119 uint8_t * cpend ;
120120 uint8_t private_key [PRIV_KEY_LEN ];
@@ -134,7 +134,7 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
134134 * the beginning of the input buffer.
135135 */
136136 uint8_t iv_and_key [PSA_CIPHER_IV_LENGTH (PSA_KEY_TYPE_AES , PSA_ALG_CTR ) +
137- BOOTUTIL_CRYPTO_AES_CTR_KEY_SIZE ];
137+ BOOT_ENC_KEY_SIZE ];
138138
139139 psa_ret = psa_crypto_init ();
140140 if (psa_ret != PSA_SUCCESS ) {
@@ -208,7 +208,7 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
208208 return -1 ;
209209 }
210210
211- len = BOOTUTIL_CRYPTO_AES_CTR_KEY_SIZE + BOOTUTIL_CRYPTO_SHA256_DIGEST_SIZE ;
211+ len = BOOT_ENC_KEY_SIZE + BOOTUTIL_CRYPTO_SHA256_DIGEST_SIZE ;
212212 psa_ret = psa_key_derivation_output_bytes (& key_do , derived_key , len );
213213 psa_cleanup_ret = psa_key_derivation_abort (& key_do );
214214 if (psa_cleanup_ret != PSA_SUCCESS ) {
@@ -219,7 +219,7 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
219219 return -1 ;
220220 }
221221
222- /* The derived key consists of BOOTUTIL_CRYPTO_AES_CTR_KEY_SIZE bytes
222+ /* The derived key consists of BOOT_ENC_KEY_SIZE bytes
223223 * followed by BOOTUTIL_CRYPTO_SHA256_DIGEST_SIZE bytes. Both parts will
224224 * be imported at the point where needed and discarded immediately after.
225225 */
@@ -228,11 +228,11 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
228228 psa_set_key_algorithm (& kattr , PSA_ALG_HMAC (PSA_ALG_SHA_256 ));
229229
230230 /* Import the MAC tag key part of derived key, that is the part that starts
231- * after BOOTUTIL_CRYPTO_AES_CTR_KEY_SIZE and has length of
231+ * after BOOT_ENC_KEY_SIZE and has length of
232232 * BOOTUTIL_CRYPTO_SHA256_DIGEST_SIZE bytes.
233233 */
234234 psa_ret = psa_import_key (& kattr ,
235- & derived_key [BOOTUTIL_CRYPTO_AES_CTR_KEY_SIZE ],
235+ & derived_key [BOOT_ENC_KEY_SIZE ],
236236 BOOTUTIL_CRYPTO_SHA256_DIGEST_SIZE , & kid );
237237 psa_reset_key_attributes (& kattr );
238238 if (psa_ret != PSA_SUCCESS ) {
@@ -262,8 +262,7 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
262262 psa_set_key_algorithm (& kattr , PSA_ALG_CTR );
263263
264264 /* Import the AES partition of derived key, the first 16 bytes */
265- psa_ret = psa_import_key (& kattr , & derived_key [0 ],
266- BOOTUTIL_CRYPTO_AES_CTR_KEY_SIZE , & kid );
265+ psa_ret = psa_import_key (& kattr , & derived_key [0 ], BOOT_ENC_KEY_SIZE , & kid );
267266 memset (derived_key , 0 , sizeof (derived_key ));
268267 if (psa_ret != PSA_SUCCESS ) {
269268 BOOT_LOG_ERR ("AES key import failed %d" , psa_ret );
@@ -279,14 +278,14 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
279278
280279 len = 0 ;
281280 psa_ret = psa_cipher_decrypt (kid , PSA_ALG_CTR , iv_and_key , sizeof (iv_and_key ),
282- enckey , BOOTUTIL_CRYPTO_AES_CTR_KEY_SIZE , & len );
281+ enckey , BOOT_ENC_KEY_SIZE , & len );
283282 memset (iv_and_key , 0 , sizeof (iv_and_key ));
284283 psa_cleanup_ret = psa_destroy_key (kid );
285284 if (psa_cleanup_ret != PSA_SUCCESS ) {
286285 BOOT_LOG_WRN ("AES key destruction failed %d" , psa_cleanup_ret );
287286 }
288- if (psa_ret != PSA_SUCCESS || len != BOOTUTIL_CRYPTO_AES_CTR_KEY_SIZE ) {
289- memset (enckey , 0 , BOOTUTIL_CRYPTO_AES_CTR_KEY_SIZE );
287+ if (psa_ret != PSA_SUCCESS || len != BOOT_ENC_KEY_SIZE ) {
288+ memset (enckey , 0 , BOOT_ENC_KEY_SIZE );
290289 BOOT_LOG_ERR ("Random key decryption failed %d" , psa_ret );
291290 return -1 ;
292291 }
0 commit comments