Skip to content

Commit b6be1b8

Browse files
committed
Space saving defines to remove currently unused crypto exchange functionality (will revisit when get to this subproject)
1 parent 20a6960 commit b6be1b8

File tree

8 files changed

+26
-11
lines changed

8 files changed

+26
-11
lines changed

Firmware/Chameleon-Mini/Application/CryptoAES128.c

+2
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ uint8_t CryptoAESDecryptBuffer(uint16_t Count, uint8_t *Plaintext, uint8_t *Ciph
289289
return 0;
290290
}
291291

292+
#ifdef ENABLE_CRYPTO_TESTS
292293
// This routine performs the CBC "send" mode chaining: C = E(P ^ IV); IV = C
293294
void CryptoAES_CBCSend(uint16_t Count, void *Plaintext, void *Ciphertext,
294295
uint8_t *IV, uint8_t *Key,
@@ -376,3 +377,4 @@ void CryptoAESDecrypt_CBCReceive(uint16_t Count, uint8_t *PlainText, uint8_t *Ci
376377
};
377378
CryptoAES_CBCRecv(Count, PlainText, CipherText, IV, Key, CryptoSpec);
378379
}
380+
#endif

Firmware/Chameleon-Mini/Application/CryptoAES128.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,20 @@ typedef enum aes_intlvl {
9999
/* AES interrupt callback function pointer. */
100100
typedef void (*aes_callback_t)(void);
101101

102+
#define CRYPTO_AES128_STRUCT_ATTR __attribute((aligned(1)))
103+
102104
typedef struct {
103105
CryptoAESDec_t ProcessingMode;
104106
uint8_t ProcessingDelay; // [0,15]
105107
CryptoAESAuto_t StartMode;
106108
unsigned char OpMode; // 0 = ECB, 1 = CBC, 2 = OFB, 3 = CFB, 4 = CTR
107109
CryptoAESXor_t XorMode;
108-
} CryptoAESConfig_t;
110+
} CryptoAESConfig_t CRYPTO_AES128_STRUCT_ATTR;
109111

110112
typedef struct {
111113
unsigned char datrdy; // ENABLE/DISABLE; Data ready interrupt
112114
unsigned char urad; // ENABLE/DISABLE; Unspecified Register Access Detection
113-
} CryptoAES_ISRConfig_t;
115+
} CryptoAES_ISRConfig_t CRYPTO_AES128_STRUCT_ATTR;
114116

115117
/* AES encryption complete. */
116118
#define AES_ENCRYPTION_COMPLETE (1UL << 0)
@@ -149,15 +151,15 @@ typedef uint8_t (*CryptoAESFuncType)(uint8_t *, uint8_t *, uint8_t *);
149151
typedef struct {
150152
CryptoAESFuncType cryptFunc;
151153
uint16_t blockSize;
152-
} CryptoAES_CBCSpec_t;
154+
} CryptoAES_CBCSpec_t CRYPTO_AES128_STRUCT_ATTR;
153155

156+
#ifdef ENABLE_CRYPTO_TESTS
154157
void CryptoAES_CBCSend(uint16_t Count, void *Plaintext, void *Ciphertext,
155158
uint8_t *IV, uint8_t *Key,
156159
CryptoAES_CBCSpec_t CryptoSpec);
157160
void CryptoAES_CBCRecv(uint16_t Count, void *Plaintext, void *Ciphertext,
158161
uint8_t *IV, uint8_t *Key,
159162
CryptoAES_CBCSpec_t CryptoSpec);
160-
161163
void CryptoAESEncrypt_CBCSend(uint16_t Count, uint8_t *PlainText, uint8_t *CipherText,
162164
uint8_t *Key, uint8_t *IV);
163165
void CryptoAESDecrypt_CBCSend(uint16_t Count, uint8_t *PlainText, uint8_t *CipherText,
@@ -166,6 +168,7 @@ void CryptoAESEncrypt_CBCReceive(uint16_t Count, uint8_t *PlainText, uint8_t *Ci
166168
uint8_t *Key, uint8_t *IV);
167169
void CryptoAESDecrypt_CBCReceive(uint16_t Count, uint8_t *PlainText, uint8_t *CipherText,
168170
uint8_t *Key, uint8_t *IV);
171+
#endif
169172

170173
/* Crypto utility functions: */
171174
#define CRYPTO_BYTES_TO_BLOCKS(numBytes, blockSize) \

Firmware/Chameleon-Mini/Application/CryptoTDEA.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void CryptoDecrypt3KTDEA(void *Plaintext, void *Ciphertext, const uint8_t *Keys)
6666
void Encrypt3DESBuffer(uint16_t Count, const void *Plaintext, void *Ciphertext, const uint8_t *IV, const uint8_t *Keys);
6767
void Decrypt3DESBuffer(uint16_t Count, void *Plaintext, const void *Ciphertext, const uint8_t *IV, const uint8_t *Keys);
6868

69-
69+
#ifdef ENABLE_CRYPTO_TESTS
7070
/** Performs the 2-key Triple DES en/deciphering in the CBC "send" mode (xor-then-crypt)
7171
*
7272
* \param Count Block count, expected to be >= 1
@@ -100,20 +100,23 @@ void CryptoDecrypt2KTDEA_CBCReceive(uint16_t Count, const void *Input, void *Out
100100
*/
101101
void CryptoEncrypt3KTDEA_CBCSend(uint16_t Count, const void *Plaintext, void *Ciphertext, void *IV, const uint8_t *Keys);
102102
void CryptoDecrypt3KTDEA_CBCReceive(uint16_t Count, const void *Plaintext, void *Ciphertext, void *IV, const uint8_t *Keys);
103+
#endif
103104

104105
/* Spec for more generic send/recv encrypt/decrypt schemes: */
105106
typedef struct {
106107
CryptoTDEAFuncType cryptFunc;
107108
uint16_t blockSize;
108109
} CryptoTDEA_CBCSpec;
109110

111+
#ifdef ENABLE_CRYPTO_TESTS
110112
void CryptoTDEA_CBCSend(uint16_t Count, void *Plaintext, void *Ciphertext,
111113
void *IV, const uint8_t *Keys, CryptoTDEA_CBCSpec CryptoSpec);
112114
void CryptoTDEA_CBCRecv(uint16_t Count, void *Plaintext, void *Ciphertext,
113115
void *IV, const uint8_t *Keys, CryptoTDEA_CBCSpec CryptoSpec);
114116

115117
uint8_t TransferEncryptTDEASend(uint8_t *Buffer, uint8_t Count);
116118
uint8_t TransferEncryptTDEAReceive(uint8_t *Buffer, uint8_t Count);
119+
#endif
117120

118121
/** Applies padding to the data within the buffer
119122
*

Firmware/Chameleon-Mini/Application/DESFire/DESFireCrypto.c

+4
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ void InitAESCryptoKeyData(void) {
174174
memset(&SessionIV[0], 0x00, CRYPTO_MAX_BLOCK_SIZE);
175175
}
176176

177+
#ifdef ENABLE_CRYPTO_TESTS
177178
uint8_t CryptoAESTransferEncryptSend(uint8_t *Buffer, uint8_t Count, const uint8_t *Key) {
178179
uint8_t AvailablePlaintext = TransferState.ReadData.Encryption.AvailablePlaintext;
179180
uint8_t TempBuffer[(DESFIRE_MAX_PAYLOAD_AES_BLOCKS + 1) * CRYPTO_DES_BLOCK_SIZE];
@@ -213,6 +214,7 @@ uint8_t CryptoAESTransferEncryptReceive(uint8_t *Buffer, uint8_t Count, const ui
213214
LogEntry(LOG_INFO_DESFIRE_INCOMING_DATA_ENC, Buffer, Count);
214215
return STATUS_OPERATION_OK;
215216
}
217+
#endif
216218

217219
/* Checksum routines */
218220

@@ -281,6 +283,7 @@ uint8_t TransferChecksumFinalMACTDEA(uint8_t *Buffer) {
281283

282284
/* Encryption routines */
283285

286+
#ifdef ENABLE_CRYPTO_TESTS
284287
uint8_t TransferEncryptTDEASend(uint8_t *Buffer, uint8_t Count) {
285288
uint8_t AvailablePlaintext = TransferState.ReadData.Encryption.AvailablePlaintext;
286289
uint8_t TempBuffer[(DESFIRE_MAX_PAYLOAD_TDEA_BLOCKS + 1) * CRYPTO_DES_BLOCK_SIZE];
@@ -312,5 +315,6 @@ uint8_t TransferEncryptTDEAReceive(uint8_t *Buffer, uint8_t Count) {
312315
LogEntry(LOG_INFO_DESFIRE_INCOMING_DATA_ENC, Buffer, Count);
313316
return 0;
314317
}
318+
#endif
315319

316320
#endif /* CONFIG_MF_DESFIRE_SUPPORT */

Firmware/Chameleon-Mini/Application/DESFire/DESFireCrypto.h

+3
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,11 @@ typedef void (*CryptoAESCBCFuncType)(uint16_t, void *, void *, uint8_t *, uint8_
129129

130130
typedef uint8_t (*CryptoTransferSendFunc)(uint8_t *, uint8_t);
131131
typedef uint8_t (*CryptoTransferReceiveFunc)(uint8_t *, uint8_t);
132+
133+
#ifdef ENABLE_CRYPTO_TESTS
132134
uint8_t CryptoAESTransferEncryptSend(uint8_t *Buffer, uint8_t Count, const uint8_t *Key);
133135
uint8_t CryptoAESTransferEncryptReceive(uint8_t *Buffer, uint8_t Count, const uint8_t *Key);
136+
#endif
134137

135138
#define DESFIRE_MAX_PAYLOAD_AES_BLOCKS (DESFIRE_MAX_PAYLOAD_SIZE / CRYPTO_AES_BLOCK_SIZE)
136139

Firmware/Chameleon-Mini/Application/DESFire/DESFireFirmwareSettings.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ This notice must be retained at the top of all source files where indicated.
4747
#define DESFIRE_PICC_ARRAY_ALIGNAT __attribute__((aligned(1)))
4848
#define DESFIRE_FIRMWARE_ARRAY_ALIGNAT __attribute__((aligned(1)))
4949
#define DESFIRE_FIRMWARE_ENUM_PACKING __attribute__((aligned(1)))
50-
#define DESFIRE_FIRMWARE_NOINIT __attribute__ ((section (".noinit")))
50+
#define DESFIRE_FIRMWARE_NOINIT __attribute__((section(".noinit")))
5151

5252
/* Some standard boolean interpreted and other values for types and return values: */
5353
typedef int BOOL;

Firmware/Chameleon-Mini/Application/DESFire/DESFirePICCControl.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,15 @@ uint8_t ReadDataFilterSetup(uint8_t CommSettings) {
131131
case DESFIRE_COMMS_PLAINTEXT_MAC:
132132
TransferState.Checksums.UpdateFunc = &TransferChecksumUpdateMACTDEA;
133133
TransferState.Checksums.FinalFunc = &TransferChecksumFinalMACTDEA;
134-
TransferState.Checksums.MACData.CryptoChecksumFunc.TDEAFunc = &CryptoEncrypt2KTDEA_CBCSend;
134+
//TransferState.Checksums.MACData.CryptoChecksumFunc.TDEAFunc = &CryptoEncrypt2KTDEA_CBCSend;
135135
memset(SessionIV, PICC_EMPTY_BYTE, sizeof(SessionIV));
136136
SessionIVByteSize = CRYPTO_2KTDEA_KEY_SIZE;
137137
break;
138138
case DESFIRE_COMMS_CIPHERTEXT_DES:
139139
TransferState.Checksums.UpdateFunc = &TransferChecksumUpdateCRCA;
140140
TransferState.Checksums.FinalFunc = &TransferChecksumFinalCRCA;
141141
TransferState.Checksums.MACData.CRCA = ISO14443A_CRCA_INIT;
142-
TransferState.ReadData.Encryption.Func = &TransferEncryptTDEASend;
142+
//TransferState.ReadData.Encryption.Func = &TransferEncryptTDEASend;
143143
memset(SessionIV, PICC_EMPTY_BYTE, sizeof(SessionIV));
144144
SessionIVByteSize = CRYPTO_3KTDEA_KEY_SIZE;
145145
break;
@@ -157,15 +157,15 @@ uint8_t WriteDataFilterSetup(uint8_t CommSettings) {
157157
case DESFIRE_COMMS_PLAINTEXT_MAC:
158158
TransferState.Checksums.UpdateFunc = &TransferChecksumUpdateMACTDEA;
159159
TransferState.Checksums.FinalFunc = &TransferChecksumFinalMACTDEA;
160-
TransferState.Checksums.MACData.CryptoChecksumFunc.TDEAFunc = &CryptoEncrypt2KTDEA_CBCReceive;
160+
//TransferState.Checksums.MACData.CryptoChecksumFunc.TDEAFunc = &CryptoEncrypt2KTDEA_CBCReceive;
161161
memset(SessionIV, 0, sizeof(SessionIVByteSize));
162162
SessionIVByteSize = CRYPTO_2KTDEA_KEY_SIZE;
163163
break;
164164
case DESFIRE_COMMS_CIPHERTEXT_DES:
165165
TransferState.Checksums.UpdateFunc = &TransferChecksumUpdateCRCA;
166166
TransferState.Checksums.FinalFunc = &TransferChecksumFinalCRCA;
167167
TransferState.Checksums.MACData.CRCA = ISO14443A_CRCA_INIT;
168-
TransferState.WriteData.Encryption.Func = &TransferEncryptTDEAReceive;
168+
//TransferState.WriteData.Encryption.Func = &TransferEncryptTDEAReceive;
169169
memset(SessionIV, 0, sizeof(SessionIVByteSize));
170170
SessionIVByteSize = CRYPTO_3KTDEA_KEY_SIZE;
171171
break;

Software/DESFireLibNFCTesting/LocalInclude/DesfireUtils.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ static inline int AuthenticateLegacy(nfc_device *nfcConnDev, uint8_t keyIndex, c
236236
};
237237
AUTHENTICATE_LEGACY_CMD[5] = keyIndex;
238238
if (PRINT_STATUS_EXCHANGE_MESSAGES) {
239-
fprintf(stdout, ">>> Start Legacy 2K3DES (EEE/DDD) Authenticate:\n");
239+
fprintf(stdout, ">>> Start Legacy 2K3DES Authenticate:\n");
240240
fprintf(stdout, " -> ");
241241
print_hex(AUTHENTICATE_LEGACY_CMD, sizeof(AUTHENTICATE_LEGACY_CMD));
242242
}

0 commit comments

Comments
 (0)