Merge readPin and verifyPin
This commit is contained in:
parent
e2d828a4a2
commit
82699f3e00
@ -457,13 +457,13 @@ void arm9Loader(u8 *arm9Section)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void computePINHash(u8 out[32], u8 *in, u32 blockCount)
|
void computePinHash(u8 *out, u8 *in, u32 blockCount)
|
||||||
{
|
{
|
||||||
u8 __attribute__((aligned(4))) cid[0x10];
|
u8 __attribute__((aligned(4))) cid[0x10];
|
||||||
u8 __attribute__((aligned(4))) cipherText[0x10];
|
u8 __attribute__((aligned(4))) cipherText[0x10];
|
||||||
sdmmc_get_cid(1, (u32 *)cid);
|
sdmmc_get_cid(1, (u32 *)cid);
|
||||||
|
|
||||||
aes_use_keyslot(4); // console-unique keyslot which keys are set by the Arm9 bootROM
|
aes_use_keyslot(4); //Console-unique keyslot whose keys are set by the ARM9 bootROM
|
||||||
aes(cipherText, in, blockCount, cid, AES_CBC_ENCRYPT_MODE, AES_INPUT_BE | AES_INPUT_NORMAL);
|
aes(cipherText, in, blockCount, cid, AES_CBC_ENCRYPT_MODE, AES_INPUT_BE | AES_INPUT_NORMAL);
|
||||||
|
|
||||||
sha(out, cipherText, 0x10, SHA_256_MODE);
|
sha(out, cipherText, 0x10, SHA_256_MODE);
|
||||||
|
@ -100,8 +100,7 @@
|
|||||||
#define SHA_1_HASH_SIZE (160 / 8)
|
#define SHA_1_HASH_SIZE (160 / 8)
|
||||||
|
|
||||||
extern u32 emuOffset;
|
extern u32 emuOffset;
|
||||||
extern bool isN3DS;
|
extern bool isN3DS, isDevUnit;
|
||||||
extern bool isDevUnit;
|
|
||||||
extern FirmwareSource firmSource;
|
extern FirmwareSource firmSource;
|
||||||
|
|
||||||
void ctrNandInit(void);
|
void ctrNandInit(void);
|
||||||
@ -109,5 +108,4 @@ u32 ctrNandRead(u32 sector, u32 sectorCount, u8 *outbuf);
|
|||||||
void setRSAMod0DerivedKeys(void);
|
void setRSAMod0DerivedKeys(void);
|
||||||
void decryptExeFs(u8 *inbuf);
|
void decryptExeFs(u8 *inbuf);
|
||||||
void arm9Loader(u8 *arm9Section);
|
void arm9Loader(u8 *arm9Section);
|
||||||
|
void computePinHash(u8 *out, u8 *in, u32 blockCount);
|
||||||
void computePINHash(u8 out[32], u8 *in, u32 blockCount);
|
|
@ -129,12 +129,7 @@ void main(void)
|
|||||||
//Boot options aren't being forced
|
//Boot options aren't being forced
|
||||||
if(needConfig != DONT_CONFIGURE)
|
if(needConfig != DONT_CONFIGURE)
|
||||||
{
|
{
|
||||||
PINData pin;
|
bool pinExists = CONFIG(8) && verifyPin();
|
||||||
|
|
||||||
bool pinExists = CONFIG(8) && readPin(&pin);
|
|
||||||
|
|
||||||
//If we get here we should check the PIN (if it exists) in all cases
|
|
||||||
if(pinExists) verifyPin(&pin);
|
|
||||||
|
|
||||||
//If no configuration file exists or SELECT is held, load configuration menu
|
//If no configuration file exists or SELECT is held, load configuration menu
|
||||||
bool shouldLoadConfigMenu = needConfig == CREATE_CONFIGURATION || ((pressed & BUTTON_SELECT) && !(pressed & BUTTON_L1));
|
bool shouldLoadConfigMenu = needConfig == CREATE_CONFIGURATION || ((pressed & BUTTON_SELECT) && !(pressed & BUTTON_L1));
|
||||||
|
52
source/pin.c
52
source/pin.c
@ -34,23 +34,7 @@
|
|||||||
#include "pin.h"
|
#include "pin.h"
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
|
|
||||||
bool readPin(PINData *out)
|
static char pinKeyToLetter(u32 pressed)
|
||||||
{
|
|
||||||
if(fileRead(out, "/luma/pin.bin") != sizeof(PINData) ||
|
|
||||||
memcmp(out->magic, "PINF", 4) != 0 ||
|
|
||||||
out->formatVersionMajor != PIN_VERSIONMAJOR ||
|
|
||||||
out->formatVersionMinor != PIN_VERSIONMINOR)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
u8 __attribute__((aligned(4))) zeroes[16] = {0};
|
|
||||||
u8 __attribute__((aligned(4))) tmp[32];
|
|
||||||
|
|
||||||
computePINHash(tmp, zeroes, 1);
|
|
||||||
|
|
||||||
return memcmp(out->testHash, tmp, 32) == 0; //Test vector verification (SD card has, or hasn't been used on another console)
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline char PINKeyToLetter(u32 pressed)
|
|
||||||
{
|
{
|
||||||
const char keys[] = "AB--------XY";
|
const char keys[] = "AB--------XY";
|
||||||
|
|
||||||
@ -89,7 +73,7 @@ void newPin(bool allowSkipping)
|
|||||||
if(pressed & BUTTON_START) return;
|
if(pressed & BUTTON_START) return;
|
||||||
if(!pressed) continue;
|
if(!pressed) continue;
|
||||||
|
|
||||||
char key = PINKeyToLetter(pressed);
|
char key = pinKeyToLetter(pressed);
|
||||||
enteredPassword[cnt++] = (u8)key; //Add character to password
|
enteredPassword[cnt++] = (u8)key; //Add character to password
|
||||||
|
|
||||||
//Visualize character on screen
|
//Visualize character on screen
|
||||||
@ -105,10 +89,10 @@ void newPin(bool allowSkipping)
|
|||||||
pin.formatVersionMajor = PIN_VERSIONMAJOR;
|
pin.formatVersionMajor = PIN_VERSIONMAJOR;
|
||||||
pin.formatVersionMinor = PIN_VERSIONMINOR;
|
pin.formatVersionMinor = PIN_VERSIONMINOR;
|
||||||
|
|
||||||
computePINHash(tmp, zeroes, 1);
|
computePinHash(tmp, zeroes, 1);
|
||||||
memcpy(pin.testHash, tmp, 32);
|
memcpy(pin.testHash, tmp, 32);
|
||||||
|
|
||||||
computePINHash(tmp, enteredPassword, (PIN_LENGTH + 15) / 16);
|
computePinHash(tmp, enteredPassword, (PIN_LENGTH + 15) / 16);
|
||||||
memcpy(pin.hash, tmp, 32);
|
memcpy(pin.hash, tmp, 32);
|
||||||
|
|
||||||
if(!fileWrite(&pin, "/luma/pin.bin", sizeof(PINData)))
|
if(!fileWrite(&pin, "/luma/pin.bin", sizeof(PINData)))
|
||||||
@ -119,10 +103,26 @@ void newPin(bool allowSkipping)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void verifyPin(PINData *in)
|
bool verifyPin(void)
|
||||||
{
|
{
|
||||||
initScreens();
|
initScreens();
|
||||||
|
|
||||||
|
PINData pin;
|
||||||
|
|
||||||
|
if(fileRead(&pin, "/luma/pin.bin") != sizeof(PINData) ||
|
||||||
|
memcmp(pin.magic, "PINF", 4) != 0 ||
|
||||||
|
pin.formatVersionMajor != PIN_VERSIONMAJOR ||
|
||||||
|
pin.formatVersionMinor != PIN_VERSIONMINOR)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
u8 __attribute__((aligned(4))) zeroes[16] = {0};
|
||||||
|
u8 __attribute__((aligned(4))) tmp[32];
|
||||||
|
|
||||||
|
computePinHash(tmp, zeroes, 1);
|
||||||
|
|
||||||
|
//Test vector verification (SD card has, or hasn't been used on another console)
|
||||||
|
if(memcmp(pin.testHash, tmp, 32) != 0) return false;
|
||||||
|
|
||||||
//Pad to AES block length with zeroes
|
//Pad to AES block length with zeroes
|
||||||
u8 __attribute__((aligned(4))) enteredPassword[16 * ((PIN_LENGTH + 15) / 16)] = {0};
|
u8 __attribute__((aligned(4))) enteredPassword[16 * ((PIN_LENGTH + 15) / 16)] = {0};
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ void verifyPin(PINData *in)
|
|||||||
|
|
||||||
if(!pressed) continue;
|
if(!pressed) continue;
|
||||||
|
|
||||||
char key = PINKeyToLetter(pressed);
|
char key = pinKeyToLetter(pressed);
|
||||||
enteredPassword[cnt++] = (u8)key; //Add character to password
|
enteredPassword[cnt++] = (u8)key; //Add character to password
|
||||||
|
|
||||||
//Visualize character on screen
|
//Visualize character on screen
|
||||||
@ -157,10 +157,8 @@ void verifyPin(PINData *in)
|
|||||||
|
|
||||||
if(cnt >= PIN_LENGTH)
|
if(cnt >= PIN_LENGTH)
|
||||||
{
|
{
|
||||||
u8 __attribute__((aligned(4))) tmp[32];
|
computePinHash(tmp, enteredPassword, (PIN_LENGTH + 15) / 16);
|
||||||
|
unlock = memcmp(pin.hash, tmp, 32) == 0;
|
||||||
computePINHash(tmp, enteredPassword, (PIN_LENGTH + 15) / 16);
|
|
||||||
unlock = memcmp(in->hash, tmp, 32) == 0;
|
|
||||||
|
|
||||||
if(!unlock)
|
if(!unlock)
|
||||||
{
|
{
|
||||||
@ -173,4 +171,6 @@ void verifyPin(PINData *in)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
@ -43,6 +43,5 @@ typedef struct __attribute__((packed))
|
|||||||
u8 hash[32];
|
u8 hash[32];
|
||||||
} PINData;
|
} PINData;
|
||||||
|
|
||||||
bool readPin(PINData* out);
|
|
||||||
void newPin(bool allowSkipping);
|
void newPin(bool allowSkipping);
|
||||||
void verifyPin(PINData *in);
|
bool verifyPin(void);
|
Reference in New Issue
Block a user