Skip to content

Commit

Permalink
Merge pull request #31 from Nitrokey/pr_10
Browse files Browse the repository at this point in the history
Fix warnings (2) / code cleanup
  • Loading branch information
szszszsz committed Nov 19, 2016
2 parents 78a8015 + 7d9362f commit 8912d3c
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 119 deletions.
72 changes: 8 additions & 64 deletions src/ccid/CcidLocalAccess.c
Expand Up @@ -634,24 +634,17 @@ int CcidAesDec (int nSendLength, unsigned char* cSendData, int nReceiveLength, u

u32 getRandomNumber (u32 Size_u32, u8 * Data_pu8)
{
u32 Ret_u32;

u32 i;

time_t now;

static u8 FlasgTimeIsSet_u8 = FALSE;

// Size ok ?
if (APDU_MAX_RESPONSE_LEN <= Size_u32)
{
return (FALSE);
}

// Get a random number from smartcard
Ret_u32 = CcidGetChallenge (Size_u32, Data_pu8);
CcidGetChallenge (Size_u32, Data_pu8);

#ifdef GENERATE_RANDOM_NUMBER_WITH_2ND_SOURCE
// FIXME check does this actually add entropy?
// Paranoia: if the random number is not really random, xor it with
// another random number from a second source
if (FALSE == FlasgTimeIsSet_u8)
Expand Down Expand Up @@ -879,40 +872,14 @@ int getAID (void)

InitSCTStruct (&tSCT);

unsigned short cRet;

unsigned char nReturnSize;

CcidSelectOpenPGPApp ();
cRet = CcidGetData (0x00, 0x4F, &nReturnSize);
CcidGetData (0x00, 0x4F, &nReturnSize);

return nReturnSize;
}

uint32_t getSerialNumber (void)
{

uint32_t serial;

uint8_t buffer[4];

InitSCTStruct (&tSCT);

unsigned short cRet;

unsigned char nReturnSize;

CcidSelectOpenPGPApp ();
cRet = CcidGetData (0x00, 0x4F, &nReturnSize);



return 0;


}


uint8_t getByteOfData (uint8_t x)
{

Expand All @@ -926,8 +893,6 @@ uint8_t cardAuthenticate (uint8_t * password)

unsigned short cRet;

unsigned char nReturnSize;

CcidSelectOpenPGPApp ();
cRet = CcidVerifyPin (3, password);

Expand All @@ -946,8 +911,6 @@ uint8_t userAuthenticate (uint8_t * password)

unsigned short cRet;

unsigned char nReturnSize;

CcidSelectOpenPGPApp ();
cRet = CcidVerifyPin (1, password);

Expand Down Expand Up @@ -1007,8 +970,6 @@ uint8_t changeUserPin (uint8_t * password, uint8_t * new_password)

unsigned short cRet;

unsigned char nReturnSize;

CcidSelectOpenPGPApp ();
cRet = CcidChangePin (1, password, new_password);

Expand All @@ -1027,8 +988,6 @@ uint8_t changeAdminPin (uint8_t * password, uint8_t * new_password)

unsigned short cRet;

unsigned char nReturnSize;

CcidSelectOpenPGPApp ();
cRet = CcidChangePin (3, password, new_password);

Expand Down Expand Up @@ -1153,6 +1112,7 @@ unsigned int nRet;

uint8_t testScAesKey (int nLen, unsigned char* pcKey)
{
//function unused in NK Pro
int nRet;

unsigned char acBufferOut[32];
Expand All @@ -1166,32 +1126,16 @@ unsigned char acBufferOut[32];

nRet = CcidAesDec (nLen, pcKey, nLen, acBufferOut);

switch (nRet)
{
case APDU_ANSWER_COMMAND_CORRECT:
memcpy (pcKey, acBufferOut, nLen);
return TRUE;
case APDU_ANSWER_REF_DATA_NOT_FOUND:
memset (pcKey, 0, nLen);
return FALSE;
default:
nRet;
}
/*
if (APDU_ANSWER_COMMAND_CORRECT == nRet) { //CI_LocalPrintf ("Decrypted AES key : "); //HexPrint (nLen,acBufferOut); //CI_LocalPrintf
("\r\n"); } else { memset (pcKey,0,nLen); //CI_LocalPrintf ("fail\n\r"); return (FALSE); }
memcpy (pcKey,acBufferOut,nLen); return (TRUE); */
if (APDU_ANSWER_COMMAND_CORRECT == nRet)
return (TRUE);
else
return (FALSE);
}

uint8_t testSendUserPW2 (unsigned char* pcPW)
{
unsigned short nRet;

int n;

n = strlen ((char *) pcPW);

// CI_LocalPrintf ("Send user password : ");
nRet = CcidVerifyPin (2, pcPW);
if (APDU_ANSWER_COMMAND_CORRECT == nRet)
Expand Down
28 changes: 0 additions & 28 deletions src/ccid/smartcard/smartcard.c
Expand Up @@ -186,34 +186,6 @@ static void NVIC_Configuration (void)
NVIC_Init (&NVIC_InitStructure);
}

/*******************************************************************************
* Function Name : EXTI_Configuration
* Description : Configures the External Interrupts controller.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
static void EXTI_Configuration (void)
{
EXTI_InitTypeDef EXTI_InitStructure;

/* Smartcard OFF Pin */
GPIO_EXTILineConfig (SC_PortSource, SC_PinSource_1);
GPIO_EXTILineConfig (SC_PortSource, SC_PinSource_2);

// GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource8);
// GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource6);

/* Clear SC EXTI Line Pending Bit */
EXTI_ClearITPendingBit (SC_EXTI);

EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_Line = SC_EXTI;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init (&EXTI_InitStructure);
}

/*******************************************************************************
* Function Name : GPIO_Configuration_Smartcard
* Description : configure the poweron port for the smartcard
Expand Down
4 changes: 1 addition & 3 deletions src/hotp/hotp.c
Expand Up @@ -104,12 +104,10 @@ extern uint8_t HID_GetReport_Value[32 + 1];
uint32_t crc (uint32_t time)
{

int i, j;
int i;

uint32_t value = time << 8;

uint32_t crc;

for (i = 0; i < 24; i++)
{
if (value & 0x80000000)
Expand Down
1 change: 0 additions & 1 deletion src/keyboard/keyboard.c
Expand Up @@ -126,7 +126,6 @@ uint8_t i;
void sendNumberN (uint32_t number, uint8_t len)
{
uint8_t result[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
uint32_t tmp_number = number;

uint8_t i;

Expand Down
3 changes: 0 additions & 3 deletions src/pwd-safe/FlashStorage.c
Expand Up @@ -946,9 +946,6 @@ u32 i1;

uint8_t page_buffer[FLASH_PAGE_SIZE];

uint8_t* page;


// Clear user page
for (i1 = 0; i1 < 7; i1++)
{
Expand Down
4 changes: 0 additions & 4 deletions src/pwd-safe/HandleAesStorageKey.c
Expand Up @@ -252,10 +252,6 @@ u32 BuildNewXorPattern_u32 (void)
{
u8 XorPattern_au8[AES_KEYSIZE_256_BIT];

time_t now;

u32 i;

#ifdef LOCAL_DEBUG
// CI_TickLocalPrintf ("BuildNewXorPattern_u32\r\n");
#endif
Expand Down
16 changes: 0 additions & 16 deletions src/pwd-safe/password_safe.c
Expand Up @@ -133,12 +133,8 @@ typePasswordSafeSlot_st PWS_BufferSlot_st;

u8 PWS_WriteSlot (u8 Slot_u8, typePasswordSafeSlot_st * Slot_st)
{
u8* WritePointer_pu8;

u8* AesKeyPointer_pu8;

void* p;

CI_LocalPrintf
("PWS_WriteSlot: Slot %d. Name -%s- Loginname -%s- PW -%s-\r\n",
Slot_u8, Slot_st->SlotName_au8, Slot_st->SlotLoginName_au8, Slot_st->SlotPassword_au8);
Expand Down Expand Up @@ -187,9 +183,6 @@ int i;
CI_LocalPrintf ("\n\r");
#endif

// Get write address
WritePointer_pu8 = (u8 *) (PWS_FLASH_START_ADDRESS + (PWS_SLOT_LENGTH * Slot_u8));

// Write to flash
uint8_t page_buffer[FLASH_PAGE_SIZE];

Expand All @@ -198,7 +191,6 @@ uint8_t* page = (uint8_t *) PWS_FLASH_START_ADDRESS;
memcpy (page_buffer, page, FLASH_PAGE_SIZE);
memcpy (page_buffer + (PWS_SLOT_LENGTH * Slot_u8), Slot_st_encrypted, PWS_SLOT_LENGTH);

p = (void *) Slot_st_encrypted;
FLASH_Unlock ();
FLASH_ErasePage (PWS_FLASH_START_ADDRESS);
write_data_to_flash (page_buffer, FLASH_PAGE_SIZE, PWS_FLASH_START_ADDRESS);
Expand All @@ -224,12 +216,8 @@ uint8_t* page = (uint8_t *) PWS_FLASH_START_ADDRESS;

u8 PWS_EraseSlot (u8 Slot_u8)
{
u8* WritePointer_pu8;

u8* AesKeyPointer_pu8;

void* p;

#if (defined __GNUC__) && (defined __AVR32__)
__attribute__ ((__aligned__ (4)))
#elif (defined __ICCAVR32__)
Expand Down Expand Up @@ -285,9 +273,6 @@ int i;
CI_LocalPrintf ("\n\r");
#endif

// Get write address
WritePointer_pu8 = (u8 *) (PWS_FLASH_START_ADDRESS + (PWS_SLOT_LENGTH * Slot_u8));

// Write to flash
uint8_t page_buffer[FLASH_PAGE_SIZE];

Expand All @@ -296,7 +281,6 @@ uint8_t* page = (uint8_t *) PWS_FLASH_START_ADDRESS;
memcpy (page_buffer, page, FLASH_PAGE_SIZE);
memcpy (page_buffer + (PWS_SLOT_LENGTH * Slot_u8), Slot_st_encrypted, PWS_SLOT_LENGTH);

p = (void *) Slot_st_encrypted;
FLASH_Unlock ();
FLASH_ErasePage (PWS_FLASH_START_ADDRESS);
write_data_to_flash (page_buffer, FLASH_PAGE_SIZE, PWS_FLASH_START_ADDRESS);
Expand Down

0 comments on commit 8912d3c

Please sign in to comment.