Skip to content

Commit 3bb4d53

Browse files
authored
Merge pull request #396 from nasa/47-static-int32_t-sadb_sa_setarsn
[#47] Reworked setARSN to match SDLS-EP 3.3.3.7.3.4 exe…
2 parents 02d99d9 + dfc0d67 commit 3bb4d53

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

src/sa/internal/sa_interface_inmemory.template.c

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,21 +1569,8 @@ static int32_t sa_setARSN(TC_t *tc_frame)
15691569
// Check SPI exists
15701570
if (spi < NUM_SA)
15711571
{
1572-
if (sa[spi].shivf_len > 0 && sa[spi].ecs == 1 && sa[spi].acs == 1)
1573-
{ // Set IV - authenticated encryption
1574-
#ifdef PDU_DEBUG
1575-
printf("SPI %d IV updated to: 0x", spi);
1576-
#endif
1577-
for (x = 0; x < IV_SIZE; x++)
1578-
{
1579-
*(sa[spi].iv + x) = (uint8_t)sdls_frame.pdu.data[x + 2];
1580-
#ifdef PDU_DEBUG
1581-
printf("%02x", *(sa[spi].iv + x));
1582-
#endif
1583-
}
1584-
Crypto_increment(sa[spi].iv, sa[spi].shivf_len);
1585-
}
1586-
else
1572+
// Check if Auth or Auth Enc
1573+
if ((sa[spi].est == 1 && sa[spi].ast == 1) || sa[spi].ast == 1)
15871574
{ // Set SN
15881575
#ifdef PDU_DEBUG
15891576
printf("SPI %d ARSN updated to: 0x", spi);
@@ -1595,10 +1582,16 @@ static int32_t sa_setARSN(TC_t *tc_frame)
15951582
printf("%02x", *(sa[spi].arsn + x));
15961583
#endif
15971584
}
1598-
}
15991585
#ifdef PDU_DEBUG
16001586
printf("\n");
16011587
#endif
1588+
}
1589+
else
1590+
{
1591+
#ifdef PDU_DEBUG
1592+
printf("Failed setARSN on SPI %d, ECS %d, ACS %d\n", spi, sa[spi].ecs, sa[spi].acs);
1593+
#endif
1594+
}
16021595
}
16031596
else
16041597
{
@@ -1744,4 +1737,4 @@ int32_t sa_verify_data(SecurityAssociation_t *sa_ptr)
17441737
status = CRYPTO_LIB_ERR_SHPLF_LEN_GREATER_THAN_MAX_PAD_SIZE;
17451738
}
17461739
return status;
1747-
}
1740+
}

test/unit/ut_ep_sa_mgmt.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ UTEST(EP_SA_MGMT, SA_6_SET_ARSN)
283283
int status = CRYPTO_LIB_SUCCESS;
284284

285285
// NOTE: Added Transfer Frame header to the plaintext
286-
char *buffer_SET_h = "2003002800ff000000001880d0b10016197f0b001a000a000600000000000000000000006413b5983e55";
286+
char *buffer_SET_h = "2003002800ff000000001880d0b10016197f0b001a000a0007112233445566778899AABB6413b5983e55";
287287

288288
uint8_t *buffer_SET_b = NULL;
289289
int buffer_SET_len = 0;
@@ -306,21 +306,24 @@ UTEST(EP_SA_MGMT, SA_6_SET_ARSN)
306306
test_association->gvcid_blk.scid = SCID & 0x3FF;
307307

308308
// Modify SA 6
309-
sa_if->sa_get_from_spi(6, &test_association);
309+
sa_if->sa_get_from_spi(7, &test_association);
310310
test_association->sa_state = SA_OPERATIONAL;
311-
test_association->arsn_len = 16;
311+
test_association->arsn_len = 11;
312312

313313
// Convert frames that will be processed
314314
hex_conversion(buffer_SET_h, (char **)&buffer_SET_b, &buffer_SET_len);
315315

316316
status = Crypto_TC_ProcessSecurity(buffer_SET_b, &buffer_SET_len, &tc_nist_processed_frame);
317317
ASSERT_EQ(CRYPTO_LIB_SUCCESS, status);
318318

319-
sa_if->sa_get_from_spi(6, &test_association);
320-
319+
printf("SA %d ARSN: 0x", test_association->spi);
320+
for (int i = 0; i < test_association->arsn_len; i++)
321+
{
322+
printf("%02x", test_association->arsn[i]);
323+
}
321324
printf("\n");
322-
Crypto_Shutdown();
323325

326+
Crypto_Shutdown();
324327
free(buffer_SET_b);
325328
}
326329

0 commit comments

Comments
 (0)