Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4f3aa0d
Fix KMC CMAC segfault, SADB bad password segfault, add more KMC unit …
Donnie-Ice Mar 23, 2026
ee42a6c
Fix off-by-one for GVCID parameter limits
Donnie-Ice Apr 1, 2026
85a639f
re-add packed AOS struct, add AOS_GCM KMC unit tests, modify how mari…
Donnie-Ice Apr 22, 2026
d307a92
Merge branch 'dev' of github.com:nasa/CryptoLib into dev
Donnie-Ice Apr 22, 2026
4872e76
add additional CAM config error checking
Donnie-Ice May 1, 2026
100e6ef
Fix AOS and TM CBC encryption, add managed parameter failsafes
Donnie-Ice Jun 24, 2026
67b6db7
Add missing frees to KMC validate_authentication
Donnie-Ice Jul 15, 2026
b4b3dff
Add additional unit tests for KMC
Donnie-Ice Jul 15, 2026
cadbd68
Add buffer size checking for CBC apply functions
Donnie-Ice Jul 23, 2026
d1efa20
change buffer check from != to <
Donnie-Ice Jul 30, 2026
f360bcf
fix mac validation error propagation
Donnie-Ice Aug 24, 2026
04b816e
remove aos apply shplf pre-populated field check, attempt to harden p…
Donnie-Ice Aug 26, 2026
28bb2be
Restore DCS certs for UTs, resolve UT failures
Donnie-Ice Aug 31, 2026
000374b
Remove zero case from window checking
Donnie-Ice Sep 9, 2026
fa5c1b4
Remove use of sa IV for base64 encoding, revert to ingest
Donnie-Ice Sep 15, 2026
7643aa3
Remove use of sa IV for base64 encoding, revert to ingest
Donnie-Ice Sep 15, 2026
39b2508
Update build CI to run on push and PR
Donnie-Ice Sep 15, 2026
84e78b6
Add rhel build to code coverage
Donnie-Ice Sep 15, 2026
66e7819
Revert rhel CI script changes
Donnie-Ice Sep 15, 2026
8be545f
CodeQL type comparison fix
Donnie-Ice Sep 16, 2026
bf9d4cd
pin 3rd party CI actions to commit hash
Donnie-Ice Sep 16, 2026
59843df
fix string length variable in int_to_str
Donnie-Ice Sep 16, 2026
3e59a34
add iv/arsn safeguards for tm/aos apply
Donnie-Ice Sep 18, 2026
9dcae12
additional length checks to TM/AOS
Donnie-Ice Sep 18, 2026
7400bb0
Add frame/SA gvcid verification on ProcessSecurity, additional length…
Donnie-Ice Sep 22, 2026
c187d91
base64url bounds checking and UTs
Donnie-Ice Sep 22, 2026
270d2df
style: auto-format via clang-format
Donnie-Ice Sep 23, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: CryptoLib

on:
push:
branches: [ dev ]
pull_request:
branches: [ main, dev ]

Expand Down Expand Up @@ -53,7 +55,7 @@ jobs:
# run: make gcov

- name: Upload
uses: codecov/codecov-action@v5
uses: codecov/codecov-action@0fb7174895f61a3b6b78fc075e0cd60383518dac # v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: 'coverage/*.c.gcov'
Expand Down Expand Up @@ -149,7 +151,7 @@ jobs:
# run: make gcov

- name: Upload
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: 'coverage/*.c.gcov'
Expand Down Expand Up @@ -202,7 +204,7 @@ jobs:
run: source ~/.bashrc && make gcov

- name: Upload
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: 'coverage/*.c.gcov'
Expand Down Expand Up @@ -235,7 +237,7 @@ jobs:
# run: make gcov

- name: Upload
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: 'coverage/*.c.gcov'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/cpp-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
run: sudo apt-get update && sudo apt-get install -y clang-format

- name: Run Linter
uses: DoozyX/clang-format-lint-action@v0.15
uses: DoozyX/clang-format-lint-action@c71d0bf4e21876ebec3e5647491186f8797fde31 # v0.15
with:
source: '.'
extensions: 'c,h'
Expand All @@ -23,7 +23,7 @@ jobs:
inplace: true

- name: Auto-Commit Formatting Changes
uses: stefanzweifel/git-auto-commit-action@v5
uses: stefanzweifel/git-auto-commit-action@b863ae1933cb653a53c021fe36dbb774e1fb9403 # v5
with:
commit_message: 'style: auto-format via clang-format'

Expand Down
6 changes: 4 additions & 2 deletions include/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
*/
#define CRYPTO_LIB_MAJOR_VERSION 1
#define CRYPTO_LIB_MINOR_VERSION 5
#define CRYPTO_LIB_REVISION 0
#define CRYPTO_LIB_REVISION 1
#define CRYPTO_LIB_MISSION_REV 0

#define GVCID_MAX_PARAM_SIZE 100
Expand Down Expand Up @@ -191,6 +191,7 @@ extern char *Crypto_Get_Error_Code_Enum_String(int32_t crypto_error_code);

int32_t Crypto_Get_Security_Header_Length(SecurityAssociation_t *sa_ptr);
int32_t Crypto_Get_Security_Trailer_Length(SecurityAssociation_t *sa_ptr);
int32_t Crypto_check_buffer_size(uint8_t *buf, uint16_t required);

int32_t crypto_handle_incrementing_nontransmitted_counter(uint8_t *dest, uint8_t *src, int src_full_len,
int transmitted_len, int window);
Expand All @@ -203,7 +204,8 @@ int32_t Crypto_TM_Sanity_Check(uint8_t *pTfBuffer);
int32_t Crypto_TM_Determine_SA_Service_Type(uint8_t *sa_service_type, SecurityAssociation_t *sa_ptr);
void Crypto_TM_Check_For_Secondary_Header(uint8_t *pTfBuffer, uint16_t *idx);
int32_t Crypto_TM_IV_Sanity_Check(uint8_t *sa_service_type, SecurityAssociation_t *sa_ptr);
void Crypto_TM_PKCS_Padding(uint32_t *pkcs_padding, SecurityAssociation_t *sa_ptr, uint8_t *pTfBuffer, uint16_t *idx_p);
void Crypto_TM_PKCS_Padding(uint32_t *pkcs_padding, SecurityAssociation_t *sa_ptr, uint8_t *pTfBuffer, uint16_t *idx_p,
uint16_t len_ingest);
void Crypto_TM_Handle_Managed_Parameter_Flags(uint16_t *pdu_len);
int32_t Crypto_TM_Get_Keys(crypto_key_t **ekp, crypto_key_t **akp, SecurityAssociation_t *sa_ptr);
int32_t Crypto_TM_Do_Encrypt_NONPLAINTEXT(uint8_t sa_service_type, uint16_t *aad_len, int *mac_loc, uint16_t *idx_p,
Expand Down
21 changes: 18 additions & 3 deletions include/crypto_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#define CRYPTOGRAHPY_KMC_CRYPTO_SERVICE_DECRYPT_ERROR 514
#define CRYPTOGRAHPY_KMC_CRYPTO_SERVICE_ENCRYPT_ERROR 515
#define CRYPTOGRAHPY_KMC_BASE64_DECRYPT_ERROR 516
#define CRYPTOGRAHPY_KMC_BASE64URL_DECRYPT_ERROR 517

#define CAM_CONFIG_NOT_SUPPORTED_ERROR 600
#define CAM_INVALID_COOKIE_FILE_CONFIGURATION_NULL 601
Expand Down Expand Up @@ -158,15 +159,29 @@
#define CRYPTO_LIB_ERR_SHPLF_LEN_LESS_THAN_MIN_PAD_SIZE (-83)
#define CRYPTO_LIB_ERR_INVALID_AOS_IZ_LENGTH (-84)
#define CRYPTO_LIB_ERR_INVALID_AOS_FRAME_LENGTH (-85)

#define CRYPTO_CORE_ERROR_CODES_MAX -85
#define CRYPTO_LIB_ERR_TM_FRAME_SIZE_EXCEEDS_SPEC_LIMIT (-86)
#define CRYPTO_LIB_ERR_AOS_FRAME_SIZE_EXCEEDS_SPEC_LIMIT (-87)
#define CRYPTO_LIB_ERR_AOS_FL_GT_MAX_FRAME_SIZE (-88)
#define CRYPTO_LIB_ERR_TM_FL_GT_MAX_FRAME_SIZE (-89)
#define CRYPTO_LIB_ERR_TM_APPLY_PADDING (-90)
#define CRYPTO_LIB_ERR_BUFFER_SIZE (-91)
#define CRYPTO_LIB_ERR_AOS_APPLY_PADDING (-92)
#define CRYPTO_LIB_ERR_INVALID_SA_IV_CONFIG (-93)
#define CRYPTO_LIB_ERR_INVALID_SA_ARSN_CONFIG (-94)
#define CRYPTO_LIB_ERR_TM_MAN_PARAM_FL_TOO_SHORT (-95)
#define CRYPTO_LIB_ERR_AOS_MAN_PARAM_FL_TOO_SHORT (-96)
#define CRYPTO_LIB_ERR_TM_FRAME_TOO_SHORT (-97)
#define CRYPTO_LIB_ERR_AOS_FRAME_TOO_SHORT (-98)
#define CRYPTO_LIB_ERR_SA_GVCID_DOESNT_MATCH_FRAME (-99)

#define CRYPTO_CORE_ERROR_CODES_MAX -99

// Define codes for returning MDB Strings, and determining error based on strings
#define CAM_ERROR_CODES 600
#define CAM_ERROR_CODES_MAX 610

#define KMC_ERROR_CODES 500
#define KMC_ERROR_CODES_MAX 516
#define KMC_ERROR_CODES_MAX 517

#define CRYPTO_INTERFACE_ERROR_CODES 400
#define CRYPTO_INTERFACE_ERROR_CODES_MAX 402
Expand Down
3 changes: 2 additions & 1 deletion include/crypto_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ typedef struct
uint16_t fhecf; // Frame header error control field
} __attribute__((packed)) AOS_FramePrimaryHeader_t;
#define AOS_FRAME_PRIMARYHEADER_SIZE (sizeof(AOS_FramePrimaryHeader_t))
#define AOS_BASE_PRIMARYHEADER_SIZE 6u

/*
** CCSDS Compliance: CCSDS 355.0-B-2 Section 4.3.1 (Security Header)
Expand Down Expand Up @@ -634,7 +635,7 @@ typedef struct
uint8_t aos_pdu[AOS_FRAME_DATA_SIZE];
uint16_t aos_pdu_len;
AOS_FrameSecurityTrailer_t aos_sec_trailer;
} AOS_t;
} __attribute__((packed)) AOS_t;
#define AOS_SIZE (sizeof(AOS_t))

#define AOS_MIN_SIZE 6
Expand Down
73 changes: 60 additions & 13 deletions src/core/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,19 +305,19 @@ int32_t Crypto_window(uint8_t *actual, uint8_t *expected, int length, int window
}
// Check for special case where received value is all 0's and expected is all 0's (won't have -1 in sa!)
// Received ARSN is: 00000000, SA ARSN is: 00000000
uint8_t zero_case = CRYPTO_TRUE;
for (i = 0; i < length; i++)
{
if (actual[i] != 0 || expected[i] != 0)
{
zero_case = CRYPTO_FALSE;
}
}
if (zero_case == CRYPTO_TRUE)
{
status = CRYPTO_LIB_SUCCESS;
return_code = 1;
}
// uint8_t zero_case = CRYPTO_TRUE;
// for (i = 0; i < length; i++)
// {
// if (actual[i] != 0 || expected[i] != 0)
// {
// zero_case = CRYPTO_FALSE;
// }
// }
// if (zero_case == CRYPTO_TRUE)
// {
// status = CRYPTO_LIB_SUCCESS;
// return_code = 1;
// }
if (return_code != 1)
{
memcpy(temp, expected, length);
Expand Down Expand Up @@ -1639,6 +1639,11 @@ uint32_t Crypto_Get_FSR(void)

int32_t Crypto_is_safe_username(const char *s)
{
if (s == NULL)
{
return CRYPTO_LIB_SUCCESS;
}

for (const unsigned char *p = (const unsigned char *)s; *p; ++p)
{
if (!(isalnum(*p) || *p == '.' || *p == '_' || *p == '-'))
Expand All @@ -1649,10 +1654,52 @@ int32_t Crypto_is_safe_username(const char *s)

int32_t Crypto_is_safe_path(const char *s)
{
if (s == NULL)
{
return CRYPTO_LIB_ERROR;
}

for (const unsigned char *p = (const unsigned char *)s; *p; ++p)
{
if (!(isalnum(*p) || *p == '.' || *p == '_' || *p == '-' || *p == '/'))
return CRYPTO_LIB_ERROR;
}
return CRYPTO_LIB_SUCCESS;
}

int32_t Crypto_check_buffer_size(uint8_t *buf, uint16_t required)
{
int32_t status = CRYPTO_LIB_SUCCESS;
#if defined(__linux__)
#include <malloc.h>
if (malloc_usable_size(buf) < required)
{
status = CRYPTO_LIB_ERR_BUFFER_SIZE;
#ifdef DEBUG
printf("Buffer of size %ld bytes, but requires %d bytes\n", malloc_usable_size(buf), required);
#endif
mc_if->mc_log(status);
}
#elif defined(__APPLE__)
#include <malloc/malloc.h>
if (malloc_size(buf) < required)
{
status = CRYPTO_LIB_ERR_BUFFER_SIZE;
#ifdef DEBUG
printf("Buffer of size %ld bytes, but requires %d bytes\n", malloc_size(buf), required);
#endif
mc_if->mc_log(status);
}
#elif defined(_WIN32)
#include <malloc.h>
if (_msize(buf) < required)
{
status = CRYPTO_LIB_ERR_BUFFER_SIZE;
#ifdef DEBUG
printf("Buffer of size %ld bytes, but requires %d bytes\n", _msize(buf), required);
#endif
mc_if->mc_log(status);
}
#endif
return status;
}
Loading
Loading