Skip to content

Commit a4672ff

Browse files
committed
Finding other places to squeeze space for the DESFire config (Log and terminal buffers stored on the stack)
1 parent 9ee3236 commit a4672ff

File tree

7 files changed

+21
-16
lines changed

7 files changed

+21
-16
lines changed

Firmware/Chameleon-Mini/Application/CryptoTDEA.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ 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-
#ifdef ENABLE_CRYPTO_TESTS
7069
/** Performs the 2-key Triple DES en/deciphering in the CBC "send" mode (xor-then-crypt)
7170
*
7271
* \param Count Block count, expected to be >= 1
@@ -90,6 +89,7 @@ void CryptoEncrypt2KTDEA_CBCReceive(uint16_t Count, const void *Input, void *Out
9089
void CryptoDecrypt2KTDEA_CBCReceive(uint16_t Count, const void *Input, void *Output, void *IV, const uint8_t *Keys);
9190

9291

92+
#ifdef ENABLE_CRYPTO_TESTS
9393
/** Performs the 3-key Triple DES en/deciphering in the CBC "send" or "receive" mode
9494
*
9595
* \param Count Block count, expected to be >= 1
@@ -108,15 +108,13 @@ typedef struct {
108108
uint16_t blockSize;
109109
} CryptoTDEA_CBCSpec;
110110

111-
#ifdef ENABLE_CRYPTO_TESTS
112111
void CryptoTDEA_CBCSend(uint16_t Count, void *Plaintext, void *Ciphertext,
113112
void *IV, const uint8_t *Keys, CryptoTDEA_CBCSpec CryptoSpec);
114113
void CryptoTDEA_CBCRecv(uint16_t Count, void *Plaintext, void *Ciphertext,
115114
void *IV, const uint8_t *Keys, CryptoTDEA_CBCSpec CryptoSpec);
116115

117116
uint8_t TransferEncryptTDEASend(uint8_t *Buffer, uint8_t Count);
118117
uint8_t TransferEncryptTDEAReceive(uint8_t *Buffer, uint8_t Count);
119-
#endif
120118

121119
/** Applies padding to the data within the buffer
122120
*

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

-2
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ uint8_t TransferChecksumFinalMACTDEA(uint8_t *Buffer) {
283283

284284
/* Encryption routines */
285285

286-
#ifdef ENABLE_CRYPTO_TESTS
287286
uint8_t TransferEncryptTDEASend(uint8_t *Buffer, uint8_t Count) {
288287
uint8_t AvailablePlaintext = TransferState.ReadData.Encryption.AvailablePlaintext;
289288
uint8_t TempBuffer[(DESFIRE_MAX_PAYLOAD_TDEA_BLOCKS + 1) * CRYPTO_DES_BLOCK_SIZE];
@@ -315,6 +314,5 @@ uint8_t TransferEncryptTDEAReceive(uint8_t *Buffer, uint8_t Count) {
315314
LogEntry(LOG_INFO_DESFIRE_INCOMING_DATA_ENC, Buffer, Count);
316315
return 0;
317316
}
318-
#endif
319317

320318
#endif /* CONFIG_MF_DESFIRE_SUPPORT */

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

+5-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,19 +157,20 @@ 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;
172172
case DESFIRE_COMMS_CIPHERTEXT_AES128:
173+
// TODO
173174
default:
174175
return STATUS_PARAMETER_ERROR;
175176
}

Firmware/Chameleon-Mini/Application/MifareDESFire.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,13 @@ uint16_t MifareDesfireAppProcess(uint8_t *Buffer, uint16_t BitCount) {
226226
} else if (ByteCount >= 6 && DesfireCLA(Buffer[0]) && Buffer[2] == 0x00 &&
227227
Buffer[3] == 0x00 && Buffer[4] == ByteCount - 6) {
228228
return MifareDesfireProcess(Buffer, BitCount);
229-
} else if (ByteCount == 4 && Buffer[2] == 0x37 && Buffer[3] == 0xC8) {
230-
// NXP-based PCD sent a "keep alive" response of ACK,
231-
// so we respond with a corresponding NAK (with CRCA bytes appended):
232-
Buffer[2] = 0x7E;
233-
Buffer[3] = 0x44;
229+
} else if (ByteCount == 4 && Buffer[2] == 0x37 && Buffer[3] == 0xC8) {
230+
// NXP-based PCD sent a "keep alive" response of ACK,
231+
// so we respond with a corresponding NAK (with CRCA bytes appended):
232+
Buffer[2] = 0x7E;
233+
Buffer[3] = 0x44;
234234
ISO14443AAppendCRCA(Buffer, 4);
235-
return 6 * BITS_PER_BYTE;
235+
return 6 * BITS_PER_BYTE;
236236
} else if (IsWrappedISO7816CommandType(Buffer, ByteCount)) {
237237
uint8_t ISO7816PrologueBytes[2];
238238
memcpy(&ISO7816PrologueBytes[0], Buffer, 2);

Firmware/Chameleon-Mini/Log.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ void LogSRAMToFRAM(void) {
229229
LogFRAMAddr += FRAM_Free;
230230
MemoryWriteBlock(&LogFRAMAddr, FRAM_LOG_ADDR_ADDR, 2);
231231
} else {
232-
// TODO handle the case in which the FRAM is full
232+
// TODO: handle the case in which the FRAM is full
233233
}
234234
}
235235
}

Firmware/Chameleon-Mini/Log.h

+4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
/** @file */
44
#include "Common.h"
55

6+
#ifdef MEMORY_LIMITED_TESTING
7+
#define LOG_SIZE 1536
8+
#else
69
#define LOG_SIZE 2048
10+
#endif
711
#define FRAM_LOG_ADDR_ADDR 0x4000 // start of the second half of FRAM
812
#define FRAM_LOG_START_ADDR 0x4002 // directly after the address
913
#define FRAM_LOG_SIZE 0x3FFE // the whole second half (minus the 2 Bytes of Address)

Firmware/Chameleon-Mini/Terminal/Terminal.h

+4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
#define TERMINAL_VBUS_PORT PORTD
1717
#define TERMINAL_VBUS_MASK PIN5_bm
1818

19+
#ifdef MEMORY_LIMITED_TESTING
20+
#define TERMINAL_BUFFER_SIZE 384
21+
#else
1922
#define TERMINAL_BUFFER_SIZE 512
23+
#endif
2024

2125
typedef enum {
2226
TERMINAL_UNINITIALIZED,

0 commit comments

Comments
 (0)