Skip to content

Commit 2367a60

Browse files
committed
bootutil: Improve defines in PSA encryption source
Remove unneeded and improve used. Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
1 parent 3f458fe commit 2367a60

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

boot/bootutil/src/encrypted_psa.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,19 @@
2828
BOOT_LOG_MODULE_DECLARE(mcuboot_psa_enc);
2929

3030
#define EXPECTED_ENC_LEN BOOT_ENC_TLV_SIZE
31-
#define EXPECTED_ENC_TLV IMAGE_TLV_ENC_X25519
3231
#define EC_PUBK_INDEX (0)
33-
#define EC_TAG_INDEX (32)
34-
#define EC_CIPHERKEY_INDEX (32 + 32)
32+
#define EC_PUBK_LEN (32)
33+
#define EC_TAG_INDEX (EC_PUBK_INDEX + EC_PUBK_LEN)
34+
#define EC_TAG_LEN (32)
35+
#define EC_CIPHERKEY_INDEX (EC_TAG_INDEX + EC_TAG_LEN)
36+
#define EC_CIPHERKEY_LEN BOOT_ENC_KEY_SIZE
3537
_Static_assert(EC_CIPHERKEY_INDEX + BOOT_ENC_KEY_SIZE == EXPECTED_ENC_LEN,
3638
"Please fix ECIES-X25519 component indexes");
3739

3840
#define X25519_OID "\x6e"
3941
static const uint8_t ec_pubkey_oid[] = MBEDTLS_OID_ISO_IDENTIFIED_ORG \
4042
MBEDTLS_OID_ORG_GOV X25519_OID;
4143

42-
#define SHARED_KEY_LEN 32
4344
#define PRIV_KEY_LEN 32
4445

4546
/* Fixme: This duplicates code from encrypted.c and depends on mbedtls */
@@ -180,7 +181,7 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
180181
*/
181182
psa_ret = psa_key_derivation_key_agreement(&key_do, PSA_KEY_DERIVATION_INPUT_SECRET,
182183
kid, &buf[EC_PUBK_INDEX],
183-
BOOTUTIL_CRYPTO_SHA256_DIGEST_SIZE);
184+
EC_PUBK_LEN);
184185
psa_cleanup_ret = psa_destroy_key(kid);
185186
if (psa_cleanup_ret != PSA_SUCCESS) {
186187
BOOT_LOG_WRN("Built-in key destruction failed %d", psa_cleanup_ret);
@@ -242,9 +243,9 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
242243

243244
/* Verify the MAC tag of the random encryption key */
244245
psa_ret = psa_mac_verify(kid, PSA_ALG_HMAC(PSA_ALG_SHA_256),
245-
&buf[EC_CIPHERKEY_INDEX], BOOT_ENC_KEY_SIZE,
246+
&buf[EC_CIPHERKEY_INDEX], EC_CIPHERKEY_LEN,
246247
&buf[EC_TAG_INDEX],
247-
BOOTUTIL_CRYPTO_SHA256_DIGEST_SIZE);
248+
EC_TAG_LEN);
248249
psa_cleanup_ret = psa_destroy_key(kid);
249250
if (psa_cleanup_ret != PSA_SUCCESS) {
250251
BOOT_LOG_WRN("MAC key destruction failed %d", psa_cleanup_ret);

0 commit comments

Comments
 (0)