Skip to content

Commit 1acbc5a

Browse files
authored
Merge pull request #400 from nasa/150-conditional-error-code-review
150 conditional error code review
2 parents 7bc238b + 0111688 commit 1acbc5a

File tree

6 files changed

+24
-13
lines changed

6 files changed

+24
-13
lines changed

include/crypto.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ uint16_t Crypto_Calc_CRC16(uint8_t *data, int size);
245245
int32_t Crypto_Check_Anti_Replay(SecurityAssociation_t *sa_ptr, uint8_t *arsn, uint8_t *iv);
246246
int32_t Crypto_Get_ECS_Algo_Keylen(uint8_t algo);
247247
int32_t Crypto_Get_ACS_Algo_Keylen(uint8_t algo);
248+
uint8_t Crypto_Is_ACS_Only_Algo(uint8_t algo);
248249

249250
int32_t Crypto_Check_Anti_Replay_Verify_Pointers(SecurityAssociation_t *sa_ptr, uint8_t *arsn, uint8_t *iv);
250251
int32_t Crypto_Check_Anti_Replay_ARSNW(SecurityAssociation_t *sa_ptr, uint8_t *arsn, int8_t *arsn_valid);

include/crypto_config_structs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ typedef enum
184184
CRYPTO_MAC_NONE,
185185
CRYPTO_MAC_CMAC_AES256,
186186
CRYPTO_MAC_HMAC_SHA256,
187-
CRYPTO_MAC_HMAC_SHA512
187+
CRYPTO_MAC_HMAC_SHA512,
188+
CRYPTO_ACS_MAX = 3
188189
} AuthCipherSuite;
189190
typedef enum
190191
{

src/core/crypto.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ uint8_t Crypto_Is_AEAD_Algorithm(uint32_t cipher_suite_id)
122122
return status;
123123
}
124124

125+
/**
126+
* @brief Function: Crypto_Is_ACS_Only_Algo
127+
* Looks up cipher suite ID and determines if it's an ACS algorithm. Returns 1 if true, 0 if false;
128+
* @param cipher_suite_id: uint8_t
129+
* @return int: Success/Failure
130+
**/
131+
uint8_t Crypto_Is_ACS_Only_Algo(uint8_t algo)
132+
{
133+
if (algo > 0 && algo <= CRYPTO_ACS_MAX)
134+
{
135+
return CRYPTO_TRUE;
136+
}
137+
return CRYPTO_FALSE;
138+
}
139+
125140
/**
126141
* @brief Function: Crypto_increment
127142
* Increments the bytes within a uint8_t array

src/core/crypto_aos.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,9 @@ int32_t Crypto_AOS_ApplySecurity(uint8_t *pTfBuffer)
243243

244244
if (sa_ptr->est == 0 && sa_ptr->ast == 1)
245245
{
246-
if (sa_ptr->acs_len != 0)
246+
if (sa_ptr->acs_len > 0)
247247
{
248-
if ((sa_ptr->acs == CRYPTO_MAC_CMAC_AES256 || sa_ptr->acs == CRYPTO_MAC_HMAC_SHA256 ||
249-
sa_ptr->acs == CRYPTO_MAC_HMAC_SHA512) &&
250-
sa_ptr->iv_len > 0)
248+
if (Crypto_Is_ACS_Only_Algo(sa_ptr->acs) && sa_ptr->iv_len > 0)
251249
{
252250
status = CRYPTO_LIB_ERR_IV_NOT_SUPPORTED_FOR_ACS_ALGO;
253251
mc_if->mc_log(status);

src/core/crypto_tc.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,9 @@ int32_t Crypto_TC_ACS_Algo_Check(SecurityAssociation_t *sa_ptr)
263263
int32_t status = CRYPTO_LIB_SUCCESS;
264264
if ((sa_ptr->est == 0) && (sa_ptr->ast == 1))
265265
{
266-
if (sa_ptr->acs_len != 0)
266+
if (sa_ptr->acs_len > 0)
267267
{
268-
if ((sa_ptr->acs == CRYPTO_MAC_CMAC_AES256 || sa_ptr->acs == CRYPTO_MAC_HMAC_SHA256 ||
269-
sa_ptr->acs == CRYPTO_MAC_HMAC_SHA512) &&
270-
sa_ptr->iv_len > 0)
268+
if (Crypto_Is_ACS_Only_Algo(sa_ptr->acs) && sa_ptr->iv_len > 0)
271269
{
272270
status = CRYPTO_LIB_ERR_IV_NOT_SUPPORTED_FOR_ACS_ALGO;
273271
mc_if->mc_log(status);

src/core/crypto_tm.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,9 @@ int32_t Crypto_TM_IV_Sanity_Check(uint8_t *sa_service_type, SecurityAssociation_
161161

162162
if (sa_ptr->est == 0 && sa_ptr->ast == 1)
163163
{
164-
if (sa_ptr->acs_len != 0)
164+
if (sa_ptr->acs_len > 0)
165165
{
166-
if ((sa_ptr->acs == CRYPTO_MAC_CMAC_AES256 || sa_ptr->acs == CRYPTO_MAC_HMAC_SHA256 ||
167-
sa_ptr->acs == CRYPTO_MAC_HMAC_SHA512) &&
168-
sa_ptr->iv_len > 0)
166+
if (Crypto_Is_ACS_Only_Algo(sa_ptr->acs) && sa_ptr->iv_len > 0)
169167
{
170168
status = CRYPTO_LIB_ERR_IV_NOT_SUPPORTED_FOR_ACS_ALGO;
171169
mc_if->mc_log(status);

0 commit comments

Comments
 (0)