From 71762595efc9e655aecdee45af12087c0a7bdd12 Mon Sep 17 00:00:00 2001 From: Maxie Dion Schmidt Date: Mon, 31 Jan 2022 12:54:23 -0500 Subject: [PATCH] Stashing incremental testing release code --- .../Chameleon-Mini/Application/CryptoMAC.h | 38 ++++++++++++++++++ .../Application/DESFire/DESFireInstructions.c | 6 +-- .../Application/DESFire/DESFireKeyUtils.h | 39 +++++++++++++++++++ Firmware/Chameleon-Mini/Makefile | 6 +-- 4 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 Firmware/Chameleon-Mini/Application/CryptoMAC.h create mode 100644 Firmware/Chameleon-Mini/Application/DESFire/DESFireKeyUtils.h diff --git a/Firmware/Chameleon-Mini/Application/CryptoMAC.h b/Firmware/Chameleon-Mini/Application/CryptoMAC.h new file mode 100644 index 00000000..c36db1ce --- /dev/null +++ b/Firmware/Chameleon-Mini/Application/CryptoMAC.h @@ -0,0 +1,38 @@ +/* +The DESFire stack portion of this firmware source +is free software written by Maxie Dion Schmidt (@maxieds): +You can redistribute it and/or modify +it under the terms of this license. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +The complete source distribution of +this firmware is available at the following link: +https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack. + +Based in part on the original DESFire code created by +@dev-zzo (GitHub handle) [Dmitry Janushkevich] available at +https://github.com/dev-zzo/ChameleonMini/tree/desfire. + +This notice must be retained at the top of all source files where indicated. +*/ + +/* + * CryptoMAC.h : + * Maxie D. Schmidt (github.com/maxieds) + */ + +#ifndef __CRYPTO_MAC_H__ +#define __CRYPTO_MAC_H__ + +#include "DESFire/DESFireCrypto.h" +#include "CryptoTDEA.h" +#include "CryptoAES128.h" + + + + + +#endif diff --git a/Firmware/Chameleon-Mini/Application/DESFire/DESFireInstructions.c b/Firmware/Chameleon-Mini/Application/DESFire/DESFireInstructions.c index fcb7ba22..257b2675 100644 --- a/Firmware/Chameleon-Mini/Application/DESFire/DESFireInstructions.c +++ b/Firmware/Chameleon-Mini/Application/DESFire/DESFireInstructions.c @@ -453,8 +453,8 @@ uint16_t EV0CmdAuthenticateLegacy1(uint8_t *Buffer, uint16_t ByteCount) { } /* Indicate that we are in DES key authentication land */ - Key = &SessionKey; keySize = GetDefaultCryptoMethodKeySize(CRYPTO_TYPE_3K3DES); + Key = &SessionKey; DesfireCommandState.KeyId = KeyId; DesfireCommandState.CryptoMethodType = CRYPTO_TYPE_3K3DES; DesfireCommandState.ActiveCommMode = GetCryptoMethodCommSettings(CRYPTO_TYPE_3K3DES); @@ -510,10 +510,10 @@ uint16_t EV0CmdAuthenticateLegacy2(uint8_t *Buffer, uint16_t ByteCount) { } /* Reset parameters for authentication from the first exchange */ - Key = &SessionKey; KeyId = DesfireCommandState.KeyId; cryptoKeyType = DesfireCommandState.CryptoMethodType; keySize = GetDefaultCryptoMethodKeySize(CRYPTO_TYPE_3K3DES); + Key = &SessionKey; ReadAppKey(SelectedApp.Slot, KeyId, *Key, keySize); /* Decrypt the challenge sent back to get RndA and a shifted RndB */ @@ -1763,10 +1763,10 @@ uint16_t DesfireCmdAuthenticate3KTDEA2(uint8_t *Buffer, uint16_t ByteCount) { } /* Reset parameters for authentication from the first exchange */ - Key = &SessionKey; KeyId = DesfireCommandState.KeyId; cryptoKeyType = DesfireCommandState.CryptoMethodType; keySize = GetDefaultCryptoMethodKeySize(CRYPTO_TYPE_3K3DES); + Key = &SessionKey; ReadAppKey(SelectedApp.Slot, KeyId, *Key, keySize); /* Decrypt the challenge sent back to get RndA and a shifted RndB */ diff --git a/Firmware/Chameleon-Mini/Application/DESFire/DESFireKeyUtils.h b/Firmware/Chameleon-Mini/Application/DESFire/DESFireKeyUtils.h new file mode 100644 index 00000000..502235e1 --- /dev/null +++ b/Firmware/Chameleon-Mini/Application/DESFire/DESFireKeyUtils.h @@ -0,0 +1,39 @@ +/* +The DESFire stack portion of this firmware source +is free software written by Maxie Dion Schmidt (@maxieds): +You can redistribute it and/or modify +it under the terms of this license. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +The complete source distribution of +this firmware is available at the following link: +https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack. + +Based in part on the original DESFire code created by +@dev-zzo (GitHub handle) [Dmitry Janushkevich] available at +https://github.com/dev-zzo/ChameleonMini/tree/desfire. + +This notice must be retained at the top of all source files where indicated. +*/ + +/* + * DESFireKeyUtils.h : + * Maxie D. Schmidt (github.com/maxieds) + */ + +#ifndef __DESFIRE_KEY_UTILS_H__ +#define __DESFIRE_KEY_UTILS_H__ + +#include "DESFireCrypto.h" + +/* TODO: Placeholder for: + * => Key (re)initialization + * => Configuring the session key on the fly + * => CommSettings: PLAIN | MACED | ENCIPHERD + * => Possibly others + */ + +#endif diff --git a/Firmware/Chameleon-Mini/Makefile b/Firmware/Chameleon-Mini/Makefile index 5e79f6c4..aaf43b80 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: @@ -133,7 +133,7 @@ SETTINGS += -DDESFIRE_MIN_OUTGOING_LOGSIZE=1 #Option to save space with the "Application/Crypto1.c" code by storing large tables #in PROGMEM. Note that this will slow down the read times when accessing these tables: -#SETTINGS += -DDESFIRE_CRYPTO1_SAVE_SPACE +SETTINGS += -DDESFIRE_CRYPTO1_SAVE_SPACE DESFIRE_MAINSRC = Application/DESFire