@@ -45,15 +45,17 @@ int32_t Crypto_Key_OTAR(void)
45
45
int y ;
46
46
int32_t status = CRYPTO_LIB_SUCCESS ;
47
47
48
- int pdu_keys = ((sdls_frame .tlv_pdu .hdr .pdu_len /BYTE_LEN ) - SDLS_KEYID_LEN - SDLS_IV_LEN - MAC_SIZE ) / (SDLS_KEYID_LEN + SDLS_KEY_LEN );
48
+ int pdu_keys = ((sdls_frame .tlv_pdu .hdr .pdu_len / BYTE_LEN ) - SDLS_KEYID_LEN - SDLS_IV_LEN - MAC_SIZE ) /
49
+ (SDLS_KEYID_LEN + SDLS_KEY_LEN );
49
50
50
51
int w ;
51
- crypto_key_t * ekp = NULL ;
52
+ crypto_key_t * ekp = NULL ;
52
53
int expected_pdu_len = SDLS_KEYID_LEN + SDLS_IV_LEN + ((SDLS_KEYID_LEN + SDLS_KEY_LEN ) * pdu_keys ) + MAC_SIZE ;
53
54
#ifdef DEBUG
54
55
printf ("Expected PDU Length: %d (%d keys)\n" , expected_pdu_len , pdu_keys );
55
56
#endif
56
- if ((sdls_frame .tlv_pdu .hdr .pdu_len / BYTE_LEN ) < SDLS_KEYID_LEN + SDLS_IV_LEN + ((SDLS_KEYID_LEN + SDLS_KEY_LEN ) * pdu_keys ) + MAC_SIZE )
57
+ if ((sdls_frame .tlv_pdu .hdr .pdu_len / BYTE_LEN ) <
58
+ SDLS_KEYID_LEN + SDLS_IV_LEN + ((SDLS_KEYID_LEN + SDLS_KEY_LEN ) * pdu_keys ) + MAC_SIZE )
57
59
{
58
60
return CRYPTO_LIB_ERR_OTAR_BAD_TLV_LENGTH ;
59
61
}
@@ -93,7 +95,7 @@ int32_t Crypto_Key_OTAR(void)
93
95
#endif
94
96
}
95
97
96
- count = (sdls_frame .tlv_pdu .hdr .pdu_len / 8 ) - MAC_SIZE ;
98
+ count = (sdls_frame .tlv_pdu .hdr .pdu_len / 8 ) - MAC_SIZE ;
97
99
for (w = 0 ; w < MAC_SIZE ; w ++ )
98
100
{ // MAC
99
101
packet .mac [w ] = sdls_frame .tlv_pdu .data [count + w ];
@@ -117,7 +119,7 @@ int32_t Crypto_Key_OTAR(void)
117
119
118
120
uint8_t ecs = CRYPTO_CIPHER_AES256_GCM ; // Per SDLS baseline
119
121
status = cryptography_if -> cryptography_aead_decrypt (
120
- & (sdls_frame .tlv_pdu .data [14 ]), // plaintext output
122
+ & (sdls_frame .tlv_pdu .data [14 ]), // plaintext output
121
123
(size_t )(pdu_keys * (SDLS_KEYID_LEN + SDLS_KEY_LEN )), // length of data
122
124
NULL , // in place decryption
123
125
0 , // in data length
@@ -229,8 +231,8 @@ int32_t Crypto_Key_update(uint8_t state)
229
231
int32_t status ;
230
232
crypto_key_t * ekp = NULL ;
231
233
int x ;
232
- int pdu_length = sdls_frame .tlv_pdu .hdr .pdu_len / 8 ;
233
- int frame_length = sdls_frame .hdr .pkt_length ;
234
+ int pdu_length = sdls_frame .tlv_pdu .hdr .pdu_len / 8 ;
235
+ int frame_length = sdls_frame .hdr .pkt_length ;
234
236
235
237
if (key_if == NULL )
236
238
{
@@ -243,7 +245,8 @@ int32_t Crypto_Key_update(uint8_t state)
243
245
printf (KYEL "PDU Length not long enough to hold key values\n" RESET );
244
246
#endif
245
247
}
246
- if ((state == KEY_DEACTIVATED || state == KEY_ACTIVE ) && (pdu_length > SDLS_MAX_KEY_UPDATE_LEN || pdu_length > frame_length ))
248
+ if ((state == KEY_DEACTIVATED || state == KEY_ACTIVE ) &&
249
+ (pdu_length > SDLS_MAX_KEY_UPDATE_LEN || pdu_length > frame_length ))
247
250
{
248
251
#ifdef PDU_DEBUG
249
252
printf (KRED "PDU Length Exceded!\n" RESET );
@@ -260,7 +263,7 @@ int32_t Crypto_Key_update(uint8_t state)
260
263
{
261
264
#ifdef PDU_DEBUG
262
265
printf (KRED "\nMax key updates exceded, exiting...\n" RESET );
263
- #endif
266
+ #endif
264
267
return CRYPTO_LIB_ERROR ;
265
268
}
266
269
@@ -378,15 +381,17 @@ int32_t Crypto_Key_inventory(uint8_t *ingest)
378
381
}
379
382
380
383
// Read in PDU
381
- packet .kid_first = ((uint8_t )sdls_frame .tlv_pdu .data [count ] << BYTE_LEN ) | ((uint8_t )sdls_frame .tlv_pdu .data [count + 1 ]);
382
- count = count + 2 ;
383
- packet .kid_last = ((uint8_t )sdls_frame .tlv_pdu .data [count ] << BYTE_LEN ) | ((uint8_t )sdls_frame .tlv_pdu .data [count + 1 ]);
384
- count = count + 2 ;
384
+ packet .kid_first =
385
+ ((uint8_t )sdls_frame .tlv_pdu .data [count ] << BYTE_LEN ) | ((uint8_t )sdls_frame .tlv_pdu .data [count + 1 ]);
386
+ count = count + 2 ;
387
+ packet .kid_last =
388
+ ((uint8_t )sdls_frame .tlv_pdu .data [count ] << BYTE_LEN ) | ((uint8_t )sdls_frame .tlv_pdu .data [count + 1 ]);
389
+ count = count + 2 ;
385
390
386
391
// Prepare for Reply
387
- range = packet .kid_last - packet .kid_first + 1 ;
392
+ range = packet .kid_last - packet .kid_first + 1 ;
388
393
sdls_frame .tlv_pdu .hdr .pdu_len = (SDLS_KEY_INVENTORY_RPLY_SIZE * (range )) * BYTE_LEN ;
389
- sdls_frame .hdr .pkt_length = CCSDS_HDR_SIZE + ECSS_PUS_SIZE + SDLS_TLV_HDR_SIZE +
394
+ sdls_frame .hdr .pkt_length = CCSDS_HDR_SIZE + ECSS_PUS_SIZE + SDLS_TLV_HDR_SIZE +
390
395
(sdls_frame .tlv_pdu .hdr .pdu_len / BYTE_LEN ) - 1 +
391
396
2 ; // 2 = Num Keys Returned Field (2 Bytes)
392
397
count = Crypto_Prep_Reply (sdls_ep_reply , CRYPTOLIB_APPID );
@@ -427,7 +432,7 @@ int32_t Crypto_Key_verify(TC_t *tc_frame)
427
432
{
428
433
// Local variables
429
434
SDLS_KEYV_CMD_t packet ;
430
- int pdu_keys = (sdls_frame .tlv_pdu .hdr .pdu_len / 8 ) / SDLS_KEYV_CMD_BLK_SIZE ;
435
+ int pdu_keys = (sdls_frame .tlv_pdu .hdr .pdu_len / 8 ) / SDLS_KEYV_CMD_BLK_SIZE ;
431
436
int x ;
432
437
int y ;
433
438
uint16_t count = 0 ;
@@ -475,11 +480,12 @@ int32_t Crypto_Key_verify(TC_t *tc_frame)
475
480
{
476
481
sdls_frame .hdr .pkt_length =
477
482
CCSDS_HDR_SIZE + ECSS_PUS_SIZE + SDLS_TLV_HDR_SIZE + (sdls_frame .tlv_pdu .hdr .pdu_len / BYTE_LEN ) - 1 ;
478
- printf ("NO PUS: sdls_frame.hdr.pkt_length Calced as %d\n" , sdls_frame .hdr .pkt_length );
483
+ printf ("NO PUS: sdls_frame.hdr.pkt_length Calced as %d\n" , sdls_frame .hdr .pkt_length );
479
484
}
480
485
else
481
486
{
482
- sdls_frame .hdr .pkt_length = CCSDS_HDR_SIZE + SDLS_TLV_HDR_SIZE + (sdls_frame .tlv_pdu .hdr .pdu_len / BYTE_LEN ) - 1 ;
487
+ sdls_frame .hdr .pkt_length =
488
+ CCSDS_HDR_SIZE + SDLS_TLV_HDR_SIZE + (sdls_frame .tlv_pdu .hdr .pdu_len / BYTE_LEN ) - 1 ;
483
489
printf ("WITH PUS: sdls_frame.hdr.pkt_length Calced as %d\n" , sdls_frame .hdr .pkt_length );
484
490
}
485
491
@@ -491,10 +497,10 @@ int32_t Crypto_Key_verify(TC_t *tc_frame)
491
497
// Key ID
492
498
sdls_ep_keyv_reply .blk [x ].kid = packet .blk [x ].kid ;
493
499
494
- sdls_ep_reply [pdu_data_idx ] = (packet .blk [x ].kid & 0xFF00 ) >> BYTE_LEN ;
500
+ sdls_ep_reply [pdu_data_idx ] = (packet .blk [x ].kid & 0xFF00 ) >> BYTE_LEN ;
495
501
pdu_data_idx += 1 ;
496
502
497
- sdls_ep_reply [pdu_data_idx ] = (packet .blk [x ].kid & 0x00FF );
503
+ sdls_ep_reply [pdu_data_idx ] = (packet .blk [x ].kid & 0x00FF );
498
504
pdu_data_idx += 1 ;
499
505
count += 2 ;
500
506
@@ -508,14 +514,14 @@ int32_t Crypto_Key_verify(TC_t *tc_frame)
508
514
// Initialization Vector
509
515
for (y = 0 ; y < SDLS_IV_LEN ; y ++ )
510
516
{
511
- sdls_ep_keyv_reply .blk [x ].iv [y ] = 0x00 ; //= *(tc_frame->tc_sec_header.iv + y);
512
- sdls_ep_reply [pdu_data_idx ] = 0x00 ; //= *(tc_frame->tc_sec_header.iv + y);
517
+ sdls_ep_keyv_reply .blk [x ].iv [y ] = 0x00 ; //= *(tc_frame->tc_sec_header.iv + y);
518
+ sdls_ep_reply [pdu_data_idx ] = 0x00 ; //= *(tc_frame->tc_sec_header.iv + y);
513
519
pdu_data_idx += 1 ;
514
520
count += 1 ;
515
521
}
516
522
// ***** This increments the lowest bytes of the IVs so they aren't identical
517
- sdls_ep_keyv_reply .blk [x ].iv [SDLS_IV_LEN - 1 ] = sdls_ep_keyv_reply .blk [x ].iv [SDLS_IV_LEN - 1 ] + x + 1 ;
518
- sdls_ep_reply [pdu_data_idx - 1 ] = sdls_ep_reply [pdu_data_idx - 1 ] + x + 1 ;
523
+ sdls_ep_keyv_reply .blk [x ].iv [SDLS_IV_LEN - 1 ] = sdls_ep_keyv_reply .blk [x ].iv [SDLS_IV_LEN - 1 ] + x + 1 ;
524
+ sdls_ep_reply [pdu_data_idx - 1 ] = sdls_ep_reply [pdu_data_idx - 1 ] + x + 1 ;
519
525
520
526
// Encrypt challenge
521
527
uint8_t ecs = CRYPTO_CIPHER_AES256_GCM ;
0 commit comments