Skip to content

Commit

Permalink
Bug fixes to observations in emsec#313
Browse files Browse the repository at this point in the history
  • Loading branch information
maxieds committed Feb 11, 2022
1 parent a02f214 commit ba3c736
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ uint16_t EV0CmdAuthenticateLegacy1(uint8_t *Buffer, uint16_t ByteCount) {
}
/* Make sure that this key is AES, and figure out its byte size */
BYTE cryptoKeyType = ReadKeyCryptoType(SelectedApp.Slot, KeyId);
if (!CryptoTypeDES(cryptoKeyType)) {
if (!CryptoType3KTDEA(cryptoKeyType)) {
Buffer[0] = STATUS_NO_SUCH_KEY;
return DESFIRE_STATUS_RESPONSE_SIZE;
}
Expand Down Expand Up @@ -492,7 +492,7 @@ uint16_t EV0CmdAuthenticateLegacy1(uint8_t *Buffer, uint16_t ByteCount) {
&Buffer[1], NULL, Key);

/* Scrub the key */
memset(*Key, 0, keySize);
memset(Key, 0, keySize);

/* Done */
DesfireState = DESFIRE_LEGACY_AUTHENTICATE2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void ReadBlockBytes(void *Buffer, SIZET StartBlock, SIZET Count) {
DEBUG_PRINT_P(rbbLogMsg, StartBlock, MEMORY_SIZE_PER_SETTING);
return;
}
MemoryDownloadBlock(Buffer, StartBlock * BLOCKWISE_IO_MULTIPLIER, Count);
MemoryReadBlockInSetting(Buffer, StartBlock * BLOCKWISE_IO_MULTIPLIER, Count);
}

void WriteBlockBytesMain(const void *Buffer, SIZET StartBlock, SIZET Count) {
Expand All @@ -54,7 +54,7 @@ void WriteBlockBytesMain(const void *Buffer, SIZET StartBlock, SIZET Count) {
DEBUG_PRINT_P(wbbLogMsg, StartBlock, MEMORY_SIZE_PER_SETTING);
return;
}
MemoryUploadBlock(Buffer, StartBlock * BLOCKWISE_IO_MULTIPLIER, Count);
MemoryWriteBlockInSetting(Buffer, StartBlock * BLOCKWISE_IO_MULTIPLIER, Count);
}

uint16_t AllocateBlocksMain(uint16_t BlockCount) {
Expand Down
2 changes: 1 addition & 1 deletion Firmware/Chameleon-Mini/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/** @file */
#include "Common.h"

#define LOG_SIZE 2048
#define LOG_SIZE 2048
#define FRAM_LOG_ADDR_ADDR 0x4000 // start of the second half of FRAM
#define FRAM_LOG_START_ADDR 0x4002 // directly after the address
#define FRAM_LOG_SIZE 0x3FFE // the whole second half (minus the 2 Bytes of Address)
Expand Down
18 changes: 18 additions & 0 deletions Firmware/Chameleon-Mini/Memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,25 @@ void MemoryWriteBlock(const void *Buffer, uint16_t Address, uint16_t ByteCount)
if (ByteCount == 0)
return;
FRAMWrite(Buffer, Address, ByteCount);
LEDHook(LED_MEMORY_CHANGED, LED_ON);
}

void MemoryReadBlockInSetting(void *Buffer, uint16_t Address, uint16_t ByteCount) {
if (ByteCount == 0 || ByteCount >= MEMORY_SIZE_PER_SETTING)
return;
uint16_t ShiftedAddress = Address + GlobalSettings.ActiveSettingIdx * MEMORY_SIZE_PER_SETTING;
if (ShiftedAddress < Address)
return;
FRAMRead(Buffer, ShiftedAddress, ByteCount);
}

void MemoryWriteBlockInSetting(const void *Buffer, uint16_t Address, uint16_t ByteCount) {
if (ByteCount == 0 || ByteCount >= MEMORY_SIZE_PER_SETTING)
return;
uint16_t ShiftedAddress = Address + GlobalSettings.ActiveSettingIdx * MEMORY_SIZE_PER_SETTING;
if (ShiftedAddress < Address)
return;
FRAMWrite(Buffer, ShiftedAddress, ByteCount);
LEDHook(LED_MEMORY_CHANGED, LED_ON);
}

Expand Down
2 changes: 2 additions & 0 deletions Firmware/Chameleon-Mini/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
void MemoryInit(void);
void MemoryReadBlock(void *Buffer, uint16_t Address, uint16_t ByteCount);
void MemoryWriteBlock(const void *Buffer, uint16_t Address, uint16_t ByteCount);
void MemoryReadBlockInSetting(void *Buffer, uint16_t Address, uint16_t ByteCount);
void MemoryWriteBlockInSetting(const void *Buffer, uint16_t Address, uint16_t ByteCount);
void MemoryClear(void);

void MemoryRecall(void);
Expand Down
4 changes: 0 additions & 4 deletions Firmware/Chameleon-Mini/Terminal/Terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
#define TERMINAL_VBUS_PORT PORTD
#define TERMINAL_VBUS_MASK PIN5_bm

#ifdef MEMORY_LIMITED_TESTING
#define TERMINAL_BUFFER_SIZE 256
#else
#define TERMINAL_BUFFER_SIZE 512
#endif

typedef enum {
TERMINAL_UNINITIALIZED,
Expand Down

0 comments on commit ba3c736

Please sign in to comment.