Minor stuff

This commit is contained in:
Aurora 2016-09-22 15:09:52 +02:00
parent 7a3d15c48b
commit a3fd55036a
3 changed files with 16 additions and 16 deletions

View File

@ -49,7 +49,7 @@ diff -uNr a/source/brahma.c b/source/brahma.c
+ if (p) { + if (p) {
+ fseek(p , 0, SEEK_END); + fseek(p , 0, SEEK_END);
+ psize = ftell(p); + psize = ftell(p);
+ if (psize < 39 && psize > 5) { + if (psize > 5 && psize < 39) {
+ char path[psize + 1]; + char path[psize + 1];
+ +
+ fseek(p, 0, SEEK_SET); + fseek(p, 0, SEEK_SET);

View File

@ -71,8 +71,8 @@ payload_maxsize equ 0x100000 ; Maximum size for the payload (maximum that CakeB
bytes_read: .word 0 bytes_read: .word 0
fopen: .ascii "OPEN" fopen: .ascii "OPEN"
.pool .pool
fname: .dcw "sdmc:/arm9loaderhax.bin" fname: .dcw "sdmc:/arm9loaderhax.bin"
.word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
.align 4 .align 4
kernelcode_start: kernelcode_start:

View File

@ -127,14 +127,14 @@ static void aes_setiv(const void *iv, u32 mode)
static void aes_advctr(void *ctr, u32 val, u32 mode) static void aes_advctr(void *ctr, u32 val, u32 mode)
{ {
u32 *ctr32 = (u32 *)ctr; u32 *ctr32 = (u32 *)ctr;
int i; int i;
if(mode & AES_INPUT_BE) if(mode & AES_INPUT_BE)
{ {
for(i = 0; i < 4; ++i) // Endian swap for(i = 0; i < 4; ++i) // Endian swap
BSWAP32(ctr32[i]); BSWAP32(ctr32[i]);
} }
if(mode & AES_INPUT_NORMAL) if(mode & AES_INPUT_NORMAL)
{ {
ADD_u128_u32(ctr32[3], ctr32[2], ctr32[1], ctr32[0], val); ADD_u128_u32(ctr32[3], ctr32[2], ctr32[1], ctr32[0], val);
@ -143,7 +143,7 @@ static void aes_advctr(void *ctr, u32 val, u32 mode)
{ {
ADD_u128_u32(ctr32[0], ctr32[1], ctr32[2], ctr32[3], val); ADD_u128_u32(ctr32[0], ctr32[1], ctr32[2], ctr32[3], val);
} }
if(mode & AES_INPUT_BE) if(mode & AES_INPUT_BE)
{ {
for(i = 0; i < 4; ++i) // Endian swap for(i = 0; i < 4; ++i) // Endian swap
@ -177,13 +177,13 @@ static void aes_batch(void *dst, const void *src, u32 blockCount)
{ {
*REG_AESBLKCNT = blockCount << 16; *REG_AESBLKCNT = blockCount << 16;
*REG_AESCNT |= AES_CNT_START; *REG_AESCNT |= AES_CNT_START;
const u32 *src32 = (const u32 *)src; const u32 *src32 = (const u32 *)src;
u32 *dst32 = (u32 *)dst; u32 *dst32 = (u32 *)dst;
u32 wbc = blockCount; u32 wbc = blockCount;
u32 rbc = blockCount; u32 rbc = blockCount;
while(rbc) while(rbc)
{ {
if(wbc && ((*REG_AESCNT & 0x1F) <= 0xC)) // There's space for at least 4 ints if(wbc && ((*REG_AESCNT & 0x1F) <= 0xC)) // There's space for at least 4 ints
@ -194,7 +194,7 @@ static void aes_batch(void *dst, const void *src, u32 blockCount)
*REG_AESWRFIFO = *src32++; *REG_AESWRFIFO = *src32++;
wbc--; wbc--;
} }
if(rbc && ((*REG_AESCNT & (0x1F << 0x5)) >= (0x4 << 0x5))) // At least 4 ints available for read if(rbc && ((*REG_AESCNT & (0x1F << 0x5)) >= (0x4 << 0x5))) // At least 4 ints available for read
{ {
*dst32++ = *REG_AESRDFIFO; *dst32++ = *REG_AESRDFIFO;
@ -238,7 +238,7 @@ static void aes(void *dst, const void *src, u32 blockCount, void *iv, u32 mode,
memcpy(iv, dst + (blocks - 1) * AES_BLOCK_SIZE, AES_BLOCK_SIZE); memcpy(iv, dst + (blocks - 1) * AES_BLOCK_SIZE, AES_BLOCK_SIZE);
aes_change_ctrmode(iv, AES_INPUT_BE | AES_INPUT_NORMAL, ivMode); aes_change_ctrmode(iv, AES_INPUT_BE | AES_INPUT_NORMAL, ivMode);
} }
// Advance counter for CTR mode // Advance counter for CTR mode
else if((mode & AES_ALL_MODES) == AES_CTR_MODE) else if((mode & AES_ALL_MODES) == AES_CTR_MODE)
aes_advctr(iv, blocks, ivMode); aes_advctr(iv, blocks, ivMode);
@ -258,7 +258,7 @@ static void sha(void *res, const void *src, u32 size, u32 mode)
{ {
sha_wait_idle(); sha_wait_idle();
*REG_SHA_CNT = mode | SHA_CNT_OUTPUT_ENDIAN | SHA_NORMAL_ROUND; *REG_SHA_CNT = mode | SHA_CNT_OUTPUT_ENDIAN | SHA_NORMAL_ROUND;
const u32 *src32 = (const u32 *)src; const u32 *src32 = (const u32 *)src;
int i; int i;
while(size >= 0x40) while(size >= 0x40)
@ -274,12 +274,12 @@ static void sha(void *res, const void *src, u32 size, u32 mode)
size -= 0x40; size -= 0x40;
} }
sha_wait_idle(); sha_wait_idle();
memcpy((void *)REG_SHA_INFIFO, src32, size); memcpy((void *)REG_SHA_INFIFO, src32, size);
*REG_SHA_CNT = (*REG_SHA_CNT & ~SHA_NORMAL_ROUND) | SHA_FINAL_ROUND; *REG_SHA_CNT = (*REG_SHA_CNT & ~SHA_NORMAL_ROUND) | SHA_FINAL_ROUND;
while(*REG_SHA_CNT & SHA_FINAL_ROUND); while(*REG_SHA_CNT & SHA_FINAL_ROUND);
sha_wait_idle(); sha_wait_idle();
@ -297,8 +297,8 @@ static void sha(void *res, const void *src, u32 size, u32 mode)
static u8 __attribute__((aligned(4))) nandCtr[AES_BLOCK_SIZE]; static u8 __attribute__((aligned(4))) nandCtr[AES_BLOCK_SIZE];
static u8 nandSlot; static u8 nandSlot;
static u32 fatStart; static u32 fatStart;
static bool didShaHashBackup = false;
static u8 __attribute__((aligned(4))) shaHashBackup[SHA_256_HASH_SIZE]; static u8 __attribute__((aligned(4))) shaHashBackup[SHA_256_HASH_SIZE];
static bool didShaHashBackup = false;
void ctrNandInit(void) void ctrNandInit(void)
{ {