Skip to content

Commit 4d3fc5c

Browse files
ahasztagjukkar
authored andcommitted
suit: Added direct decryption
Added the possibility to decrypt the firmware directly using the secret key, without using AES KW. Signed-off-by: Artur Hadasz <[email protected]>
1 parent 8965d4f commit 4d3fc5c

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

subsys/suit/stream/stream_filters/src/suit_decrypt_filter.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ struct decrypt_ctx {
2727
size_t tag_size;
2828
size_t stored_tag_bytes;
2929
uint8_t tag[PSA_AEAD_TAG_MAX_SIZE];
30+
enum suit_cose_alg kw_alg_id;
3031
bool in_use;
3132
};
3233

@@ -200,7 +201,11 @@ static suit_plat_err_t flush(void *ctx)
200201
}
201202
}
202203

203-
psa_destroy_key(decrypt_ctx->cek_key_id);
204+
#ifdef CONFIG_SUIT_AES_KW_MANUAL
205+
if (decrypt_ctx->kw_alg_id == suit_cose_aes256_kw) {
206+
psa_destroy_key(decrypt_ctx->cek_key_id);
207+
}
208+
#endif
204209

205210
zeroize(decrypted_buf, sizeof(decrypted_buf));
206211

@@ -209,6 +214,7 @@ static suit_plat_err_t flush(void *ctx)
209214
decrypt_ctx->tag_size = 0;
210215
decrypt_ctx->stored_tag_bytes = 0;
211216
zeroize(decrypt_ctx->tag, sizeof(decrypt_ctx->tag));
217+
decrypt_ctx->kw_alg_id = 0;
212218

213219
return res;
214220
}
@@ -278,6 +284,21 @@ static suit_plat_err_t unwrap_cek(enum suit_cose_alg kw_alg_id,
278284
}
279285
break;
280286
#endif
287+
case suit_cose_direct:
288+
psa_key_id_t cek_key_id_value;
289+
290+
if (suit_plat_decode_key_id(&kw_key.direct.key_id, &cek_key_id_value)
291+
!= SUIT_PLAT_SUCCESS) {
292+
return SUIT_PLAT_ERR_INVAL;
293+
}
294+
#ifdef MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
295+
cek_key_id->MBEDTLS_PRIVATE(key_id) = cek_key_id_value;
296+
cek_key_id->MBEDTLS_PRIVATE(owner) = NRF_OWNER_SECURE;
297+
#else /* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */
298+
*cek_key_id = cek_key_id_value;
299+
#endif /* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */
300+
break;
301+
281302
default:
282303
LOG_ERR("Unsupported key wrap/key derivation algorithm: %d", kw_alg_id);
283304
return SUIT_PLAT_ERR_INVAL;
@@ -335,6 +356,8 @@ suit_plat_err_t suit_decrypt_filter_get(struct stream_sink *dec_sink,
335356
return ret;
336357
}
337358

359+
ctx.kw_alg_id = enc_info->kw_alg_id;
360+
338361
ctx.operation = psa_aead_operation_init();
339362

340363
status = psa_aead_decrypt_setup(&ctx.operation, ctx.cek_key_id, psa_decrypt_alg_id);

0 commit comments

Comments
 (0)