diff --git a/Firmware/Chameleon-Mini/Application/CryptoAES128.c b/Firmware/Chameleon-Mini/Application/CryptoAES128.c index 90071361..f825d451 100644 --- a/Firmware/Chameleon-Mini/Application/CryptoAES128.c +++ b/Firmware/Chameleon-Mini/Application/CryptoAES128.c @@ -289,6 +289,7 @@ uint8_t CryptoAESDecryptBuffer(uint16_t Count, uint8_t *Plaintext, uint8_t *Ciph return 0; } +#ifdef ENABLE_CRYPTO_TESTS // This routine performs the CBC "send" mode chaining: C = E(P ^ IV); IV = C void CryptoAES_CBCSend(uint16_t Count, void *Plaintext, void *Ciphertext, uint8_t *IV, uint8_t *Key, @@ -376,3 +377,4 @@ void CryptoAESDecrypt_CBCReceive(uint16_t Count, uint8_t *PlainText, uint8_t *Ci }; CryptoAES_CBCRecv(Count, PlainText, CipherText, IV, Key, CryptoSpec); } +#endif diff --git a/Firmware/Chameleon-Mini/Application/CryptoAES128.h b/Firmware/Chameleon-Mini/Application/CryptoAES128.h index 7483ca5a..4fa9a57a 100644 --- a/Firmware/Chameleon-Mini/Application/CryptoAES128.h +++ b/Firmware/Chameleon-Mini/Application/CryptoAES128.h @@ -99,18 +99,20 @@ typedef enum aes_intlvl { /* AES interrupt callback function pointer. */ typedef void (*aes_callback_t)(void); +#define CRYPTO_AES128_STRUCT_ATTR __attribute((aligned(1))) + typedef struct { CryptoAESDec_t ProcessingMode; uint8_t ProcessingDelay; // [0,15] CryptoAESAuto_t StartMode; unsigned char OpMode; // 0 = ECB, 1 = CBC, 2 = OFB, 3 = CFB, 4 = CTR CryptoAESXor_t XorMode; -} CryptoAESConfig_t; +} CryptoAESConfig_t CRYPTO_AES128_STRUCT_ATTR; typedef struct { unsigned char datrdy; // ENABLE/DISABLE; Data ready interrupt unsigned char urad; // ENABLE/DISABLE; Unspecified Register Access Detection -} CryptoAES_ISRConfig_t; +} CryptoAES_ISRConfig_t CRYPTO_AES128_STRUCT_ATTR; /* AES encryption complete. */ #define AES_ENCRYPTION_COMPLETE (1UL << 0) @@ -149,15 +151,15 @@ typedef uint8_t (*CryptoAESFuncType)(uint8_t *, uint8_t *, uint8_t *); typedef struct { CryptoAESFuncType cryptFunc; uint16_t blockSize; -} CryptoAES_CBCSpec_t; +} CryptoAES_CBCSpec_t CRYPTO_AES128_STRUCT_ATTR; +#ifdef ENABLE_CRYPTO_TESTS void CryptoAES_CBCSend(uint16_t Count, void *Plaintext, void *Ciphertext, uint8_t *IV, uint8_t *Key, CryptoAES_CBCSpec_t CryptoSpec); void CryptoAES_CBCRecv(uint16_t Count, void *Plaintext, void *Ciphertext, uint8_t *IV, uint8_t *Key, CryptoAES_CBCSpec_t CryptoSpec); - void CryptoAESEncrypt_CBCSend(uint16_t Count, uint8_t *PlainText, uint8_t *CipherText, uint8_t *Key, uint8_t *IV); 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 uint8_t *Key, uint8_t *IV); void CryptoAESDecrypt_CBCReceive(uint16_t Count, uint8_t *PlainText, uint8_t *CipherText, uint8_t *Key, uint8_t *IV); +#endif /* Crypto utility functions: */ #define CRYPTO_BYTES_TO_BLOCKS(numBytes, blockSize) \ diff --git a/Firmware/Chameleon-Mini/Application/CryptoTDEA.h b/Firmware/Chameleon-Mini/Application/CryptoTDEA.h index b8b1a0a7..d6572c32 100644 --- a/Firmware/Chameleon-Mini/Application/CryptoTDEA.h +++ b/Firmware/Chameleon-Mini/Application/CryptoTDEA.h @@ -66,7 +66,7 @@ void CryptoDecrypt3KTDEA(void *Plaintext, void *Ciphertext, const uint8_t *Keys) void Encrypt3DESBuffer(uint16_t Count, const void *Plaintext, void *Ciphertext, const uint8_t *IV, const uint8_t *Keys); void Decrypt3DESBuffer(uint16_t Count, void *Plaintext, const void *Ciphertext, const uint8_t *IV, const uint8_t *Keys); - +#ifdef ENABLE_CRYPTO_TESTS /** Performs the 2-key Triple DES en/deciphering in the CBC "send" mode (xor-then-crypt) * * \param Count Block count, expected to be >= 1 @@ -100,6 +100,7 @@ void CryptoDecrypt2KTDEA_CBCReceive(uint16_t Count, const void *Input, void *Out */ void CryptoEncrypt3KTDEA_CBCSend(uint16_t Count, const void *Plaintext, void *Ciphertext, void *IV, const uint8_t *Keys); void CryptoDecrypt3KTDEA_CBCReceive(uint16_t Count, const void *Plaintext, void *Ciphertext, void *IV, const uint8_t *Keys); +#endif /* Spec for more generic send/recv encrypt/decrypt schemes: */ typedef struct { @@ -107,6 +108,7 @@ typedef struct { uint16_t blockSize; } CryptoTDEA_CBCSpec; +#ifdef ENABLE_CRYPTO_TESTS void CryptoTDEA_CBCSend(uint16_t Count, void *Plaintext, void *Ciphertext, void *IV, const uint8_t *Keys, CryptoTDEA_CBCSpec CryptoSpec); void CryptoTDEA_CBCRecv(uint16_t Count, void *Plaintext, void *Ciphertext, @@ -114,6 +116,7 @@ void CryptoTDEA_CBCRecv(uint16_t Count, void *Plaintext, void *Ciphertext, uint8_t TransferEncryptTDEASend(uint8_t *Buffer, uint8_t Count); uint8_t TransferEncryptTDEAReceive(uint8_t *Buffer, uint8_t Count); +#endif /** Applies padding to the data within the buffer * diff --git a/Firmware/Chameleon-Mini/Application/DESFire/DESFireCrypto.c b/Firmware/Chameleon-Mini/Application/DESFire/DESFireCrypto.c index edb5cc50..cb64d0c2 100644 --- a/Firmware/Chameleon-Mini/Application/DESFire/DESFireCrypto.c +++ b/Firmware/Chameleon-Mini/Application/DESFire/DESFireCrypto.c @@ -174,6 +174,7 @@ void InitAESCryptoKeyData(void) { memset(&SessionIV[0], 0x00, CRYPTO_MAX_BLOCK_SIZE); } +#ifdef ENABLE_CRYPTO_TESTS uint8_t CryptoAESTransferEncryptSend(uint8_t *Buffer, uint8_t Count, const uint8_t *Key) { uint8_t AvailablePlaintext = TransferState.ReadData.Encryption.AvailablePlaintext; 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 LogEntry(LOG_INFO_DESFIRE_INCOMING_DATA_ENC, Buffer, Count); return STATUS_OPERATION_OK; } +#endif /* Checksum routines */ @@ -281,6 +283,7 @@ uint8_t TransferChecksumFinalMACTDEA(uint8_t *Buffer) { /* Encryption routines */ +#ifdef ENABLE_CRYPTO_TESTS uint8_t TransferEncryptTDEASend(uint8_t *Buffer, uint8_t Count) { uint8_t AvailablePlaintext = TransferState.ReadData.Encryption.AvailablePlaintext; 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) { LogEntry(LOG_INFO_DESFIRE_INCOMING_DATA_ENC, Buffer, Count); return 0; } +#endif #endif /* CONFIG_MF_DESFIRE_SUPPORT */ diff --git a/Firmware/Chameleon-Mini/Application/DESFire/DESFireCrypto.h b/Firmware/Chameleon-Mini/Application/DESFire/DESFireCrypto.h index 3a2ad219..ee9bbe95 100644 --- a/Firmware/Chameleon-Mini/Application/DESFire/DESFireCrypto.h +++ b/Firmware/Chameleon-Mini/Application/DESFire/DESFireCrypto.h @@ -129,8 +129,11 @@ typedef void (*CryptoAESCBCFuncType)(uint16_t, void *, void *, uint8_t *, uint8_ typedef uint8_t (*CryptoTransferSendFunc)(uint8_t *, uint8_t); typedef uint8_t (*CryptoTransferReceiveFunc)(uint8_t *, uint8_t); + +#ifdef ENABLE_CRYPTO_TESTS uint8_t CryptoAESTransferEncryptSend(uint8_t *Buffer, uint8_t Count, const uint8_t *Key); uint8_t CryptoAESTransferEncryptReceive(uint8_t *Buffer, uint8_t Count, const uint8_t *Key); +#endif #define DESFIRE_MAX_PAYLOAD_AES_BLOCKS (DESFIRE_MAX_PAYLOAD_SIZE / CRYPTO_AES_BLOCK_SIZE) diff --git a/Firmware/Chameleon-Mini/Application/DESFire/DESFireFirmwareSettings.h b/Firmware/Chameleon-Mini/Application/DESFire/DESFireFirmwareSettings.h index 894c7511..fa08e466 100644 --- a/Firmware/Chameleon-Mini/Application/DESFire/DESFireFirmwareSettings.h +++ b/Firmware/Chameleon-Mini/Application/DESFire/DESFireFirmwareSettings.h @@ -47,7 +47,7 @@ This notice must be retained at the top of all source files where indicated. #define DESFIRE_PICC_ARRAY_ALIGNAT __attribute__((aligned(1))) #define DESFIRE_FIRMWARE_ARRAY_ALIGNAT __attribute__((aligned(1))) #define DESFIRE_FIRMWARE_ENUM_PACKING __attribute__((aligned(1))) -#define DESFIRE_FIRMWARE_NOINIT __attribute__ ((section (".noinit"))) +#define DESFIRE_FIRMWARE_NOINIT __attribute__((section(".noinit"))) /* Some standard boolean interpreted and other values for types and return values: */ typedef int BOOL; diff --git a/Firmware/Chameleon-Mini/Application/DESFire/DESFirePICCControl.c b/Firmware/Chameleon-Mini/Application/DESFire/DESFirePICCControl.c index 19c4b839..7b82f2bb 100644 --- a/Firmware/Chameleon-Mini/Application/DESFire/DESFirePICCControl.c +++ b/Firmware/Chameleon-Mini/Application/DESFire/DESFirePICCControl.c @@ -131,7 +131,7 @@ uint8_t ReadDataFilterSetup(uint8_t CommSettings) { case DESFIRE_COMMS_PLAINTEXT_MAC: TransferState.Checksums.UpdateFunc = &TransferChecksumUpdateMACTDEA; TransferState.Checksums.FinalFunc = &TransferChecksumFinalMACTDEA; - TransferState.Checksums.MACData.CryptoChecksumFunc.TDEAFunc = &CryptoEncrypt2KTDEA_CBCSend; + //TransferState.Checksums.MACData.CryptoChecksumFunc.TDEAFunc = &CryptoEncrypt2KTDEA_CBCSend; memset(SessionIV, PICC_EMPTY_BYTE, sizeof(SessionIV)); SessionIVByteSize = CRYPTO_2KTDEA_KEY_SIZE; break; @@ -139,7 +139,7 @@ uint8_t ReadDataFilterSetup(uint8_t CommSettings) { TransferState.Checksums.UpdateFunc = &TransferChecksumUpdateCRCA; TransferState.Checksums.FinalFunc = &TransferChecksumFinalCRCA; TransferState.Checksums.MACData.CRCA = ISO14443A_CRCA_INIT; - TransferState.ReadData.Encryption.Func = &TransferEncryptTDEASend; + //TransferState.ReadData.Encryption.Func = &TransferEncryptTDEASend; memset(SessionIV, PICC_EMPTY_BYTE, sizeof(SessionIV)); SessionIVByteSize = CRYPTO_3KTDEA_KEY_SIZE; break; @@ -157,7 +157,7 @@ uint8_t WriteDataFilterSetup(uint8_t CommSettings) { case DESFIRE_COMMS_PLAINTEXT_MAC: TransferState.Checksums.UpdateFunc = &TransferChecksumUpdateMACTDEA; TransferState.Checksums.FinalFunc = &TransferChecksumFinalMACTDEA; - TransferState.Checksums.MACData.CryptoChecksumFunc.TDEAFunc = &CryptoEncrypt2KTDEA_CBCReceive; + //TransferState.Checksums.MACData.CryptoChecksumFunc.TDEAFunc = &CryptoEncrypt2KTDEA_CBCReceive; memset(SessionIV, 0, sizeof(SessionIVByteSize)); SessionIVByteSize = CRYPTO_2KTDEA_KEY_SIZE; break; @@ -165,7 +165,7 @@ uint8_t WriteDataFilterSetup(uint8_t CommSettings) { TransferState.Checksums.UpdateFunc = &TransferChecksumUpdateCRCA; TransferState.Checksums.FinalFunc = &TransferChecksumFinalCRCA; TransferState.Checksums.MACData.CRCA = ISO14443A_CRCA_INIT; - TransferState.WriteData.Encryption.Func = &TransferEncryptTDEAReceive; + //TransferState.WriteData.Encryption.Func = &TransferEncryptTDEAReceive; memset(SessionIV, 0, sizeof(SessionIVByteSize)); SessionIVByteSize = CRYPTO_3KTDEA_KEY_SIZE; break; diff --git a/Software/DESFireLibNFCTesting/LocalInclude/DesfireUtils.h b/Software/DESFireLibNFCTesting/LocalInclude/DesfireUtils.h index 18d442fd..33b55f37 100644 --- a/Software/DESFireLibNFCTesting/LocalInclude/DesfireUtils.h +++ b/Software/DESFireLibNFCTesting/LocalInclude/DesfireUtils.h @@ -236,7 +236,7 @@ static inline int AuthenticateLegacy(nfc_device *nfcConnDev, uint8_t keyIndex, c }; AUTHENTICATE_LEGACY_CMD[5] = keyIndex; if (PRINT_STATUS_EXCHANGE_MESSAGES) { - fprintf(stdout, ">>> Start Legacy 2K3DES (EEE/DDD) Authenticate:\n"); + fprintf(stdout, ">>> Start Legacy 2K3DES Authenticate:\n"); fprintf(stdout, " -> "); print_hex(AUTHENTICATE_LEGACY_CMD, sizeof(AUTHENTICATE_LEGACY_CMD)); }