Skip to content

Commit 51a71a6

Browse files
authored
Merge pull request #339 from nasa/44-crypto_key_otar---fixed-iv-length
[#44] Removed magic numbers from OTAR
2 parents 8d3401c + ce995e2 commit 51a71a6

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

include/crypto_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@
210210
#define SDLS_IV_LEN 12 /* bytes */
211211
#define SDLS_KEYV_KEY_ID_LEN 2 /* bytes */
212212
#define SDLS_KEY_LEN 32 /* bytes */
213+
#define SDLS_KEYID_LEN 2 /* bytes */
213214

214215
// TC Behavior Defines
215216
#define TC_SDLS_EP_VCID \

src/core/crypto_key_mgmt.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ int32_t Crypto_Key_OTAR(void)
4545
int y;
4646
int32_t status = CRYPTO_LIB_SUCCESS;
4747
// uint16_t pdu_len = (uint16_t) sdls_frame.pdu.hdr.pdu_len[1] << 8 | sdls_frame.pdu.hdr.pdu_len[0];
48-
int pdu_keys = (sdls_frame.pdu.hdr.pdu_len - 30) / (2 + 32);
48+
int pdu_keys = (sdls_frame.pdu.hdr.pdu_len - SDLS_KEYID_LEN - SDLS_IV_LEN - MAC_SIZE) / (SDLS_KEYID_LEN + SDLS_KEY_LEN);
4949
int w;
5050
crypto_key_t *ekp = NULL;
5151

@@ -76,7 +76,7 @@ int32_t Crypto_Key_OTAR(void)
7676
return status;
7777
}
7878

79-
for (count = 2; count < (2 + 12); count++)
79+
for (count = 2; count < (2 + SDLS_IV_LEN); count++)
8080
{ // Initialization Vector
8181
packet.iv[count - 2] = sdls_frame.pdu.data[count];
8282
#ifdef DEBUG
@@ -85,7 +85,7 @@ int32_t Crypto_Key_OTAR(void)
8585
}
8686

8787
count = sdls_frame.pdu.hdr.pdu_len - MAC_SIZE;
88-
for (w = 0; w < 16; w++)
88+
for (w = 0; w < MAC_SIZE; w++)
8989
{ // MAC
9090
packet.mac[w] = sdls_frame.pdu.data[count + w];
9191
#ifdef DEBUG
@@ -101,7 +101,7 @@ int32_t Crypto_Key_OTAR(void)
101101

102102
uint8_t ecs = CRYPTO_CIPHER_AES256_GCM;
103103
status = cryptography_if->cryptography_aead_decrypt(&(sdls_frame.pdu.data[14]), // plaintext output
104-
(size_t)(pdu_keys * (2 + SDLS_KEY_LEN)), // length of data
104+
(size_t)(pdu_keys * (SDLS_KEYID_LEN + SDLS_KEY_LEN)), // length of data
105105
NULL, // in place decryption
106106
0, // in data length
107107
&(ekp->value[0]), // key

0 commit comments

Comments
 (0)