Skip to content

Commit beaad03

Browse files
committed
bootutil: Replace local identifiers with common definitions
Cleanup. Signed-off-by: Dominik Ermel <[email protected]>
1 parent 3481b21 commit beaad03

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

boot/bootutil/src/encrypted.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ key_unwrap(const uint8_t *wrapped, uint8_t *enckey, struct bootutil_key *bootuti
9797
static const uint8_t ec_pubkey_oid[] = MBEDTLS_OID_EC_ALG_UNRESTRICTED;
9898
static const uint8_t ec_secp256r1_oid[] = MBEDTLS_OID_EC_GRP_SECP256R1;
9999

100-
#define SHARED_KEY_LEN NUM_ECC_BYTES
101-
#define PRIV_KEY_LEN NUM_ECC_BYTES
102-
103100
/*
104101
* Parses the output of `imgtool keygen`, which produces a PKCS#8 elliptic
105102
* curve keypair. See RFC5208 and RFC5915.
@@ -179,9 +176,6 @@ parse_ec256_enckey(uint8_t **p, uint8_t *end, uint8_t *private_key)
179176
static const uint8_t ec_pubkey_oid[] = MBEDTLS_OID_ISO_IDENTIFIED_ORG \
180177
MBEDTLS_OID_ORG_GOV X25519_OID;
181178

182-
#define SHARED_KEY_LEN 32
183-
#define PRIV_KEY_LEN 32
184-
185179
static int
186180
parse_x25519_enckey(uint8_t **p, uint8_t *end, uint8_t *private_key)
187181
{
@@ -221,11 +215,11 @@ parse_x25519_enckey(uint8_t **p, uint8_t *end, uint8_t *private_key)
221215
return -7;
222216
}
223217

224-
if (len != PRIV_KEY_LEN) {
218+
if (len != EC_PRIVK_LEN) {
225219
return -8;
226220
}
227221

228-
memcpy(private_key, *p, PRIV_KEY_LEN);
222+
memcpy(private_key, *p, EC_PRIVK_LEN);
229223
return 0;
230224
}
231225
#endif /* defined(MCUBOOT_ENCRYPT_X25519) */
@@ -399,11 +393,11 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
399393
bootutil_hmac_sha256_context hmac;
400394
bootutil_aes_ctr_context aes_ctr;
401395
uint8_t tag[BOOTUTIL_CRYPTO_SHA256_DIGEST_SIZE];
402-
uint8_t shared[SHARED_KEY_LEN];
396+
uint8_t shared[EC_SHARED_LEN];
403397
uint8_t derived_key[BOOT_ENC_KEY_SIZE + BOOTUTIL_CRYPTO_SHA256_DIGEST_SIZE];
404398
uint8_t *cp;
405399
uint8_t *cpend;
406-
uint8_t private_key[PRIV_KEY_LEN];
400+
uint8_t private_key[EC_PRIVK_LEN];
407401
uint8_t counter[BOOT_ENC_BLOCK_SIZE];
408402
uint16_t len;
409403
#endif
@@ -509,7 +503,7 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
509503
*/
510504

511505
len = BOOT_ENC_KEY_SIZE + BOOTUTIL_CRYPTO_SHA256_DIGEST_SIZE;
512-
rc = hkdf(shared, SHARED_KEY_LEN, (uint8_t *)"MCUBoot_ECIES_v1", 16,
506+
rc = hkdf(shared, EC_SHARED_LEN, (uint8_t *)"MCUBoot_ECIES_v1", 16,
513507
derived_key, &len);
514508
if (rc != 0 || len != (BOOT_ENC_KEY_SIZE + BOOTUTIL_CRYPTO_SHA256_DIGEST_SIZE)) {
515509
return -1;

boot/bootutil/src/encrypted_psa.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ BOOT_LOG_MODULE_DECLARE(mcuboot_psa_enc);
3131
static const uint8_t ec_pubkey_oid[] = MBEDTLS_OID_ISO_IDENTIFIED_ORG \
3232
MBEDTLS_OID_ORG_GOV X25519_OID;
3333

34-
#define PRIV_KEY_LEN 32
35-
3634
/* Partitioning of HKDF derived material, from the exchange derived key */
3735
/* AES key encryption key */
3836
#define HKDF_AES_KEY_INDEX 0
@@ -83,11 +81,11 @@ parse_x25519_enckey(uint8_t **p, uint8_t *end, uint8_t *private_key)
8381
return -7;
8482
}
8583

86-
if (len != PRIV_KEY_LEN) {
84+
if (len != EC_PRIVK_LEN) {
8785
return -8;
8886
}
8987

90-
memcpy(private_key, *p, PRIV_KEY_LEN);
88+
memcpy(private_key, *p, EC_PRIVK_LEN);
9189
return 0;
9290
}
9391

@@ -117,7 +115,7 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
117115
uint8_t derived_key[HKDF_SIZE];
118116
uint8_t *cp;
119117
uint8_t *cpend;
120-
uint8_t private_key[PRIV_KEY_LEN];
118+
uint8_t private_key[EC_PRIVK_LEN];
121119
size_t len;
122120
psa_status_t psa_ret = PSA_ERROR_BAD_STATE;
123121
psa_status_t psa_cleanup_ret = PSA_ERROR_BAD_STATE;

0 commit comments

Comments
 (0)