From e22b286c9eff4428629760a3d5031cd8bdc7de91 Mon Sep 17 00:00:00 2001 From: Maxie Dion Schmidt Date: Fri, 11 Feb 2022 17:43:41 -0500 Subject: [PATCH] Removing default testing nonce B from auth commands ; Running make style --- .../Chameleon-Mini/Application/CryptoTDEA.c | 58 ++++++------ .../Chameleon-Mini/Application/CryptoTDEA.h | 12 +-- .../DESFire/DESFireApplicationDirectory.c | 14 +-- .../DESFire/DESFireApplicationDirectory.h | 6 +- .../DESFire/DESFireChameleonTerminal.c | 8 +- .../Application/DESFire/DESFireCrypto.c | 50 +++++----- .../Application/DESFire/DESFireCrypto.h | 2 +- .../Application/DESFire/DESFireInstructions.c | 46 ++++----- .../DESFire/DESFirePICCHeaderLayout.h | 2 +- .../Application/MifareDESFire.c | 22 ++--- Firmware/Chameleon-Mini/Configuration.c | 94 +++++++++---------- Firmware/Chameleon-Mini/Configuration.h | 8 +- Firmware/Chameleon-Mini/Makefile | 4 +- Firmware/Chameleon-Mini/Memory.c | 2 +- Firmware/Chameleon-Mini/Terminal/Commands.c | 4 +- .../Chameleon-Mini/Tests/ChameleonTerminal.c | 4 +- Firmware/Chameleon-Mini/Tests/CryptoTests.c | 28 +++--- 17 files changed, 182 insertions(+), 182 deletions(-) diff --git a/Firmware/Chameleon-Mini/Application/CryptoTDEA.c b/Firmware/Chameleon-Mini/Application/CryptoTDEA.c index 97f1b3af..11314ec2 100644 --- a/Firmware/Chameleon-Mini/Application/CryptoTDEA.c +++ b/Firmware/Chameleon-Mini/Application/CryptoTDEA.c @@ -21,19 +21,19 @@ void EncryptDESBuffer(uint16_t Count, const void *Plaintext, void *Ciphertext, c if (IVIn == NULL) { memset(IV, 0x00, CRYPTO_DES_BLOCK_SIZE); } else { - memcpy(IV, IVIn, CRYPTO_DES_BLOCK_SIZE); + memcpy(IV, IVIn, CRYPTO_DES_BLOCK_SIZE); } while (blockIndex < numBlocks) { if (blockIndex == 0) { memcpy(inputBlock, &Plaintext[0], CRYPTO_DES_BLOCK_SIZE); - CryptoMemoryXOR(IV, inputBlock, CRYPTO_DES_BLOCK_SIZE); - } else { + CryptoMemoryXOR(IV, inputBlock, CRYPTO_DES_BLOCK_SIZE); + } else { memcpy(inputBlock, &Ciphertext[(blockIndex - 1) * CRYPTO_DES_BLOCK_SIZE], CRYPTO_DES_BLOCK_SIZE); - CryptoMemoryXOR(&Plaintext[blockIndex * CRYPTO_DES_BLOCK_SIZE], inputBlock, CRYPTO_DES_BLOCK_SIZE); - } - CryptoSpec.cryptFunc(inputBlock, ctBuf, Keys); - ctBuf += CryptoSpec.blockSize; - blockIndex++; + CryptoMemoryXOR(&Plaintext[blockIndex * CRYPTO_DES_BLOCK_SIZE], inputBlock, CRYPTO_DES_BLOCK_SIZE); + } + CryptoSpec.cryptFunc(inputBlock, ctBuf, Keys); + ctBuf += CryptoSpec.blockSize; + blockIndex++; } } @@ -49,18 +49,18 @@ void DecryptDESBuffer(uint16_t Count, void *Plaintext, const void *Ciphertext, c if (IVIn == NULL) { memset(IV, 0x00, CRYPTO_DES_BLOCK_SIZE); } else { - memcpy(IV, IVIn, CRYPTO_DES_BLOCK_SIZE); + memcpy(IV, IVIn, CRYPTO_DES_BLOCK_SIZE); } while (blockIndex < numBlocks) { - CryptoSpec.cryptFunc(inputBlock, Ciphertext + blockIndex * CRYPTO_DES_BLOCK_SIZE, Keys); + CryptoSpec.cryptFunc(inputBlock, Ciphertext + blockIndex * CRYPTO_DES_BLOCK_SIZE, Keys); if (blockIndex == 0) { memcpy(Plaintext, inputBlock, CRYPTO_DES_BLOCK_SIZE); - CryptoMemoryXOR(IV, Plaintext, CRYPTO_DES_BLOCK_SIZE); - } else { + CryptoMemoryXOR(IV, Plaintext, CRYPTO_DES_BLOCK_SIZE); + } else { memcpy(Plaintext + blockIndex * CRYPTO_DES_BLOCK_SIZE, inputBlock, CRYPTO_DES_BLOCK_SIZE); - CryptoMemoryXOR(&Ciphertext[(blockIndex - 1) * CRYPTO_DES_BLOCK_SIZE], - Plaintext + blockIndex * CRYPTO_DES_BLOCK_SIZE, CRYPTO_DES_BLOCK_SIZE); - } + CryptoMemoryXOR(&Ciphertext[(blockIndex - 1) * CRYPTO_DES_BLOCK_SIZE], + Plaintext + blockIndex * CRYPTO_DES_BLOCK_SIZE, CRYPTO_DES_BLOCK_SIZE); + } blockIndex++; } } @@ -78,19 +78,19 @@ void Encrypt3DESBuffer(uint16_t Count, const void *Plaintext, void *Ciphertext, if (IVIn == NULL) { memset(IV, 0x00, CRYPTO_3KTDEA_BLOCK_SIZE); } else { - memcpy(IV, IVIn, CRYPTO_3KTDEA_BLOCK_SIZE); + memcpy(IV, IVIn, CRYPTO_3KTDEA_BLOCK_SIZE); } while (blockIndex < numBlocks) { if (blockIndex == 0) { memcpy(inputBlock, &Plaintext[0], CRYPTO_3KTDEA_BLOCK_SIZE); - CryptoMemoryXOR(IV, inputBlock, CRYPTO_3KTDEA_BLOCK_SIZE); - } else { + CryptoMemoryXOR(IV, inputBlock, CRYPTO_3KTDEA_BLOCK_SIZE); + } else { memcpy(inputBlock, &Ciphertext[(blockIndex - 1) * CRYPTO_3KTDEA_BLOCK_SIZE], CRYPTO_3KTDEA_BLOCK_SIZE); - CryptoMemoryXOR(&Plaintext[blockIndex * CRYPTO_3KTDEA_BLOCK_SIZE], inputBlock, CRYPTO_3KTDEA_BLOCK_SIZE); - } - CryptoSpec.cryptFunc(inputBlock, ctBuf, Keys); + CryptoMemoryXOR(&Plaintext[blockIndex * CRYPTO_3KTDEA_BLOCK_SIZE], inputBlock, CRYPTO_3KTDEA_BLOCK_SIZE); + } + CryptoSpec.cryptFunc(inputBlock, ctBuf, Keys); ctBuf += CryptoSpec.blockSize; - blockIndex++; + blockIndex++; } } @@ -106,18 +106,18 @@ void Decrypt3DESBuffer(uint16_t Count, void *Plaintext, const void *Ciphertext, if (IVIn == NULL) { memset(IV, 0x00, CRYPTO_3KTDEA_BLOCK_SIZE); } else { - memcpy(IV, IVIn, CRYPTO_3KTDEA_BLOCK_SIZE); + memcpy(IV, IVIn, CRYPTO_3KTDEA_BLOCK_SIZE); } while (blockIndex < numBlocks) { - CryptoSpec.cryptFunc(inputBlock, Ciphertext + blockIndex * CRYPTO_3KTDEA_BLOCK_SIZE, Keys); + CryptoSpec.cryptFunc(inputBlock, Ciphertext + blockIndex * CRYPTO_3KTDEA_BLOCK_SIZE, Keys); if (blockIndex == 0) { memcpy(Plaintext, inputBlock, CRYPTO_3KTDEA_BLOCK_SIZE); - CryptoMemoryXOR(IV, Plaintext, CRYPTO_3KTDEA_BLOCK_SIZE); - } else { + CryptoMemoryXOR(IV, Plaintext, CRYPTO_3KTDEA_BLOCK_SIZE); + } else { memcpy(Plaintext + blockIndex * CRYPTO_3KTDEA_BLOCK_SIZE, inputBlock, CRYPTO_3KTDEA_BLOCK_SIZE); - CryptoMemoryXOR(&Ciphertext[(blockIndex - 1) * CRYPTO_3KTDEA_BLOCK_SIZE], - Plaintext + blockIndex * CRYPTO_3KTDEA_BLOCK_SIZE, CRYPTO_3KTDEA_BLOCK_SIZE); - } + CryptoMemoryXOR(&Ciphertext[(blockIndex - 1) * CRYPTO_3KTDEA_BLOCK_SIZE], + Plaintext + blockIndex * CRYPTO_3KTDEA_BLOCK_SIZE, CRYPTO_3KTDEA_BLOCK_SIZE); + } blockIndex++; } } diff --git a/Firmware/Chameleon-Mini/Application/CryptoTDEA.h b/Firmware/Chameleon-Mini/Application/CryptoTDEA.h index 90b90573..e6b28b1c 100644 --- a/Firmware/Chameleon-Mini/Application/CryptoTDEA.h +++ b/Firmware/Chameleon-Mini/Application/CryptoTDEA.h @@ -1,9 +1,9 @@ - /* - * CryptoDES.h - * - * Created on: 18.10.2016 - * Author: dev_zzo - */ +/* +* CryptoDES.h +* +* Created on: 18.10.2016 +* Author: dev_zzo +*/ #ifndef CRYPTODES_H_ #define CRYPTODES_H_ diff --git a/Firmware/Chameleon-Mini/Application/DESFire/DESFireApplicationDirectory.c b/Firmware/Chameleon-Mini/Application/DESFire/DESFireApplicationDirectory.c index df512633..d66cc85a 100644 --- a/Firmware/Chameleon-Mini/Application/DESFire/DESFireApplicationDirectory.c +++ b/Firmware/Chameleon-Mini/Application/DESFire/DESFireApplicationDirectory.c @@ -209,7 +209,7 @@ void SetAppProperty(DesfireCardLayout propId, BYTE AppSlot, SIZET Value) { bool KeyIdValid(uint8_t AppSlot, uint8_t KeyId) { if (KeyId >= DESFIRE_MAX_KEYS || KeyId >= ReadMaxKeyCount(AppSlot)) { const char *debugMsg = PSTR("INVKEY-KeyId(%02x)-RdMax(%02x)"); - DEBUG_PRINT_P(debugMsg, KeyId, ReadMaxKeyCount(AppSlot)); + DEBUG_PRINT_P(debugMsg, KeyId, ReadMaxKeyCount(AppSlot)); return false; } return true; @@ -585,8 +585,8 @@ uint16_t CreateApp(const DESFireAidType Aid, uint8_t KeyCount, uint8_t KeySettin /* Allocate storage for the application structure itself */ AppDir.AppCacheStructBlockOffset[Slot] = AllocateBlocks(SELECTED_APP_CACHE_TYPE_BLOCK_SIZE); if (AppDir.AppCacheStructBlockOffset[Slot] == 0) { - const char *debugMsg = PSTR("X - alloc blks, slot = %d"); - DEBUG_PRINT_P(debugMsg, Slot); + const char *debugMsg = PSTR("X - alloc blks, slot = %d"); + DEBUG_PRINT_P(debugMsg, Slot); return STATUS_OUT_OF_EEPROM_ERROR; } /* Allocate storage for the application components */ @@ -628,8 +628,8 @@ uint16_t CreateApp(const DESFireAidType Aid, uint8_t KeyCount, uint8_t KeySettin } else { SIZET fileAccessRightsData[DESFIRE_MAX_FILES]; for (int fidx = 0; fidx < DESFIRE_MAX_FILES; fidx++) { - fileAccessRightsData[fidx] = 0x000f; - } + fileAccessRightsData[fidx] = 0x000f; + } WriteBlockBytes(fileAccessRightsData, appCacheData.FileAccessRights, sizeof(SIZET) * DESFIRE_MAX_FILES); } appCacheData.KeyVersionsArray = AllocateBlocks(APP_CACHE_KEY_VERSIONS_ARRAY_BLOCK_SIZE); @@ -669,8 +669,8 @@ uint16_t CreateApp(const DESFireAidType Aid, uint8_t KeyCount, uint8_t KeySettin } BYTE cryptoBlankKeyData[CRYPTO_MAX_KEY_SIZE]; memset(cryptoBlankKeyData, 0x00, CRYPTO_MAX_KEY_SIZE); - WriteBlockBytes(cryptoBlankKeyData, keyAddresses[0], CRYPTO_MAX_KEY_SIZE); - WriteBlockBytes(keyAddresses, appCacheData.KeyAddress, sizeof(SIZET) * DESFIRE_MAX_KEYS); + WriteBlockBytes(cryptoBlankKeyData, keyAddresses[0], CRYPTO_MAX_KEY_SIZE); + WriteBlockBytes(keyAddresses, appCacheData.KeyAddress, sizeof(SIZET) * DESFIRE_MAX_KEYS); } SIZET appCacheDataBlockId = AppDir.AppCacheStructBlockOffset[Slot]; WriteBlockBytes(&appCacheData, appCacheDataBlockId, sizeof(SelectedAppCacheType)); diff --git a/Firmware/Chameleon-Mini/Application/DESFire/DESFireApplicationDirectory.h b/Firmware/Chameleon-Mini/Application/DESFire/DESFireApplicationDirectory.h index aa7e962e..3c501617 100644 --- a/Firmware/Chameleon-Mini/Application/DESFire/DESFireApplicationDirectory.h +++ b/Firmware/Chameleon-Mini/Application/DESFire/DESFireApplicationDirectory.h @@ -37,7 +37,7 @@ This notice must be retained at the top of all source files where indicated. #ifdef MEMORY_LIMITED_TESTING #define DESFIRE_MAX_APPS (3) -#else +#else #ifdef DESFIRE_CUSTOM_MAX_APPS #define DESFIRE_MAX_APPS (DESFIRE_CUSTOM_MAX_APPS) #else @@ -49,7 +49,7 @@ This notice must be retained at the top of all source files where indicated. #ifdef MEMORY_LIMITED_TESTING #define DESFIRE_MAX_FILES (4) -#else +#else #ifdef DESFIRE_CUSTOM_MAX_FILES #define DESFIRE_MAX_FILES (DESFIRE_CUSTOM_MAX_FILES) #else @@ -59,7 +59,7 @@ This notice must be retained at the top of all source files where indicated. #ifdef MEMORY_LIMITED_TESTING #define DESFIRE_MAX_KEYS (2) -#else +#else #ifdef DESFIRE_CUSTOM_MAX_KEYS #define DESFIRE_MAX_KEYS (DESFIRE_CUSTOM_MAX_KEYS) #else diff --git a/Firmware/Chameleon-Mini/Application/DESFire/DESFireChameleonTerminal.c b/Firmware/Chameleon-Mini/Application/DESFire/DESFireChameleonTerminal.c index efdbaa9d..92e202af 100644 --- a/Firmware/Chameleon-Mini/Application/DESFire/DESFireChameleonTerminal.c +++ b/Firmware/Chameleon-Mini/Application/DESFire/DESFireChameleonTerminal.c @@ -242,13 +242,13 @@ CommandStatusIdType CommandDESFireSetTestingMode(char *OutParam, const char *InP CommandStatusIdType CommandDESFireGetCommMode(char *OutParam) { if (!IsDESFireConfiguration()) { ExitOnInvalidConfigurationError(OutParam); - } else if(DesfireCommMode == DESFIRE_COMMS_PLAINTEXT) { + } else if (DesfireCommMode == DESFIRE_COMMS_PLAINTEXT) { snprintf_P(OutParam, TERMINAL_BUFFER_SIZE, PSTR("Plaintext")); - } else if(DesfireCommMode == DESFIRE_COMMS_PLAINTEXT_MAC) { + } else if (DesfireCommMode == DESFIRE_COMMS_PLAINTEXT_MAC) { snprintf_P(OutParam, TERMINAL_BUFFER_SIZE, PSTR("Plaintext/MAC")); - } else if(DesfireCommMode == DESFIRE_COMMS_CIPHERTEXT_DES) { + } else if (DesfireCommMode == DESFIRE_COMMS_CIPHERTEXT_DES) { snprintf_P(OutParam, TERMINAL_BUFFER_SIZE, PSTR("Enciphered/DES")); - } else if(DesfireCommMode == DESFIRE_COMMS_CIPHERTEXT_AES128) { + } else if (DesfireCommMode == DESFIRE_COMMS_CIPHERTEXT_AES128) { snprintf_P(OutParam, TERMINAL_BUFFER_SIZE, PSTR("Enciphered/AES128")); } else { snprintf_P(OutParam, TERMINAL_BUFFER_SIZE, PSTR("Unknown")); diff --git a/Firmware/Chameleon-Mini/Application/DESFire/DESFireCrypto.c b/Firmware/Chameleon-Mini/Application/DESFire/DESFireCrypto.c index 3ba04aaf..fa0abeb3 100644 --- a/Firmware/Chameleon-Mini/Application/DESFire/DESFireCrypto.c +++ b/Firmware/Chameleon-Mini/Application/DESFire/DESFireCrypto.c @@ -122,32 +122,32 @@ const char *GetCommSettingsDesc(uint8_t cryptoType) { /* Code is adapted from @github/andrade/nfcjlib */ bool generateSessionKey(uint8_t *sessionKey, uint8_t *rndA, uint8_t *rndB, uint16_t cryptoType) { - switch(cryptoType) { - case CRYPTO_TYPE_DES: + switch (cryptoType) { + case CRYPTO_TYPE_DES: + memcpy(sessionKey, rndA, 4); + memcpy(sessionKey + 4, rndB, 4); + break; + case CRYPTO_TYPE_2KTDEA: + memcpy(sessionKey, rndA, 4); + memcpy(sessionKey + 4, rndB, 4); + memcpy(sessionKey + 8, rndA + 4, 4); + memcpy(sessionKey + 12, rndB + 4, 4); + break; + case CRYPTO_TYPE_3K3DES: + memcpy(sessionKey, rndA, 4); + memcpy(sessionKey + 4, rndB, 4); + memcpy(sessionKey + 8, rndA + 6, 4); + memcpy(sessionKey + 12, rndB + 6, 4); + memcpy(sessionKey + 16, rndA + 12, 4); + memcpy(sessionKey + 20, rndB + 12, 4); + break; + case CRYPTO_TYPE_AES128: memcpy(sessionKey, rndA, 4); - memcpy(sessionKey + 4, rndB, 4); - break; - case CRYPTO_TYPE_2KTDEA: - memcpy(sessionKey, rndA, 4); - memcpy(sessionKey + 4, rndB, 4); - memcpy(sessionKey + 8, rndA + 4, 4); - memcpy(sessionKey + 12, rndB + 4, 4); - break; - case CRYPTO_TYPE_3K3DES: - memcpy(sessionKey, rndA, 4); - memcpy(sessionKey + 4, rndB, 4); - memcpy(sessionKey + 8, rndA + 6, 4); - memcpy(sessionKey + 12, rndB + 6, 4); - memcpy(sessionKey + 16, rndA + 12, 4); - memcpy(sessionKey + 20, rndB + 12, 4); - break; - case CRYPTO_TYPE_AES128: - memcpy(sessionKey, rndA, 4); - memcpy(sessionKey + 4, rndB, 4); - memcpy(sessionKey + 8, rndA + 12, 4); - memcpy(sessionKey + 12, rndB + 12, 4); - break; - default: + memcpy(sessionKey + 4, rndB, 4); + memcpy(sessionKey + 8, rndA + 12, 4); + memcpy(sessionKey + 12, rndB + 12, 4); + break; + default: return false; } return true; diff --git a/Firmware/Chameleon-Mini/Application/DESFire/DESFireCrypto.h b/Firmware/Chameleon-Mini/Application/DESFire/DESFireCrypto.h index a21ceebb..10e637be 100644 --- a/Firmware/Chameleon-Mini/Application/DESFire/DESFireCrypto.h +++ b/Firmware/Chameleon-Mini/Application/DESFire/DESFireCrypto.h @@ -64,7 +64,7 @@ extern BYTE DesfireCommMode; /* Key sizes, block sizes (in bytes): */ #define CRYPTO_AES_KEY_SIZE (16) -#define CRYPTO_MAX_KEY_SIZE (24) +#define CRYPTO_MAX_KEY_SIZE (24) #define CRYPTO_MAX_BLOCK_SIZE (16) #define DESFIRE_AES_IV_SIZE (CRYPTO_AES_BLOCK_SIZE) #define CRYPTO_CHALLENGE_RESPONSE_BYTES (16) diff --git a/Firmware/Chameleon-Mini/Application/DESFire/DESFireInstructions.c b/Firmware/Chameleon-Mini/Application/DESFire/DESFireInstructions.c index b836f5bd..222e9d98 100644 --- a/Firmware/Chameleon-Mini/Application/DESFire/DESFireInstructions.c +++ b/Firmware/Chameleon-Mini/Application/DESFire/DESFireInstructions.c @@ -45,15 +45,15 @@ This notice must be retained at the top of all source files where indicated. DesfireSavedCommandStateType DesfireCommandState = { 0 }; -/* NOTE: The order of the structures in this buffer MUST be kept in - * ascending sorted order by the INS code. This property of the - * array has to be maintained as new commands and functions are - * added to keep CallInstructionHandler(uint8_t*, uint16_t) - * operating correctly. The instruction handler performs a - * binary search on the array to save time locating the correct - * C function to call to execute the command -- and this speedup - * helps keep timing issues at bay. DO NOT just append new command - * handlers to the end of the array, or insert them haphazardly in +/* NOTE: The order of the structures in this buffer MUST be kept in + * ascending sorted order by the INS code. This property of the + * array has to be maintained as new commands and functions are + * added to keep CallInstructionHandler(uint8_t*, uint16_t) + * operating correctly. The instruction handler performs a + * binary search on the array to save time locating the correct + * C function to call to execute the command -- and this speedup + * helps keep timing issues at bay. DO NOT just append new command + * handlers to the end of the array, or insert them haphazardly in * the middle !!! */ const __flash DESFireCommand DESFireCommandSet[] = { @@ -309,19 +309,19 @@ uint16_t CallInstructionHandler(uint8_t *Buffer, uint16_t ByteCount) { uint16_t curInsLower = 0, curInsUpper = sizeof(DESFireCommandSet) / sizeof(DESFireCommand) - 1; uint16_t curInsIndex; DESFireCommand dfCmd; - while(curInsUpper >= curInsLower) { + while (curInsUpper >= curInsLower) { curInsIndex = curInsLower + (curInsUpper + 1 - curInsLower) / 2; memcpy_P(&dfCmd, insLookupTableBuf + curInsIndex * sizeof(DESFireCommand), sizeof(DESFireCommand)); if (dfCmd.insCode == insCode) { - if (dfCmd.insFunc == NULL) { - return CmdNotImplemented(Buffer, ByteCount); - } - return dfCmd.insFunc(Buffer, ByteCount); - } else if (dfCmd.insCode < insCode) { - curInsLower = curInsIndex + 1; - } else { - curInsUpper = curInsIndex - 1; - } + if (dfCmd.insFunc == NULL) { + return CmdNotImplemented(Buffer, ByteCount); + } + return dfCmd.insFunc(Buffer, ByteCount); + } else if (dfCmd.insCode < insCode) { + curInsLower = curInsIndex + 1; + } else { + curInsUpper = curInsIndex - 1; + } } return ISO14443A_APP_NO_RESPONSE; } @@ -507,7 +507,7 @@ uint16_t EV0CmdAuthenticateLegacy2(uint8_t *Buffer, uint16_t ByteCount) { /* Set status for the next incoming command on error */ DesfireState = DESFIRE_IDLE; - + /* Validate command length */ if (ByteCount != 2 * CRYPTO_CHALLENGE_RESPONSE_BYTES + 1) { Buffer[0] = STATUS_LENGTH_ERROR; @@ -534,7 +534,7 @@ uint16_t EV0CmdAuthenticateLegacy2(uint8_t *Buffer, uint16_t ByteCount) { /* Check that the returned RndB matches what we sent in the previous round */ if (memcmp(DesfireCommandState.RndB, challengeRndB, CRYPTO_CHALLENGE_RESPONSE_BYTES)) { Buffer[0] = STATUS_AUTHENTICATION_ERROR; - return DESFIRE_STATUS_RESPONSE_SIZE; + return DESFIRE_STATUS_RESPONSE_SIZE; } /* Authenticated successfully */ @@ -1791,7 +1791,7 @@ uint16_t DesfireCmdAuthenticate3KTDEA2(uint8_t *Buffer, uint16_t ByteCount) { /* Check that the returned RndB matches what we sent in the previous round */ if (memcmp(DesfireCommandState.RndB, challengeRndB, CRYPTO_CHALLENGE_RESPONSE_BYTES)) { LogEntry(LOG_ERR_DESFIRE_GENERIC_ERROR, (const void *) challengeRndB, CRYPTO_CHALLENGE_RESPONSE_BYTES); - Buffer[0] = STATUS_AUTHENTICATION_ERROR; + Buffer[0] = STATUS_AUTHENTICATION_ERROR; return DESFIRE_STATUS_RESPONSE_SIZE; } @@ -1805,7 +1805,7 @@ uint16_t DesfireCmdAuthenticate3KTDEA2(uint8_t *Buffer, uint16_t ByteCount) { RotateArrayLeft(challengeRndA, challengeRndAB, CRYPTO_CHALLENGE_RESPONSE_BYTES); Encrypt3DESBuffer(CRYPTO_CHALLENGE_RESPONSE_BYTES, challengeRndAB, &Buffer[1], NULL, Key); - + generateSessionKey(SessionKey, challengeRndA, challengeRndB, CRYPTO_TYPE_3K3DES); /* Return the status on success */ diff --git a/Firmware/Chameleon-Mini/Application/DESFire/DESFirePICCHeaderLayout.h b/Firmware/Chameleon-Mini/Application/DESFire/DESFirePICCHeaderLayout.h index d1c6b144..be0479ac 100644 --- a/Firmware/Chameleon-Mini/Application/DESFire/DESFirePICCHeaderLayout.h +++ b/Firmware/Chameleon-Mini/Application/DESFire/DESFirePICCHeaderLayout.h @@ -145,7 +145,7 @@ This notice must be retained at the top of all source files where indicated. #define PICC_FORMAT_BYTE (0x00) #define PICC_EMPTY_BYTE (0x00) -typedef struct DESFIRE_FIRMWARE_PACKING DESFIRE_FIRMWARE_ALIGNAT{ +typedef struct DESFIRE_FIRMWARE_PACKING DESFIRE_FIRMWARE_ALIGNAT { /* Static data: does not change during the PICC's lifetime. * We will add Chameleon Mini terminal commands to enable * resetting this data so tags can be emulated authentically. diff --git a/Firmware/Chameleon-Mini/Application/MifareDESFire.c b/Firmware/Chameleon-Mini/Application/MifareDESFire.c index 822174e8..e05ba826 100644 --- a/Firmware/Chameleon-Mini/Application/MifareDESFire.c +++ b/Firmware/Chameleon-Mini/Application/MifareDESFire.c @@ -61,12 +61,12 @@ static void MifareDesfireAppInitLocal(uint8_t StorageSize, uint8_t Version, bool DesfireFromHalt = false; switch (Version) { case MIFARE_DESFIRE_EV1: - InitialisePiccBackendEV1(StorageSize, FormatPICC); - break; - case MIFARE_DESFIRE_EV0: - default: /* Fall through */ - InitialisePiccBackendEV0(StorageSize, FormatPICC); - break; + InitialisePiccBackendEV1(StorageSize, FormatPICC); + break; + case MIFARE_DESFIRE_EV0: + default: /* Fall through */ + InitialisePiccBackendEV0(StorageSize, FormatPICC); + break; } DesfireCommMode = DESFIRE_DEFAULT_COMMS_STANDARD; } @@ -129,7 +129,7 @@ uint16_t MifareDesfireProcessCommand(uint8_t *Buffer, uint16_t ByteCount) { return ISO14443A_APP_NO_RESPONSE; } else if (Buffer[0] != STATUS_ADDITIONAL_FRAME) { DesfireState = DESFIRE_IDLE; - uint16_t ReturnBytes = CallInstructionHandler(Buffer, ByteCount); + uint16_t ReturnBytes = CallInstructionHandler(Buffer, ByteCount); return ReturnBytes; } @@ -172,8 +172,8 @@ uint16_t MifareDesfireProcess(uint8_t *Buffer, uint16_t BitCount) { size_t ByteCount = (BitCount + BITS_PER_BYTE - 1) / BITS_PER_BYTE; DesfireCmdCLA = Buffer[0]; if ((ByteCount >= 8 && DesfireCLA(Buffer[0]) && Buffer[2] == 0x00 && - Buffer[3] == 0x00 && (Buffer[4] == ByteCount - 6 || Buffer[4] == ByteCount - 8)) || Iso7816CLA(DesfireCmdCLA)) { - // Wrapped native command structure: + Buffer[3] == 0x00 && (Buffer[4] == ByteCount - 6 || Buffer[4] == ByteCount - 8)) || Iso7816CLA(DesfireCmdCLA)) { + // Wrapped native command structure: /* Unwrap the PDU from ISO 7816-4 */ // Check CRC bytes appended to the buffer: // -- Actually, just ignore parity problems if they exist, @@ -238,8 +238,8 @@ uint16_t MifareDesfireAppProcess(uint8_t *Buffer, uint16_t BitCount) { ISO14443AAppendCRCA(Buffer, ProcessedByteCount); ProcessedBitCount += 2 * BITS_PER_BYTE; return ProcessedBitCount; - } else if((ReturnedBytes = CallInstructionHandler(Buffer, ByteCount)) != ISO14443A_APP_NO_RESPONSE) { - return ReturnedBytes; + } else if ((ReturnedBytes = CallInstructionHandler(Buffer, ByteCount)) != ISO14443A_APP_NO_RESPONSE) { + return ReturnedBytes; } else { return ISO144433APiccProcess(Buffer, BitCount); } diff --git a/Firmware/Chameleon-Mini/Configuration.c b/Firmware/Chameleon-Mini/Configuration.c index a319aba4..cdc5ac86 100644 --- a/Firmware/Chameleon-Mini/Configuration.c +++ b/Firmware/Chameleon-Mini/Configuration.c @@ -96,8 +96,8 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = { .CodecDeInitFunc = CodecDeInitDummy, .CodecTaskFunc = CodecTaskDummy, .ApplicationInitFunc = ApplicationInitDummy, - .ApplicationInitRunOnceFunc = ApplicationInitDummy, - .ApplicationResetFunc = ApplicationResetDummy, + .ApplicationInitRunOnceFunc = ApplicationInitDummy, + .ApplicationResetFunc = ApplicationResetDummy, .ApplicationTaskFunc = ApplicationTaskDummy, .ApplicationTickFunc = ApplicationTickDummy, .ApplicationProcessFunc = ApplicationProcessDummy, @@ -114,8 +114,8 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = { .CodecDeInitFunc = ISO14443ACodecDeInit, .CodecTaskFunc = ISO14443ACodecTask, .ApplicationInitFunc = MifareUltralightAppInit, - .ApplicationInitRunOnceFunc = MifareUltralightAppInit, - .ApplicationResetFunc = MifareUltralightAppReset, + .ApplicationInitRunOnceFunc = MifareUltralightAppInit, + .ApplicationResetFunc = MifareUltralightAppReset, .ApplicationTaskFunc = MifareUltralightAppTask, .ApplicationTickFunc = ApplicationTickDummy, .ApplicationProcessFunc = MifareUltralightAppProcess, @@ -131,8 +131,8 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = { .CodecDeInitFunc = ISO14443ACodecDeInit, .CodecTaskFunc = ISO14443ACodecTask, .ApplicationInitFunc = MifareUltralightCAppInit, - .ApplicationInitRunOnceFunc = MifareUltralightCAppInit, - .ApplicationResetFunc = MifareUltralightCAppReset, + .ApplicationInitRunOnceFunc = MifareUltralightCAppInit, + .ApplicationResetFunc = MifareUltralightCAppReset, .ApplicationTaskFunc = MifareUltralightAppTask, .ApplicationTickFunc = ApplicationTickDummy, .ApplicationProcessFunc = MifareUltralightAppProcess, @@ -148,8 +148,8 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = { .CodecDeInitFunc = ISO14443ACodecDeInit, .CodecTaskFunc = ISO14443ACodecTask, .ApplicationInitFunc = MifareUltralightEV11AppInit, - .ApplicationInitRunOnceFunc = MifareUltralightEV11AppInit, - .ApplicationResetFunc = MifareUltralightAppReset, + .ApplicationInitRunOnceFunc = MifareUltralightEV11AppInit, + .ApplicationResetFunc = MifareUltralightAppReset, .ApplicationTaskFunc = MifareUltralightAppTask, .ApplicationTickFunc = ApplicationTickDummy, .ApplicationProcessFunc = MifareUltralightAppProcess, @@ -165,8 +165,8 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = { .CodecDeInitFunc = ISO14443ACodecDeInit, .CodecTaskFunc = ISO14443ACodecTask, .ApplicationInitFunc = MifareUltralightEV12AppInit, - .ApplicationInitRunOnceFunc = MifareUltralightEV12AppInit, - .ApplicationResetFunc = MifareUltralightAppReset, + .ApplicationInitRunOnceFunc = MifareUltralightEV12AppInit, + .ApplicationResetFunc = MifareUltralightAppReset, .ApplicationTaskFunc = MifareUltralightAppTask, .ApplicationTickFunc = ApplicationTickDummy, .ApplicationProcessFunc = MifareUltralightAppProcess, @@ -184,8 +184,8 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = { .CodecDeInitFunc = ISO14443ACodecDeInit, .CodecTaskFunc = ISO14443ACodecTask, .ApplicationInitFunc = MifareClassicAppInitMini4B, - .ApplicationInitRunOnceFunc = MifareClassicAppInitMini4B, - .ApplicationResetFunc = MifareClassicAppReset, + .ApplicationInitRunOnceFunc = MifareClassicAppInitMini4B, + .ApplicationResetFunc = MifareClassicAppReset, .ApplicationTaskFunc = MifareClassicAppTask, .ApplicationTickFunc = ApplicationTickDummy, .ApplicationProcessFunc = MifareClassicAppProcess, @@ -203,8 +203,8 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = { .CodecDeInitFunc = ISO14443ACodecDeInit, .CodecTaskFunc = ISO14443ACodecTask, .ApplicationInitFunc = MifareClassicAppInit1K, - .ApplicationInitRunOnceFunc = MifareClassicAppInit1K, - .ApplicationResetFunc = MifareClassicAppReset, + .ApplicationInitRunOnceFunc = MifareClassicAppInit1K, + .ApplicationResetFunc = MifareClassicAppReset, .ApplicationTaskFunc = MifareClassicAppTask, .ApplicationTickFunc = ApplicationTickDummy, .ApplicationProcessFunc = MifareClassicAppProcess, @@ -222,8 +222,8 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = { .CodecDeInitFunc = ISO14443ACodecDeInit, .CodecTaskFunc = ISO14443ACodecTask, .ApplicationInitFunc = MifareClassicAppInit1K7B, - .ApplicationInitRunOnceFunc = MifareClassicAppInit1K7B, - .ApplicationResetFunc = MifareClassicAppReset, + .ApplicationInitRunOnceFunc = MifareClassicAppInit1K7B, + .ApplicationResetFunc = MifareClassicAppReset, .ApplicationTaskFunc = MifareClassicAppTask, .ApplicationTickFunc = ApplicationTickDummy, .ApplicationProcessFunc = MifareClassicAppProcess, @@ -241,8 +241,8 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = { .CodecDeInitFunc = ISO14443ACodecDeInit, .CodecTaskFunc = ISO14443ACodecTask, .ApplicationInitFunc = MifareClassicAppInit4K, - .ApplicationInitRunOnceFunc = MifareClassicAppInit4K, - .ApplicationResetFunc = MifareClassicAppReset, + .ApplicationInitRunOnceFunc = MifareClassicAppInit4K, + .ApplicationResetFunc = MifareClassicAppReset, .ApplicationTaskFunc = MifareClassicAppTask, .ApplicationTickFunc = ApplicationTickDummy, .ApplicationProcessFunc = MifareClassicAppProcess, @@ -260,8 +260,8 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = { .CodecDeInitFunc = ISO14443ACodecDeInit, .CodecTaskFunc = ISO14443ACodecTask, .ApplicationInitFunc = MifareClassicAppInit4K7B, - .ApplicationInitRunOnceFunc = MifareClassicAppInit4K7B, - .ApplicationResetFunc = MifareClassicAppReset, + .ApplicationInitRunOnceFunc = MifareClassicAppInit4K7B, + .ApplicationResetFunc = MifareClassicAppReset, .ApplicationTaskFunc = MifareClassicAppTask, .ApplicationTickFunc = ApplicationTickDummy, .ApplicationProcessFunc = MifareClassicAppProcess, @@ -279,8 +279,8 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = { .CodecDeInitFunc = Sniff14443ACodecDeInit, .CodecTaskFunc = Sniff14443ACodecTask, .ApplicationInitFunc = Sniff14443AAppInit, - .ApplicationInitRunOnceFunc = Sniff14443AAppInit, - .ApplicationResetFunc = Sniff14443AAppReset, + .ApplicationInitRunOnceFunc = Sniff14443AAppInit, + .ApplicationResetFunc = Sniff14443AAppReset, .ApplicationTaskFunc = Sniff14443AAppTask, .ApplicationTickFunc = Sniff14443AAppTick, .ApplicationProcessFunc = Sniff14443AAppProcess, @@ -298,8 +298,8 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = { .CodecDeInitFunc = Reader14443ACodecDeInit, .CodecTaskFunc = Reader14443ACodecTask, .ApplicationInitFunc = Reader14443AAppInit, - .ApplicationInitRunOnceFunc = Reader14443AAppInit, - .ApplicationResetFunc = Reader14443AAppReset, + .ApplicationInitRunOnceFunc = Reader14443AAppInit, + .ApplicationResetFunc = Reader14443AAppReset, .ApplicationTaskFunc = Reader14443AAppTask, .ApplicationTickFunc = Reader14443AAppTick, .ApplicationProcessFunc = Reader14443AAppProcess, @@ -317,8 +317,8 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = { .CodecDeInitFunc = ISO15693CodecDeInit, .CodecTaskFunc = ISO15693CodecTask, .ApplicationInitFunc = VicinityAppInit, - .ApplicationInitRunOnceFunc = VicinityAppInit, - .ApplicationResetFunc = VicinityAppReset, + .ApplicationInitRunOnceFunc = VicinityAppInit, + .ApplicationResetFunc = VicinityAppReset, .ApplicationTaskFunc = VicinityAppTask, .ApplicationTickFunc = VicinityAppTick, .ApplicationProcessFunc = VicinityAppProcess, @@ -336,8 +336,8 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = { .CodecDeInitFunc = ISO15693CodecDeInit, .CodecTaskFunc = ISO15693CodecTask, .ApplicationInitFunc = ApplicationInitDummy, - .ApplicationInitRunOnceFunc = ApplicationInitDummy, - .ApplicationResetFunc = ApplicationResetDummy, + .ApplicationInitRunOnceFunc = ApplicationInitDummy, + .ApplicationResetFunc = ApplicationResetDummy, .ApplicationTaskFunc = ApplicationTaskDummy, .ApplicationTickFunc = ApplicationTickDummy, .ApplicationProcessFunc = ApplicationProcessDummy, @@ -355,8 +355,8 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = { .CodecDeInitFunc = ISO15693CodecDeInit, .CodecTaskFunc = ISO15693CodecTask, .ApplicationInitFunc = Sl2s2002AppInit, - .ApplicationInitRunOnceFunc = Sl2s2002AppInit, - .ApplicationResetFunc = Sl2s2002AppReset, + .ApplicationInitRunOnceFunc = Sl2s2002AppInit, + .ApplicationResetFunc = Sl2s2002AppReset, .ApplicationTaskFunc = Sl2s2002AppTask, .ApplicationTickFunc = Sl2s2002AppTick, .ApplicationProcessFunc = Sl2s2002AppProcess, @@ -374,8 +374,8 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = { .CodecDeInitFunc = ISO15693CodecDeInit, .CodecTaskFunc = ISO15693CodecTask, .ApplicationInitFunc = TITagitstandardAppInit, - .ApplicationInitRunOnceFunc = TITagitstandardAppInit, - .ApplicationResetFunc = TITagitstandardAppReset, + .ApplicationInitRunOnceFunc = TITagitstandardAppInit, + .ApplicationResetFunc = TITagitstandardAppReset, .ApplicationTaskFunc = TITagitstandardAppTask, .ApplicationTickFunc = TITagitstandardAppTick, .ApplicationProcessFunc = TITagitstandardAppProcess, @@ -393,8 +393,8 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = { .CodecDeInitFunc = ISO15693CodecDeInit, .CodecTaskFunc = ISO15693CodecTask, .ApplicationInitFunc = TITagitplusAppInit, - .ApplicationInitRunOnceFunc = TITagitplusAppInit, - .ApplicationResetFunc = TITagitplusAppReset, + .ApplicationInitRunOnceFunc = TITagitplusAppInit, + .ApplicationResetFunc = TITagitplusAppReset, .ApplicationTaskFunc = TITagitplusAppTask, .ApplicationTickFunc = TITagitplusAppTick, .ApplicationProcessFunc = TITagitplusAppProcess, @@ -412,8 +412,8 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = { .CodecDeInitFunc = ISO15693CodecDeInit, .CodecTaskFunc = ISO15693CodecTask, .ApplicationInitFunc = EM4233AppInit, - .ApplicationInitRunOnceFunc = EM4233AppInit, - .ApplicationResetFunc = EM4233AppReset, + .ApplicationInitRunOnceFunc = EM4233AppInit, + .ApplicationResetFunc = EM4233AppReset, .ApplicationTaskFunc = EM4233AppTask, .ApplicationTickFunc = EM4233AppTick, .ApplicationProcessFunc = EM4233AppProcess, @@ -431,8 +431,8 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = { .CodecDeInitFunc = ISO14443ACodecDeInit, .CodecTaskFunc = ISO14443ACodecTask, .ApplicationInitFunc = NTAG215AppInit, - .ApplicationInitRunOnceFunc = NTAG215AppInit, - .ApplicationResetFunc = NTAG215AppReset, + .ApplicationInitRunOnceFunc = NTAG215AppInit, + .ApplicationResetFunc = NTAG215AppReset, .ApplicationTaskFunc = NTAG215AppTask, .ApplicationTickFunc = ApplicationTickDummy, .ApplicationProcessFunc = NTAG215AppProcess, @@ -449,8 +449,8 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = { .CodecDeInitFunc = ISO14443ACodecDeInit, .CodecTaskFunc = ISO14443ACodecTask, .ApplicationInitFunc = MifareDesfireEV0AppInit, - .ApplicationInitRunOnceFunc = MifareDesfireEV0AppInitRunOnce, - .ApplicationResetFunc = MifareDesfireAppReset, + .ApplicationInitRunOnceFunc = MifareDesfireEV0AppInitRunOnce, + .ApplicationResetFunc = MifareDesfireAppReset, .ApplicationTaskFunc = MifareDesfireAppTask, .ApplicationTickFunc = MifareDesfireAppTick, .ApplicationProcessFunc = MifareDesfireAppProcess, @@ -465,8 +465,8 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = { .CodecDeInitFunc = ISO14443ACodecDeInit, .CodecTaskFunc = ISO14443ACodecTask, .ApplicationInitFunc = MifareDesfire2kEV1AppInit, - .ApplicationInitRunOnceFunc = MifareDesfire2kEV1AppInitRunOnce, - .ApplicationResetFunc = MifareDesfireAppReset, + .ApplicationInitRunOnceFunc = MifareDesfire2kEV1AppInitRunOnce, + .ApplicationResetFunc = MifareDesfireAppReset, .ApplicationTaskFunc = MifareDesfireAppTask, .ApplicationTickFunc = MifareDesfireAppTick, .ApplicationProcessFunc = MifareDesfireAppProcess, @@ -481,8 +481,8 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = { .CodecDeInitFunc = ISO14443ACodecDeInit, .CodecTaskFunc = ISO14443ACodecTask, .ApplicationInitFunc = MifareDesfire4kEV1AppInit, - .ApplicationInitRunOnceFunc = MifareDesfire4kEV1AppInitRunOnce, - .ApplicationResetFunc = MifareDesfireAppReset, + .ApplicationInitRunOnceFunc = MifareDesfire4kEV1AppInitRunOnce, + .ApplicationResetFunc = MifareDesfireAppReset, .ApplicationTaskFunc = MifareDesfireAppTask, .ApplicationTickFunc = MifareDesfireAppTick, .ApplicationProcessFunc = MifareDesfireAppProcess, @@ -510,10 +510,10 @@ void ConfigurationSetById(ConfigurationEnum Configuration, bool appInitRunOnce) CommandLinePendingTaskBreak(); // break possibly pending task GlobalSettings.ActiveSettingPtr->Configuration = Configuration; - + /* Blank memory scape slate for the newly set configuration */ MemoryClear(); - + /* Copy struct from PROGMEM to RAM */ memcpy_P(&ActiveConfiguration, &ConfigurationTable[Configuration], sizeof(ConfigurationType)); @@ -556,7 +556,7 @@ bool ConfigurationSetByName(const char *Configuration, bool appInitRunOnce) { MapIdType Id; if (MapTextToId(ConfigurationMap, ARRAY_COUNT(ConfigurationMap), Configuration, &Id)) { ConfigurationSetById(Id, appInitRunOnce); - LogEntry(LOG_INFO_CONFIG_SET, Configuration, StringLength(Configuration, CONFIGURATION_NAME_LENGTH_MAX - 1)); + LogEntry(LOG_INFO_CONFIG_SET, Configuration, StringLength(Configuration, CONFIGURATION_NAME_LENGTH_MAX - 1)); return true; } else { return false; diff --git a/Firmware/Chameleon-Mini/Configuration.h b/Firmware/Chameleon-Mini/Configuration.h index 3e5f82fe..2ed04938 100644 --- a/Firmware/Chameleon-Mini/Configuration.h +++ b/Firmware/Chameleon-Mini/Configuration.h @@ -114,10 +114,10 @@ typedef struct { */ /** Function that initializes the application. */ void (*ApplicationInitFunc)(void); - /** Function to initialize one-time-only data in the application - * (like the filesystem for `CONFIG=MF_DESFIRE`). This function does not - * get called when changing slots to run a preexisting configuration or when the - * device is powered on and reinitializes the last loaded slot. + /** Function to initialize one-time-only data in the application + * (like the filesystem for `CONFIG=MF_DESFIRE`). This function does not + * get called when changing slots to run a preexisting configuration or when the + * device is powered on and reinitializes the last loaded slot. */ void (*ApplicationInitRunOnceFunc)(void); /** Function that resets the application. */ diff --git a/Firmware/Chameleon-Mini/Makefile b/Firmware/Chameleon-Mini/Makefile index 31d1ecf2..20f987d9 100644 --- a/Firmware/Chameleon-Mini/Makefile +++ b/Firmware/Chameleon-Mini/Makefile @@ -100,8 +100,8 @@ SETTINGS += -DDESFIRE_DEFAULT_LOGGING_MODE=DEBUGGING #SETTINGS += -DDESFIRE_DEFAULT_LOGGING_MODE=OFF #Set a default testing mode setting (0 = OFF, non-NULL = ON): -#SETTINGS += -DDESFIRE_DEFAULT_TESTING_MODE=0 -SETTINGS += -DDESFIRE_DEFAULT_TESTING_MODE=1 +SETTINGS += -DDESFIRE_DEFAULT_TESTING_MODE=0 +#SETTINGS += -DDESFIRE_DEFAULT_TESTING_MODE=1 #Feature: Use randomized UIDs that mask the actual secret UID until #the tag has been issued a successful authentication sequence: diff --git a/Firmware/Chameleon-Mini/Memory.c b/Firmware/Chameleon-Mini/Memory.c index d0800210..889a4ea9 100644 --- a/Firmware/Chameleon-Mini/Memory.c +++ b/Firmware/Chameleon-Mini/Memory.c @@ -374,7 +374,7 @@ void MemoryReadBlockInSetting(void *Buffer, uint16_t Address, uint16_t ByteCount return; uint16_t ShiftedAddress = Address + GlobalSettings.ActiveSettingIdx * MEMORY_SIZE_PER_SETTING; if (ShiftedAddress < Address) - return; + return; FRAMRead(Buffer, ShiftedAddress, ByteCount); } diff --git a/Firmware/Chameleon-Mini/Terminal/Commands.c b/Firmware/Chameleon-Mini/Terminal/Commands.c index 501813c0..6db401a8 100644 --- a/Firmware/Chameleon-Mini/Terminal/Commands.c +++ b/Firmware/Chameleon-Mini/Terminal/Commands.c @@ -46,8 +46,8 @@ CommandStatusIdType CommandSetConfig(char *OutMessage, const char *InParam) { return COMMAND_INFO_OK_WITH_TEXT_ID; } else if (ConfigurationByNameIsValid(InParam)) { ConfigurationSetByName(InParam, true); - SETTING_UPDATE(GlobalSettings.ActiveSettingPtr->Configuration); - return COMMAND_INFO_OK_ID; + SETTING_UPDATE(GlobalSettings.ActiveSettingPtr->Configuration); + return COMMAND_INFO_OK_ID; } else { return COMMAND_ERR_INVALID_PARAM_ID; } diff --git a/Firmware/Chameleon-Mini/Tests/ChameleonTerminal.c b/Firmware/Chameleon-Mini/Tests/ChameleonTerminal.c index c55c41f9..ec3d112c 100644 --- a/Firmware/Chameleon-Mini/Tests/ChameleonTerminal.c +++ b/Firmware/Chameleon-Mini/Tests/ChameleonTerminal.c @@ -9,14 +9,14 @@ CommandStatusIdType CommandRunTests(char *OutParam) { const ChameleonTestType testCases[] = { #ifdef ENABLE_CRYPTO_TESTS #ifdef ENABLE_CRYPTO_TDEA_TESTS - &CryptoTDEATestCase1, + &CryptoTDEATestCase1, &CryptoTDEATestCase2, #endif #ifdef ENABLE_CRYPTO_3DES_TESTS &Crypto3DESTestCase1, #endif #ifdef ENABLE_CRYPTO_AES_TESTS - &CryptoAESTestCase1, + &CryptoAESTestCase1, &CryptoAESTestCase2, #endif #endif diff --git a/Firmware/Chameleon-Mini/Tests/CryptoTests.c b/Firmware/Chameleon-Mini/Tests/CryptoTests.c index 5ce35fdf..8b364b1f 100644 --- a/Firmware/Chameleon-Mini/Tests/CryptoTests.c +++ b/Firmware/Chameleon-Mini/Tests/CryptoTests.c @@ -57,25 +57,25 @@ bool CryptoTDEATestCase2(char *OutParam, uint16_t MaxOutputLength) { #endif #ifdef ENABLE_CRYPTO_3DES_TESTS -// Data from: +// Data from: // https://boringssl.googlesource.com/boringssl/+/2490/crypto/cipher/test/cipher_test.txt#33 bool Crypto3DESTestCase1(char *OutParam, uint16_t MaxOutputLength) { const uint8_t KeyData[3 * CRYPTO_DES_BLOCK_SIZE] = { - 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, - 0xf1, 0xe0, 0xd3, 0xc2, 0xb5, 0xa4, 0x97, 0x86, - 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 + 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, + 0xf1, 0xe0, 0xd3, 0xc2, 0xb5, 0xa4, 0x97, 0x86, + 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 }; const uint8_t PlainText[4 * CRYPTO_DES_BLOCK_SIZE] = { - 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x20, - 0x4E, 0x6F, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x74, 0x69, 0x6D, 0x65, 0x20, - 0x66, 0x6F, 0x72, 0x20, 0x00, 0x00, 0x00, 0x00 + 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x20, + 0x4E, 0x6F, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74, + 0x68, 0x65, 0x20, 0x74, 0x69, 0x6D, 0x65, 0x20, + 0x66, 0x6F, 0x72, 0x20, 0x00, 0x00, 0x00, 0x00 }; const uint8_t CipherText[4 * CRYPTO_DES_BLOCK_SIZE] = { - 0x3F, 0xE3, 0x01, 0xC9, 0x62, 0xAC, 0x01, 0xD0, - 0x22, 0x13, 0x76, 0x3C, 0x1C, 0xBD, 0x4C, 0xDC, - 0x79, 0x96, 0x57, 0xC0, 0x64, 0xEC, 0xF5, 0xD4, - 0x1C, 0x67, 0x38, 0x12, 0xCF, 0xDE, 0x96, 0x75 + 0x3F, 0xE3, 0x01, 0xC9, 0x62, 0xAC, 0x01, 0xD0, + 0x22, 0x13, 0x76, 0x3C, 0x1C, 0xBD, 0x4C, 0xDC, + 0x79, 0x96, 0x57, 0xC0, 0x64, 0xEC, 0xF5, 0xD4, + 0x1C, 0x67, 0x38, 0x12, 0xCF, 0xDE, 0x96, 0x75 }; const uint8_t IV[CRYPTO_DES_BLOCK_SIZE] = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 @@ -85,7 +85,7 @@ bool Crypto3DESTestCase1(char *OutParam, uint16_t MaxOutputLength) { Encrypt3DESBuffer(dataBytes, PlainText, tempBuffer, IV, KeyData); if (memcmp(tempBuffer, CipherText, dataBytes)) { strcat_P(OutParam, PSTR("> ENC: ")); - OutParam += 7; + OutParam += 7; BufferToHexString(OutParam, MaxOutputLength - 7, tempBuffer, dataBytes); strcat_P(OutParam, PSTR("\r\n")); return false; @@ -93,7 +93,7 @@ bool Crypto3DESTestCase1(char *OutParam, uint16_t MaxOutputLength) { Decrypt3DESBuffer(dataBytes, tempBuffer, CipherText, IV, KeyData); if (memcmp(tempBuffer, PlainText, dataBytes)) { strcat_P(OutParam, PSTR("> DEC: ")); - OutParam += 7; + OutParam += 7; BufferToHexString(OutParam, MaxOutputLength - 7, tempBuffer, dataBytes); strcat_P(OutParam, PSTR("\r\n")); return false;