Skip to content

Commit 7fb1b16

Browse files
authored
Merge pull request #324 from nasa/319-crypto_structsh
[#319] Remove Commented Code, Magic Number Cleanup, Lin…
2 parents 74532eb + ec0366a commit 7fb1b16

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

include/crypto_structs.h

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
#ifndef CRYPTO_STRUCTS_H
2020
#define CRYPTO_STRUCTS_H
2121

22+
#define SDLS_CHALLENGED_SIZE 10
23+
#define SDLS_CMAC_SIZE 10
24+
#define SDLS_KEY_VERIFY_BLK_SIZE 29
25+
#define SDLS_KEY_ID_SIZE 98
26+
#define SDLS_EKB_LEN 30
27+
2228
#include "crypto_config.h"
2329

2430
#ifdef NOS3 // NOS3/cFS build is ready
@@ -46,6 +52,8 @@ typedef struct
4652

4753
/*
4854
** Security Association
55+
* https://public.ccsds.org/Pubs/355x0b2.pdf
56+
* Table A6
4957
*/
5058
typedef struct
5159
{
@@ -57,7 +65,6 @@ typedef struct
5765
char ak_ref[REF_SIZE]; // Authentication Key Reference (Used with string-referenced keystores,EG-PKCS12 keystores, KMC crypto)
5866
uint8_t sa_state : 2;
5967
crypto_gvcid_t gvcid_blk;
60-
// crypto_gvcid_t gvcid_tm_blk[NUM_GVCID];
6168
uint8_t lpid;
6269

6370
// Configuration
@@ -114,15 +121,14 @@ typedef struct
114121
{
115122
uint16_t ekid; // Encrypted Key ID
116123
uint8_t ek[KEY_SIZE]; // Encrypted Key
117-
// uint8_t ekcrc[4]; // Encrypted Key CRC
118124
} SDLS_EKB_t;
119125
#define SDLS_EKB_SIZE (sizeof(SDLS_EKB_t))
120126

121127
typedef struct
122128
{
123129
uint16_t mkid; // Master Key ID
124130
uint8_t iv[IV_SIZE]; // Initialization Vector
125-
SDLS_EKB_t EKB[30]; // Encrypted Key Block
131+
SDLS_EKB_t EKB[SDLS_EKB_LEN]; // Encrypted Key Block
126132
uint8_t mac[MAC_SIZE]; // Message Authentication Code
127133
} SDLS_OTAR_t;
128134
#define SDLS_OTAR_SIZE (sizeof(SDLS_OTAR_t))
@@ -135,7 +141,7 @@ typedef struct
135141

136142
typedef struct
137143
{
138-
SDLS_KEY_t kblk[98]; // Key ID Block
144+
SDLS_KEY_t kblk[SDLS_KEY_ID_SIZE]; // Key ID Block
139145
} SDLS_KEY_BLK_t;
140146
#define SDLS_KEY_BLK_SIZE (sizeof(SDLS_KEY_BLK_t))
141147

@@ -155,7 +161,7 @@ typedef struct
155161

156162
typedef struct
157163
{
158-
SDLS_KEYV_CMD_BLK_t blk[29]; // Key Verification Command Block
164+
SDLS_KEYV_CMD_BLK_t blk[SDLS_KEY_VERIFY_BLK_SIZE]; // Key Verification Command Block
159165
} SDLS_KEYV_CMD_t;
160166
#define SDLS_KEYV_CMD_SIZE (sizeof(SDLS_KEYV_CMD_t))
161167

@@ -168,25 +174,27 @@ typedef struct
168174
} SDLS_KEYV_RPLY_BLK_t;
169175
#define SDLS_KEYV_RPLY_BLK_SIZE (sizeof(SDLS_KEYV_RPLY_BLK_t))
170176

177+
171178
typedef struct
172179
{
173-
SDLS_KEYV_RPLY_BLK_t blk[29]; // Key Verification Reply Block
180+
SDLS_KEYV_RPLY_BLK_t blk[SDLS_KEY_VERIFY_BLK_SIZE]; // Key Verification Reply Block
174181
} SDLS_KEYV_RPLY_t;
175182
#define SDLS_KEYV_RPLY_SIZE (sizeof(SDLS_KEYV_RPLY_t))
176183

177184
typedef struct
178185
{
179186
uint16_t kid : 16; // Key ID
180-
uint8_t challenged[10];
187+
uint8_t challenged[SDLS_CHALLENGED_SIZE];
181188
} SDLS_KEYDB_CMD_t;
182189
#define SDLS_KEYDB_CMD_SIZE (sizeof(SDLS_KEYDB_CMD_t))
183190

191+
184192
typedef struct
185193
{
186194
uint16_t kid : 16; // Key ID
187195
uint8_t iv[IV_SIZE]; // Initialization Vector
188-
uint8_t challenged[10]; // Encrypted Challenge
189-
uint8_t cmac[4]; // Challenge Message Authentication Code
196+
uint8_t challenged[SDLS_CHALLENGED_SIZE]; // Encrypted Challenge
197+
uint8_t cmac[SDLS_CMAC_SIZE]; // Challenge Message Authentication Code
190198
} SDLS_KEYDB_RPLY_t;
191199
#define SDLS_KEYDB_RPLY_SIZE (sizeof(SDLS_KEYDB_RPLY_t))
192200

@@ -233,8 +241,6 @@ typedef struct
233241
/*
234242
** Telecommand (TC) Definitions
235243
*/
236-
// typedef struct __attribute__ ((packed)) //__attribute__ ((packed)) is not easily supported in CFFI python. Only add
237-
// when CFFI properly supports packed & nonpacked structs.
238244
typedef struct
239245
{
240246
uint8_t tfvn : 2; // Transfer Frame Version Number
@@ -312,19 +318,10 @@ typedef struct
312318
} CCSDS_PUS_t;
313319
#define CCSDS_PUS_SIZE (sizeof(CCSDS_PUS_t))
314320

315-
/* unused?
316-
typedef struct
317-
{
318-
uint8_t CmdHeader[CFE_SB_CMD_HDR_SIZE];
319-
320-
} Crypto_NoArgsCmd_t;
321-
*/
322-
323321
typedef struct
324322
{
325323
CCSDS_HDR_t hdr;
326324
CCSDS_PUS_t pus;
327-
// CCSDS_2HDR_t cmd;
328325
SDLS_TLV_t pdu;
329326
} CCSDS_t;
330327
#define CCSDS_SIZE (sizeof(CCSDS_t))
@@ -396,17 +393,13 @@ typedef struct
396393
uint16_t fhp : 11; // First Header Pointer
397394
// Sync Flag 0 = Contains position of the first byte of the first packet in the data field
398395
// Sync Flag 1 = undefined
399-
// uint8_t tfshvn :2; // Transfer Frame Secondary Header Version Number - shall be 00
400-
// uint8_t tfshlen :6; // TFSH Length (max 64 Bytes)
401396
} TM_FramePrimaryHeader_t;
402397
#define TM_FRAME_PRIMARYHEADER_SIZE (sizeof(TM_FramePrimaryHeader_t))
403398

404399
typedef struct
405400
{
406401
uint16_t spi; // Security Parameter Index
407402
uint8_t iv[IV_SIZE]; // Initialization Vector for encryption
408-
// uint8_t sn[TM_SN_SIZE]; // Sequence Number for anti-replay
409-
// uint8_t pad[TM_PAD_SIZE]; // Count of the used fill Bytes
410403
} TM_FrameSecurityHeader_t;
411404
#define TM_FRAME_SECHEADER_SIZE (sizeof(TM_FrameSecurityHeader_t))
412405

@@ -462,8 +455,6 @@ typedef struct
462455
{
463456
uint16_t spi; // Security Parameter Index
464457
uint8_t iv[IV_SIZE]; // Initialization Vector for encryption
465-
// uint8_t sn[TM_SN_SIZE]; // Sequence Number for anti-replay
466-
// uint8_t pad[TM_PAD_SIZE]; // Count of the used fill Bytes
467458
} AOS_FrameSecurityHeader_t;
468459
#define AOS_FRAME_SECHEADER_SIZE (sizeof(AOS_FrameSecurityHeader_t))
469460

0 commit comments

Comments
 (0)