Skip to content

Commit

Permalink
Merge pull request #337 from nasa/299-setup-code-formatter
Browse files Browse the repository at this point in the history
299 setup code formatter
  • Loading branch information
Donnie-Ice authored Oct 21, 2024
2 parents 48cc556 + a3f2e78 commit 8d3401c
Show file tree
Hide file tree
Showing 101 changed files with 17,484 additions and 12,385 deletions.
64 changes: 64 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
Language: Cpp
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignConsecutiveMacros: true
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
BinPackArguments: true
BinPackParameters: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Allman
BreakBeforeTernaryOperators: true
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: ''
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: []
IncludeBlocks: Preserve
IncludeCategories: []
IncludeIsMainRegex: '$'
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: false
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpaceBeforeCpp11BracedList: true
SpacesBeforeTrailingComments: 1
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: c++11
TabWidth: 8
UseTab: Never
25 changes: 25 additions & 0 deletions .github/workflows/cpp-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: cpp-linter

on:
pull_request:
branches: [ main, dev ]

jobs:
cpp-linter:
permissions:
pull-requests: write
contents: write
actions: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cpp-linter/cpp-linter-action@v2
id: linter
with:
style: 'file'
files-changed-only: false
verbosity: 'info'
step-summary: 'true'
no-lgtm: 'false'
passive-reviews: 'true'
ignore: 'test/include/utest.h'
373 changes: 207 additions & 166 deletions include/crypto.h

Large diffs are not rendered by default.

197 changes: 98 additions & 99 deletions include/crypto_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
// Debug Colors
#ifdef DEBUG
#define CRYPTO_DEBUG printf("%s:%s: %d", __FILE__, __FUNCTION__, __LINE__);
#define KRED "\x1B[31m"
#define KGRN "\x1B[32m"
#define KYEL "\x1B[33m"
#define KBLU "\x1B[34m"
#define KMAG "\x1B[35m"
#define KCYN "\x1B[36m"
#define RESET "\033[0m"
#define KRED "\x1B[31m"
#define KGRN "\x1B[32m"
#define KYEL "\x1B[33m"
#define KBLU "\x1B[34m"
#define KMAG "\x1B[35m"
#define KCYN "\x1B[36m"
#define RESET "\033[0m"
#else
#define CRYPTO_DEBUG
#define KRED
Expand All @@ -45,8 +45,8 @@
#define GVCID_MAN_PARAM_SIZE 250

// Max Frame Size
#define TC_MAX_FRAME_SIZE 1024
#define TM_MAX_FRAME_SIZE 1786
#define TC_MAX_FRAME_SIZE 1024
#define TM_MAX_FRAME_SIZE 1786
#define AOS_MAX_FRAME_SIZE 1786

// Spacecraft Defines
Expand All @@ -61,173 +61,173 @@

// GVCID Defines
#define NUM_GVCID 64
#define TYPE_TC 0
#define TYPE_MAP 1
#define TYPE_TM 2
#define TYPE_AOS 3
#define TYPE_TC 0
#define TYPE_MAP 1
#define TYPE_TM 2
#define TYPE_AOS 3

// Specific to Authentication
#define SA_NONE 0
#define SA_UNKEYED 1
#define SA_KEYED 2
#define SA_NONE 0
#define SA_UNKEYED 1
#define SA_KEYED 2
#define SA_OPERATIONAL 3
// SA State Transitions
#define SA_CREATE 5
#define SA_REKEY 6
#define SA_START 7
#define SA_STOP 2
#define SA_REKEY 6
#define SA_START 7
#define SA_STOP 2
#define SA_EXPIRE 1
#define SA_DELETE 0
// SA Additional Directives
#define SA_STATUS 8
#define SA_SETARSN 9
#define SA_STATUS 8
#define SA_SETARSN 9
#define SA_SETARSNW 10

// Key State Defines
#define KEY_PREACTIVE 0
#define KEY_ACTIVE 1
#define KEY_PREACTIVE 0
#define KEY_ACTIVE 1
#define KEY_DEACTIVATED 2
#define KEY_DESTROYED 3
#define KEY_CORRUPTED 4
#define KEY_DESTROYED 3
#define KEY_CORRUPTED 4

// Key Length Defines
// ECS
#define AES256_GCM_KEYLEN 32
#define AES256_GCM_KEYLEN 32
#define AES256_GCM_SIV_KEYLEN 32
#define AES256_CBC_KEYLEN 32
#define AES256_CCM_KEYLEN 32
#define AES256_CBC_KEYLEN 32
#define AES256_CCM_KEYLEN 32
// ACS
#define CMAC_AES256_KEYLEN 32
#define HMAC_SHA256_KEYLEN 32
#define HMAC_SHA512_KEYLEN 64

// SA Service Types
#define SA_PLAINTEXT 0
#define SA_AUTHENTICATION 1
#define SA_ENCRYPTION 2
#define SA_PLAINTEXT 0
#define SA_AUTHENTICATION 1
#define SA_ENCRYPTION 2
#define SA_AUTHENTICATED_ENCRYPTION 3

// Generic Defines
#define NUM_SA 64
#define SPI_LEN 2 /* bytes */
#define KEY_SIZE 512 /* bytes */
#define KEY_ID_SIZE 8
#define NUM_KEYS 256
#define DISABLED 0
#define ENABLED 1
#define IV_SIZE 16 /* TM IV size bytes */
#define IV_SIZE_TC 4 /* TC IV size bytes */
#define REF_SIZE 250
#define OCF_SIZE 4
#define MAC_SIZE 16 /* bytes */
#define FECF_SIZE 2
#define NUM_SA 64
#define SPI_LEN 2 /* bytes */
#define KEY_SIZE 512 /* bytes */
#define KEY_ID_SIZE 8
#define NUM_KEYS 256
#define DISABLED 0
#define ENABLED 1
#define IV_SIZE 16 /* TM IV size bytes */
#define IV_SIZE_TC 4 /* TC IV size bytes */
#define REF_SIZE 250
#define OCF_SIZE 4
#define MAC_SIZE 16 /* bytes */
#define FECF_SIZE 2
#define TC_SEGMENT_HDR_SIZE 1
#define ECS_SIZE 4 /* bytes */
#define ABM_SIZE 1786 /* bytes */
#define ARSN_SIZE 20 /* total messages */
#define ARSNW_SIZE 1 /* bytes */
#define SN_SIZE 16 /* bytes */
#define PAD_SIZE 32 /* bytes */
#define CHALLENGE_SIZE 16 /* bytes */
#define CHALLENGE_MAC_SIZE 16 /* bytes */
#define BYTE_LEN 8 /* bits */
#define ECS_SIZE 4 /* bytes */
#define ABM_SIZE 1786 /* bytes */
#define ARSN_SIZE 20 /* total messages */
#define ARSNW_SIZE 1 /* bytes */
#define SN_SIZE 16 /* bytes */
#define PAD_SIZE 32 /* bytes */
#define CHALLENGE_SIZE 16 /* bytes */
#define CHALLENGE_MAC_SIZE 16 /* bytes */
#define BYTE_LEN 8 /* bits */

// Monitoring and Control Defines
#define EMV_SIZE 4 /* bytes */
#define LOG_SIZE 50 /* packets */
#define ST_OK 0x00
#define ST_NOK 0xFF
#define ST_OK 0x00
#define ST_NOK 0xFF

// Protocol Data Unit (PDU)
// PDU Type
#define PDU_TYPE_COMMAND 0
#define PDU_TYPE_REPLY 1
#define PDU_TYPE_REPLY 1
// PDU User Flag
#define PDU_USER_FLAG_TRUE 1
#define PDU_USER_FLAG_TRUE 1
#define PDU_USER_FLAG_FALSE 0

// Procedure Identification (PID) - CCSDS Defined Commands
// Service Group - Key Management
#define SG_KEY_MGMT 0x00 // 0b00
#define PID_OTAR 0x01 // 0b0001
#define PID_KEY_ACTIVATION 0x02 // 0b0010
#define PID_KEY_DEACTIVATION 0x03 //0b0011
#define SG_KEY_MGMT 0x00 // 0b00
#define PID_OTAR 0x01 // 0b0001
#define PID_KEY_ACTIVATION 0x02 // 0b0010
#define PID_KEY_DEACTIVATION 0x03 // 0b0011
#define PID_KEY_VERIFICATION 0x04 // 0b0100
#define PID_KEY_DESTRUCTION 0x06 // 0b0110
#define PID_KEY_INVENTORY 0x07 // 0b0111
#define PID_KEY_DESTRUCTION 0x06 // 0b0110
#define PID_KEY_INVENTORY 0x07 // 0b0111
// Service Group - Security Association Management
#define SG_SA_MGMT 0x01 // 0b01
#define PID_CREATE_SA 0x01 //0b0001
#define PID_REKEY_SA 0x06 //0b0110
#define PID_START_SA 0x0B //0b1011
#define PID_STOP_SA 0x0E // 0b1110
#define SG_SA_MGMT 0x01 // 0b01
#define PID_CREATE_SA 0x01 // 0b0001
#define PID_REKEY_SA 0x06 // 0b0110
#define PID_START_SA 0x0B // 0b1011
#define PID_STOP_SA 0x0E // 0b1110
#define PID_EXPIRE_SA 0x09 // 0b1001
#define PID_DELETE_SA 0x04 // 0b0100
#define PID_SET_ARSN 0x0A //0b1010
#define PID_SET_ARSN 0x0A // 0b1010
#define PID_SET_ARSNW 0x05 // 0b0101
#define PID_READ_ARSN 0x00 // 0b0000
#define PID_SA_STATUS 0x0F // 0b1111
// Service Group - Security Monitoring & Control
#define SG_SEC_MON_CTRL 0x03 // 0b11
#define PID_PING 0x01 // 0b0001
#define PID_LOG_STATUS 0x02 //0b0010
#define PID_DUMP_LOG 0x03 // 0b0011
#define PID_ERASE_LOG 0x04 // 0b0100
#define PID_SELF_TEST 0x05 // 0b0101
#define PID_ALARM_FLAG 0x07 // 0b0111
#define PID_PING 0x01 // 0b0001
#define PID_LOG_STATUS 0x02 // 0b0010
#define PID_DUMP_LOG 0x03 // 0b0011
#define PID_ERASE_LOG 0x04 // 0b0100
#define PID_SELF_TEST 0x05 // 0b0101
#define PID_ALARM_FLAG 0x07 // 0b0111

// Procedure Identification (PID) - User Defined Commands
#define PID_IDLE_FRAME_TRIGGER 0
#define PID_TOGGLE_BAD_SPI 1
#define PID_TOGGLE_BAD_IV 2
#define PID_TOGGLE_BAD_MAC 3
#define PID_TOGGLE_BAD_FECF 4
#define PID_MODIFY_KEY 5
#define PID_MODIFY_ACTIVE_TM 6
#define PID_MODIFY_VCID 7
#define PID_TOGGLE_BAD_SPI 1
#define PID_TOGGLE_BAD_IV 2
#define PID_TOGGLE_BAD_MAC 3
#define PID_TOGGLE_BAD_FECF 4
#define PID_MODIFY_KEY 5
#define PID_MODIFY_ACTIVE_TM 6
#define PID_MODIFY_VCID 7

// TC Defines
#define TC_SH_SIZE 8 /* bits */
#define TC_SN_SIZE 2
#define TC_SN_WINDOW 10 /* +/- value */
#define TC_SH_SIZE 8 /* bits */
#define TC_SN_SIZE 2
#define TC_SN_WINDOW 10 /* +/- value */
#define TC_FRAME_DATA_SIZE 1019 /* bytes */ // 1024 - 5byte header
#define TC_CADU_ASM_SIZE 4
#define TC_CADU_ASM_SIZE 4

// CCSDS PUS Defines
#define TLV_DATA_SIZE 494 /* bytes */

// TM Defines
#define TM_FRAME_DATA_SIZE 1786 /* bytes */
#define TM_FILL_SIZE 1145 /* bytes */
#define TM_PAD_SIZE 2 /* bytes */
#define TM_FILL_SIZE 1145 /* bytes */
#define TM_PAD_SIZE 2 /* bytes */

// AOS Defines
#define AOS_FRAME_DATA_SIZE 1786 /* bytes */
#define AOS_FILL_SIZE 1145 /* bytes */
#define AOS_FILL_SIZE 1145 /* bytes */

// SDLS Behavior Defines
#define SDLS_KEYV_MAX_KEYS 21 /* keys */
#define SDLS_IV_LEN 12 /* bytes */
#define SDLS_KEYV_KEY_ID_LEN 2 /* bytes */
#define SDLS_KEY_LEN 32 /* bytes */
#define SDLS_KEYV_MAX_KEYS 21 /* keys */
#define SDLS_IV_LEN 12 /* bytes */
#define SDLS_KEYV_KEY_ID_LEN 2 /* bytes */
#define SDLS_KEY_LEN 32 /* bytes */

// TC Behavior Defines
#define TC_SDLS_EP_VCID \
#define TC_SDLS_EP_VCID \
4 // VCID which has SDLS PDUs (JPL uses VCIDs to determine TC type, there is no space packet layer with APIDs). Set
// to -1 if uses SP APIDs.

// TM Behavior Defines
#define TM_CADU_HAS_ASM 1 // Skip 0x1acffc1d at beginning of each frame
// TM CADU based on ASM, currently only holds non-turbo ASM
#ifdef TM_CADU_HAS_ASM
#define TM_CADU_SIZE (TM_FRAME_DATA_SIZE + TC_CADU_ASM_SIZE)
#define TM_CADU_SIZE (TM_FRAME_DATA_SIZE + TC_CADU_ASM_SIZE)
#else
#define TM_CADU_SIZE TM_FRAME_DATA_SIZE
#define TM_CADU_SIZE TM_FRAME_DATA_SIZE
#endif

// Logic Behavior Defines
#define CRYPTO_FALSE 0
#define CRYPTO_TRUE 1
#define CRYPTO_TRUE 1

/*
** SAVE FILE NAME/LOCATION
Expand All @@ -239,5 +239,4 @@
*/
#define TC_BLOCK_SIZE 16


#endif //CRYPTO_CONFIG_H
#endif // CRYPTO_CONFIG_H
Loading

0 comments on commit 8d3401c

Please sign in to comment.