Skip to content

Commit c9109bd

Browse files
authored
Merge pull request #504 from nasa/dev
RC v1.5.0
2 parents 9ffda0f + 2a237a3 commit c9109bd

45 files changed

Lines changed: 2830 additions & 2249 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
repository: NASA-AMMOS/DCS
7474
path: DCS
7575
submodules: recursive
76-
ref: main
76+
ref: dev
7777
- name: setup python
7878
uses: actions/setup-python@v5
7979
with:

include/crypto.h

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@
5050
** Crypto Version
5151
*/
5252
#define CRYPTO_LIB_MAJOR_VERSION 1
53-
#define CRYPTO_LIB_MINOR_VERSION 4
54-
#define CRYPTO_LIB_REVISION 3
53+
#define CRYPTO_LIB_MINOR_VERSION 5
54+
#define CRYPTO_LIB_REVISION 0
5555
#define CRYPTO_LIB_MISSION_REV 0
5656

57-
#define GVCID_MAX_PARAM_SIZE 250
57+
#define GVCID_MAX_PARAM_SIZE 100
5858
#define CRC32TBL_SIZE 256
5959
#define CRC16TBL_SIZE 256
6060

@@ -65,10 +65,15 @@ uint8_t Crypto_gf_mul(uint8_t a, uint8_t b);
6565

6666
// Crypto Library Configuration functions
6767
extern int32_t Crypto_Config_CryptoLib(uint8_t key_type, uint8_t mc_type, uint8_t sa_type, uint8_t cryptography_type,
68-
uint8_t iv_type, uint8_t crypto_create_fecf, uint8_t process_sdls_pdus,
69-
uint8_t has_pus_hdr, uint8_t ignore_sa_state, uint8_t ignore_anti_replay,
70-
uint8_t unique_sa_per_mapid, uint8_t crypto_check_fecf, uint8_t vcid_bitmask,
71-
uint8_t crypto_increment_nontransmitted_iv);
68+
uint8_t iv_type);
69+
extern int32_t Crypto_Config_TC(uint8_t crypto_create_fecf, uint8_t process_sdls_pdus, uint8_t has_pus_hdr,
70+
uint8_t ignore_anti_replay, uint8_t ignore_sa_state, uint8_t unique_sa_per_mapid,
71+
uint8_t crypto_check_fecf, uint8_t vcid_bitmask,
72+
uint8_t crypto_increment_nontransmitted_iv);
73+
extern int32_t Crypto_Config_TM(uint8_t crypto_create_fecf, uint8_t ignore_anti_replay, uint8_t crypto_check_fecf,
74+
uint8_t vcid_bitmask, uint8_t crypto_increment_nontransmitted_iv);
75+
extern int32_t Crypto_Config_AOS(uint8_t crypto_create_fecf, uint8_t ignore_anti_replay, uint8_t crypto_check_fecf,
76+
uint8_t vcid_bitmask, uint8_t crypto_increment_nontransmitted_iv);
7277
extern int32_t Crypto_Config_MariaDB(char *mysql_hostname, char *mysql_database, uint16_t mysql_port,
7378
uint8_t mysql_require_secure_transport, uint8_t mysql_tls_verify_server,
7479
char *mysql_tls_ca, char *mysql_tls_capath, char *mysql_mtls_cert,
@@ -81,11 +86,13 @@ extern int32_t Crypto_Config_Kmc_Crypto_Service(char *protocol, char *kmc_crypto
8186
char *mtls_client_key_pass, char *mtls_issuer_cert);
8287
extern int32_t Crypto_Config_Cam(uint8_t cam_enabled, char *cookie_file_path, char *keytab_file_path,
8388
uint8_t login_method, char *access_manager_uri, char *username, char *cam_home);
84-
extern int32_t Crypto_Config_Add_Gvcid_Managed_Parameters(GvcidManagedParameters_t mp_struct);
89+
extern int32_t Crypto_Config_Add_TC_Gvcid_Managed_Parameters(TCGvcidManagedParameters_t mp_struct);
90+
extern int32_t Crypto_Config_Add_TM_Gvcid_Managed_Parameters(TMGvcidManagedParameters_t mp_struct);
91+
extern int32_t Crypto_Config_Add_AOS_Gvcid_Managed_Parameters(AOSGvcidManagedParameters_t mp_struct);
8592
// Initialization
8693
extern int32_t Crypto_Init(void); // Initialize CryptoLib After Configuration Calls
8794
extern int32_t Crypto_Init_With_Configs(
88-
CryptoConfig_t *crypto_config_p, GvcidManagedParameters_t *gvcid_managed_parameters_p,
95+
CryptoConfigGlobal_t *crypto_config_p, TCGvcidManagedParameters_t *gvcid_managed_parameters_p,
8996
SadbMariaDBConfig_t *sa_mariadb_config_p,
9097
CryptographyKmcCryptoServiceConfig_t
9198
*cryptography_kmc_crypto_config_p); // Initialize CryptoLib With Application Defined Configuration
@@ -128,7 +135,7 @@ void Crypto_TC_Get_Ciper_Mode_TCP(uint8_t sa_service_type, uint32_t *encryption_
128135
SecurityAssociation_t *sa_ptr);
129136
int32_t Crypto_TC_Get_Ciper_Mode_TCA(uint8_t sa_service_type, uint32_t *encryption_cipher,
130137
uint8_t *ecs_is_aead_algorithm, SecurityAssociation_t *sa_ptr);
131-
void Crypto_TC_Calc_Lengths(uint8_t *fecf_len, uint8_t *segment_hdr_len, uint8_t *ocf_len);
138+
void Crypto_TC_Calc_Lengths(uint8_t *fecf_len, uint8_t *segment_hdr_len);
132139
void Crypto_TC_Set_Segment_Header(TC_t *tc_sdls_processed_frame, uint8_t *ingest, int *byte_idx);
133140
int32_t Crypto_TC_Check_CMD_Frame_Flag(uint8_t header_cc);
134141
int32_t Crypto_TC_Validate_SA_Service_Type(uint8_t sa_service_type);
@@ -185,6 +192,9 @@ extern char *Crypto_Get_Error_Code_Enum_String(int32_t crypto_error_code);
185192
int32_t Crypto_Get_Security_Header_Length(SecurityAssociation_t *sa_ptr);
186193
int32_t Crypto_Get_Security_Trailer_Length(SecurityAssociation_t *sa_ptr);
187194

195+
int32_t crypto_handle_incrementing_nontransmitted_counter(uint8_t *dest, uint8_t *src, int src_full_len,
196+
int transmitted_len, int window);
197+
188198
/*
189199
** Internal Prototypes
190200
*/
@@ -245,14 +255,16 @@ uint16_t Crypto_Calc_FECF(const uint8_t *ingest, int len_ingest);
245255
uint16_t Crypto_Calc_FHECF(uint8_t *data);
246256
int32_t Crypto_Calc_CRC_Init_Table(void);
247257
uint16_t Crypto_Calc_CRC16(uint8_t *data, int size);
248-
int32_t Crypto_Check_Anti_Replay(SecurityAssociation_t *sa_ptr, uint8_t *arsn, uint8_t *iv);
258+
int32_t Crypto_Check_Anti_Replay(SecurityAssociation_t *sa_ptr, uint8_t *arsn, uint8_t *iv,
259+
uint8_t increment_nontransmitted);
249260
int32_t Crypto_Get_ECS_Algo_Keylen(uint8_t algo);
250261
int32_t Crypto_Get_ACS_Algo_Keylen(uint8_t algo);
251262
uint8_t Crypto_Is_ACS_Only_Algo(uint8_t algo);
252263

253264
int32_t Crypto_Check_Anti_Replay_Verify_Pointers(SecurityAssociation_t *sa_ptr, uint8_t *arsn, uint8_t *iv);
254265
int32_t Crypto_Check_Anti_Replay_ARSNW(SecurityAssociation_t *sa_ptr, uint8_t *arsn, int8_t *arsn_valid);
255-
int32_t Crypto_Check_Anti_Replay_GCM(SecurityAssociation_t *sa_ptr, uint8_t *iv, int8_t *iv_valid);
266+
int32_t Crypto_Check_Anti_Replay_GCM(SecurityAssociation_t *sa_ptr, uint8_t *iv, int8_t *iv_valid,
267+
uint8_t increment_nontransmitted);
256268

257269
// SDLS Related Functions
258270
extern uint8_t Crypto_Prep_Reply(uint8_t *ingest, uint8_t appID);
@@ -300,9 +312,15 @@ int32_t Crypto_SEC_MON_CTRL(uint8_t *ingest);
300312
int32_t Crypto_USER_DEFINED_CMD(uint8_t *ingest);
301313

302314
// Managed Parameter Functions
303-
int32_t Crypto_Get_Managed_Parameters_For_Gvcid(uint8_t tfvn, uint16_t scid, uint8_t vcid,
304-
GvcidManagedParameters_t *managed_parameters_in,
305-
GvcidManagedParameters_t *managed_parameters_out);
315+
int32_t Crypto_Get_TC_Managed_Parameters_For_Gvcid(uint8_t tfvn, uint16_t scid, uint8_t vcid,
316+
TCGvcidManagedParameters_t *managed_parameters_in,
317+
TCGvcidManagedParameters_t *managed_parameters_out);
318+
int32_t Crypto_Get_TM_Managed_Parameters_For_Gvcid(uint8_t tfvn, uint16_t scid, uint8_t vcid,
319+
TMGvcidManagedParameters_t *managed_parameters_in,
320+
TMGvcidManagedParameters_t *managed_parameters_out);
321+
int32_t Crypto_Get_AOS_Managed_Parameters_For_Gvcid(uint8_t tfvn, uint16_t scid, uint8_t vcid,
322+
AOSGvcidManagedParameters_t *managed_parameters_in,
323+
AOSGvcidManagedParameters_t *managed_parameters_out);
306324
// Project-wide support functions
307325
extern int32_t crypto_deep_copy_string(char *src_string, char **dst_string);
308326

@@ -327,27 +345,30 @@ extern AOS_FrameSecurityHeader_t aos_frame_sec_hdr; // Used to reduce bit math d
327345
extern uint8_t parity[4]; // Used in FHECF calc
328346

329347
// Global configuration structs
330-
extern CryptoConfig_t crypto_config;
348+
extern CryptoConfigGlobal_t crypto_config_global;
349+
extern CryptoConfigTC_t crypto_config_tc;
350+
extern CryptoConfigTM_t crypto_config_tm;
351+
extern CryptoConfigAOS_t crypto_config_aos;
331352
extern SadbMariaDBConfig_t *sa_mariadb_config;
332-
extern char *mariadb_table_name;
353+
extern char mariadb_table_name[26];
333354
extern CryptographyKmcCryptoServiceConfig_t *cryptography_kmc_crypto_config;
334355
extern CamConfig_t *cam_config;
335-
extern GvcidManagedParameters_t *gvcid_managed_parameters;
336-
extern GvcidManagedParameters_t *current_managed_parameters;
337-
extern GvcidManagedParameters_t gvcid_managed_parameters_array[GVCID_MAX_PARAM_SIZE];
338-
extern GvcidManagedParameters_t tc_current_managed_parameters_struct;
339-
extern GvcidManagedParameters_t tm_current_managed_parameters_struct;
340-
extern GvcidManagedParameters_t aos_current_managed_parameters_struct;
341-
extern int gvcid_counter;
356+
extern TCGvcidManagedParameters_t tc_gvcid_managed_parameters_array[GVCID_MAX_PARAM_SIZE];
357+
extern TMGvcidManagedParameters_t tm_gvcid_managed_parameters_array[GVCID_MAX_PARAM_SIZE];
358+
extern AOSGvcidManagedParameters_t aos_gvcid_managed_parameters_array[GVCID_MAX_PARAM_SIZE];
359+
extern TCGvcidManagedParameters_t tc_current_managed_parameters_struct;
360+
extern TMGvcidManagedParameters_t tm_current_managed_parameters_struct;
361+
extern AOSGvcidManagedParameters_t aos_current_managed_parameters_struct;
362+
extern int tc_gvcid_counter;
363+
extern int tm_gvcid_counter;
364+
extern int aos_gvcid_counter;
342365
extern KeyInterface key_if;
343366
extern McInterface mc_if;
344367
extern SaInterface sa_if;
345368
extern CryptographyInterface cryptography_if;
346369

347370
// extern crypto_key_t ak_ring[NUM_KEYS];
348-
extern SadbMariaDBConfig_t *sa_mariadb_config;
349-
extern GvcidManagedParameters_t *gvcid_managed_parameters;
350-
extern GvcidManagedParameters_t *current_managed_parameters;
371+
extern SadbMariaDBConfig_t *sa_mariadb_config;
351372

352373
// OCF
353374
extern uint8_t ocf;

include/crypto_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#endif
4343

4444
// Managed Parameters Size
45-
#define GVCID_MAN_PARAM_SIZE 250
45+
#define GVCID_MAN_PARAM_SIZE 100
4646

4747
// Max Frame Size
4848
#define TC_MAX_FRAME_SIZE 1024

include/crypto_config_structs.h

Lines changed: 86 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,38 +29,39 @@ ivv-itc@lists.nasa.gov
2929
// main config enums
3030
typedef enum
3131
{
32-
UNITIALIZED = 0,
32+
UNINITIALIZED = 0,
3333
INITIALIZED
3434
} InitStatus;
3535
typedef enum
3636
{
37-
KEY_TYPE_UNITIALIZED = 0,
37+
KEY_TYPE_UNINITIALIZED = 0,
3838
KEY_TYPE_CUSTOM,
3939
KEY_TYPE_INTERNAL,
4040
KEY_TYPE_KMC
4141
} KeyType;
4242
typedef enum
4343
{
44-
MC_TYPE_UNITIALIZED = 0,
44+
MC_TYPE_UNINITIALIZED = 0,
4545
MC_TYPE_CUSTOM,
4646
MC_TYPE_DISABLED,
4747
MC_TYPE_INTERNAL
4848
} McType;
4949
typedef enum
5050
{
51-
SA_TYPE_UNITIALIZED = 0,
51+
SA_TYPE_UNINITIALIZED = 0,
5252
SA_TYPE_CUSTOM,
5353
SA_TYPE_INMEMORY,
5454
SA_TYPE_MARIADB
5555
} SadbType;
5656
typedef enum
5757
{
58-
CRYPTOGRAPHY_TYPE_UNITIALIZED = 0,
58+
CRYPTOGRAPHY_TYPE_UNINITIALIZED = 0,
5959
CRYPTOGRAPHY_TYPE_LIBGCRYPT,
6060
CRYPTOGRAPHY_TYPE_KMCCRYPTO,
6161
CRYPTOGRAPHY_TYPE_WOLFSSL,
6262
CRYPTOGRAPHY_TYPE_CUSTOM
6363
} CryptographyType;
64+
6465
/***************************************
6566
** GVCID Managed Parameter enums
6667
****************************************/
@@ -89,19 +90,17 @@ typedef enum
8990
} CreateFecfBool;
9091
typedef enum
9192
{
92-
AOS_FHEC_NA = 0,
93-
AOS_NO_FHEC,
93+
AOS_NO_FHEC = 0,
9494
AOS_HAS_FHEC
9595
} AosFhecPresent;
9696
typedef enum
9797
{
98-
AOS_IZ_NA,
99-
AOS_NO_IZ,
98+
AOS_NO_IZ = 0,
10099
AOS_HAS_IZ
101100
} AosInsertZonePresent;
102101
typedef enum
103102
{
104-
TC_CHECK_FECF_FALSE,
103+
TC_CHECK_FECF_FALSE = 0,
105104
TC_CHECK_FECF_TRUE,
106105
TM_CHECK_FECF_FALSE,
107106
TM_CHECK_FECF_TRUE,
@@ -110,7 +109,7 @@ typedef enum
110109
} CheckFecfBool;
111110
typedef enum
112111
{
113-
AOS_NO_OCF,
112+
AOS_NO_OCF = 0,
114113
AOS_HAS_OCF,
115114
TC_OCF_NA,
116115
TM_NO_OCF,
@@ -143,9 +142,13 @@ typedef enum
143142
} TcIgnoreSaState;
144143
typedef enum
145144
{
146-
TC_IGNORE_ANTI_REPLAY_FALSE,
147-
TC_IGNORE_ANTI_REPLAY_TRUE
148-
} TcIgnoreAntiReplay;
145+
TC_IGNORE_ANTI_REPLAY_FALSE = 0,
146+
TC_IGNORE_ANTI_REPLAY_TRUE,
147+
TM_IGNORE_ANTI_REPLAY_FALSE,
148+
TM_IGNORE_ANTI_REPLAY_TRUE,
149+
AOS_IGNORE_ANTI_REPLAY_FALSE,
150+
AOS_IGNORE_ANTI_REPLAY_TRUE,
151+
} IgnoreAntiReplay;
149152
typedef enum
150153
{
151154
TC_UNIQUE_SA_PER_MAP_ID_FALSE,
@@ -207,37 +210,94 @@ typedef struct
207210
McType mc_type;
208211
SadbType sa_type;
209212
CryptographyType cryptography_type;
210-
IvType iv_type; // Whether or not CryptoLib should generate the IV
211-
CreateFecfBool crypto_create_fecf; // Whether or not CryptoLib is expected to calculate TC FECFs and return
213+
IvType iv_type; // Whether or not CryptoLib should generate the IV
214+
} __attribute__((packed)) CryptoConfigGlobal_t;
215+
#define CRYPTO_GLOBAL_CONFIG_SIZE (sizeof(CryptoConfigGlobal_t))
216+
217+
typedef struct
218+
{
219+
InitStatus init_status;
220+
CreateFecfBool crypto_create_fecf; // Whether or not CryptoLib is expected to calculate TC FECFs and return
212221
// payloads with the FECF
213222
TcProcessSdlsPdus process_sdls_pdus; // Config to process SDLS extended procedure PDUs in CryptoLib
214-
TcPusHdrPresent has_pus_hdr;
215-
TcIgnoreSaState ignore_sa_state; // TODO - add logic that uses this configuration
216-
TcIgnoreAntiReplay ignore_anti_replay;
223+
TcPusHdrPresent has_pus_hdr; // For ESA Testing
224+
IgnoreAntiReplay ignore_anti_replay;
225+
TcIgnoreSaState ignore_sa_state;
217226
TcUniqueSaPerMapId unique_sa_per_mapid;
218227
CheckFecfBool crypto_check_fecf;
219228
uint8_t vcid_bitmask;
220229
uint8_t crypto_increment_nontransmitted_iv; // Whether or not CryptoLib increments the non-transmitted portion of
221230
// the IV field
222-
} CryptoConfig_t;
223-
#define CRYPTO_CONFIG_SIZE (sizeof(CryptoConfig_t))
231+
} __attribute__((packed)) CryptoConfigTC_t;
232+
#define CRYPTO_TC_CONFIG_SIZE (sizeof(CryptoConfigTC_t))
233+
234+
typedef struct
235+
{
236+
InitStatus init_status;
237+
CreateFecfBool crypto_create_fecf; // Whether or not CryptoLib is expected to calculate TC FECFs and return
238+
// payloads with the FECF
239+
IgnoreAntiReplay ignore_anti_replay;
240+
CheckFecfBool crypto_check_fecf;
241+
uint8_t vcid_bitmask;
242+
uint8_t crypto_increment_nontransmitted_iv; // Whether or not CryptoLib increments the non-transmitted portion of
243+
// the IV field
244+
} __attribute__((packed)) CryptoConfigTM_t;
245+
#define CRYPTO_TM_CONFIG_SIZE (sizeof(CryptoConfigTM_t))
224246

225-
typedef struct _GvcidManagedParameters_t GvcidManagedParameters_t;
226-
struct _GvcidManagedParameters_t
247+
typedef struct
248+
{
249+
InitStatus init_status;
250+
CreateFecfBool crypto_create_fecf; // Whether or not CryptoLib is expected to calculate TC FECFs and return
251+
// payloads with the FECF
252+
IgnoreAntiReplay ignore_anti_replay;
253+
CheckFecfBool crypto_check_fecf;
254+
uint8_t vcid_bitmask;
255+
uint8_t crypto_increment_nontransmitted_iv; // Whether or not CryptoLib increments the non-transmitted portion of
256+
// the IV field
257+
} __attribute__((packed)) CryptoConfigAOS_t;
258+
#define CRYPTO_AOS_CONFIG_SIZE (sizeof(CryptoConfigAOS_t))
259+
260+
typedef struct _TCGvcidManagedParameters_t TCGvcidManagedParameters_t;
261+
struct _TCGvcidManagedParameters_t
227262
{
228263
uint8_t tfvn : 4; // Transfer Frame Version Number
229264
uint16_t scid : 10; // SpacecraftID
230265
uint8_t vcid : 6; // Virtual Channel ID
231266
FecfPresent has_fecf;
267+
TcSegmentHdrsPresent has_segmentation_hdr;
268+
uint16_t max_frame_size; // Maximum TC/TM Frame Length with headers
269+
int set_flag;
270+
} __attribute__((packed));
271+
#define TC_GVCID_MANAGED_PARAMETERS_SIZE (sizeof(TCGvcidManagedParameters_t))
272+
273+
typedef struct _TMGvcidManagedParameters_t TMGvcidManagedParameters_t;
274+
struct _TMGvcidManagedParameters_t
275+
{
276+
uint8_t tfvn : 2; // Transfer Frame Version Number
277+
uint16_t scid : 10; // SpacecraftID
278+
uint8_t vcid : 3; // Virtual Channel ID
279+
FecfPresent has_fecf;
280+
uint16_t max_frame_size; // Maximum TC/TM Frame Length with headers
281+
OcfPresent has_ocf;
282+
int set_flag;
283+
} __attribute__((packed));
284+
#define TM_GVCID_MANAGED_PARAMETERS_SIZE (sizeof(TMGvcidManagedParameters_t))
285+
286+
typedef struct _AOSGvcidManagedParameters_t AOSGvcidManagedParameters_t;
287+
struct _AOSGvcidManagedParameters_t
288+
{
289+
uint8_t tfvn : 2; // Transfer Frame Version Number
290+
uint8_t scid : 8; // SpacecraftID
291+
uint8_t vcid : 6; // Virtual Channel ID
292+
FecfPresent has_fecf;
232293
AosFhecPresent aos_has_fhec;
233294
AosInsertZonePresent aos_has_iz;
234295
uint16_t aos_iz_len;
235-
TcSegmentHdrsPresent has_segmentation_hdr;
236296
uint16_t max_frame_size; // Maximum TC/TM Frame Length with headers
237297
OcfPresent has_ocf;
238298
int set_flag;
239-
};
240-
#define GVCID_MANAGED_PARAMETERS_SIZE (sizeof(GvcidManagedParameters_t))
299+
} __attribute__((packed));
300+
#define AOS_GVCID_MANAGED_PARAMETERS_SIZE (sizeof(AOSGvcidManagedParameters_t))
241301

242302
/*
243303
** SaDB MariaDB Configuration Block

include/crypto_print.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,6 @@ void Crypto_binprint(void *c, size_t n);
100100
* @param managed_parameters: GvcidManagedParameters_t*, The binary array to be printed.
101101
* @param print_children: uint8_t, The size of the array to be printed.
102102
**/
103-
void Crypto_mpPrint(GvcidManagedParameters_t *managed_parameters, uint8_t print_children);
103+
// void Crypto_mpPrint(GvcidManagedParameters_t *managed_parameters, uint8_t print_children);
104104

105105
#endif // CRYPTO_PRINT_H

0 commit comments

Comments
 (0)