Skip to content

Improve PSA offset/len defines for tlv and remove some defs from bootutil #2281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

de-nordic
Copy link
Collaborator

Fixes in encrypted_psa.
BOOTUTIL_CRYPTO_AES_CTR_KEY_SIZE has been replaced with BOOT_ENC_KEY_SIZE
BOOTUTIL_CRYPTO_AES_CTR_BLOCK_SIZE has been replaced with BOOT_ENC_BLOCK_SIZE

Remove unneeded and improve used.

Signed-off-by: Dominik Ermel <[email protected]>
BOOT_ENC_KEY_SIZE is enough.
BOOTUTIL_CRYPTO_AES_CTR_BLOCK_SIZE has been replaced with
BOOT_ENC_BLOCK_SIZE.

Signed-off-by: Dominik Ermel <[email protected]>
@de-nordic de-nordic requested a review from davidvincze as a code owner April 25, 2025 18:58
@de-nordic de-nordic requested review from Copilot and removed request for davidvincze April 25, 2025 18:58
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves the PSA offset/length definitions for TLV handling and removes outdated bootutil definitions, streamlining the key and block size constants used in encryption functions.

  • Update key and block size constants from BOOTUTIL_CRYPTO_AES_CTR_KEY_SIZE/BOOTUTIL_CRYPTO_AES_CTR_BLOCK_SIZE to BOOT_ENC_KEY_SIZE/BOOT_ENC_BLOCK_SIZE.
  • Adjust associated index and length calculations in encryption and decryption routines.
  • Refactor crypto header definitions for consistency across crypto branches.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
boot/bootutil/src/encrypted_psa.c Updated key derivation and decryption routines to use the new BOOT_ENC_* definitions.
boot/bootutil/src/encrypted.c Revised AES key unwrap and decryption functions to consistently reflect the updated defines.
boot/bootutil/include/bootutil/crypto/aes_ctr.h Modified macro definitions to use BOOT_ENC_BLOCK_SIZE (and ensure compatibility with new sizes).
Comments suppressed due to low confidence (3)

boot/bootutil/src/encrypted_psa.c:184

  • The updated argument in psa_key_derivation_key_agreement has changed from BOOTUTIL_CRYPTO_SHA256_DIGEST_SIZE to EC_PUBK_LEN; please confirm that using the public key length here is intentional and matches the expected input size for key derivation. Adding a clarifying comment could aid future maintainers.
psa_ret = psa_key_derivation_key_agreement(&key_do, PSA_KEY_DERIVATION_INPUT_SECRET, kid, &buf[EC_PUBK_INDEX], EC_PUBK_LEN);

boot/bootutil/src/encrypted.c:537

  • Ensure that there are adequate tests covering the new key derivation logic with the updated key size constants, including both success and failure scenarios for the hkdf function.
if (rc != 0 || len != (BOOT_ENC_KEY_SIZE + BOOTUTIL_CRYPTO_SHA256_DIGEST_SIZE)) {

boot/bootutil/include/bootutil/crypto/aes_ctr.h:25

  • Review the consistency of macro definitions across different crypto branches; verify that BOOT_ENC_KEY_SIZE is defined for the MBEDTLS and PSA branches, as it is not explicitly declared in this header.
#define BOOT_ENC_BLOCK_SIZE (16)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant