@@ -114,7 +114,7 @@ extern const struct bootutil_key bootutil_enc_key;
114
114
int
115
115
boot_decrypt_key (const uint8_t * buf , uint8_t * enckey )
116
116
{
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 ];
118
118
uint8_t * cp ;
119
119
uint8_t * cpend ;
120
120
uint8_t private_key [PRIV_KEY_LEN ];
@@ -134,7 +134,7 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
134
134
* the beginning of the input buffer.
135
135
*/
136
136
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 ];
138
138
139
139
psa_ret = psa_crypto_init ();
140
140
if (psa_ret != PSA_SUCCESS ) {
@@ -208,7 +208,7 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
208
208
return -1 ;
209
209
}
210
210
211
- len = BOOTUTIL_CRYPTO_AES_CTR_KEY_SIZE + BOOTUTIL_CRYPTO_SHA256_DIGEST_SIZE ;
211
+ len = BOOT_ENC_KEY_SIZE + BOOTUTIL_CRYPTO_SHA256_DIGEST_SIZE ;
212
212
psa_ret = psa_key_derivation_output_bytes (& key_do , derived_key , len );
213
213
psa_cleanup_ret = psa_key_derivation_abort (& key_do );
214
214
if (psa_cleanup_ret != PSA_SUCCESS ) {
@@ -219,7 +219,7 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
219
219
return -1 ;
220
220
}
221
221
222
- /* The derived key consists of BOOTUTIL_CRYPTO_AES_CTR_KEY_SIZE bytes
222
+ /* The derived key consists of BOOT_ENC_KEY_SIZE bytes
223
223
* followed by BOOTUTIL_CRYPTO_SHA256_DIGEST_SIZE bytes. Both parts will
224
224
* be imported at the point where needed and discarded immediately after.
225
225
*/
@@ -228,11 +228,11 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
228
228
psa_set_key_algorithm (& kattr , PSA_ALG_HMAC (PSA_ALG_SHA_256 ));
229
229
230
230
/* 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
232
232
* BOOTUTIL_CRYPTO_SHA256_DIGEST_SIZE bytes.
233
233
*/
234
234
psa_ret = psa_import_key (& kattr ,
235
- & derived_key [BOOTUTIL_CRYPTO_AES_CTR_KEY_SIZE ],
235
+ & derived_key [BOOT_ENC_KEY_SIZE ],
236
236
BOOTUTIL_CRYPTO_SHA256_DIGEST_SIZE , & kid );
237
237
psa_reset_key_attributes (& kattr );
238
238
if (psa_ret != PSA_SUCCESS ) {
@@ -262,8 +262,7 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
262
262
psa_set_key_algorithm (& kattr , PSA_ALG_CTR );
263
263
264
264
/* 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 );
267
266
memset (derived_key , 0 , sizeof (derived_key ));
268
267
if (psa_ret != PSA_SUCCESS ) {
269
268
BOOT_LOG_ERR ("AES key import failed %d" , psa_ret );
@@ -279,14 +278,14 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
279
278
280
279
len = 0 ;
281
280
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 );
283
282
memset (iv_and_key , 0 , sizeof (iv_and_key ));
284
283
psa_cleanup_ret = psa_destroy_key (kid );
285
284
if (psa_cleanup_ret != PSA_SUCCESS ) {
286
285
BOOT_LOG_WRN ("AES key destruction failed %d" , psa_cleanup_ret );
287
286
}
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 );
290
289
BOOT_LOG_ERR ("Random key decryption failed %d" , psa_ret );
291
290
return -1 ;
292
291
}
0 commit comments