aboutsummaryrefslogtreecommitdiff
path: root/src/DSi.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/DSi.cpp')
-rw-r--r--src/DSi.cpp64
1 files changed, 32 insertions, 32 deletions
diff --git a/src/DSi.cpp b/src/DSi.cpp
index 2f92a5d..dc066a7 100644
--- a/src/DSi.cpp
+++ b/src/DSi.cpp
@@ -55,8 +55,8 @@ u32 SCFG_EXT[2];
u32 SCFG_MC;
u16 SCFG_RST;
-u8 ARM9iBIOS[0x10000];
-u8 ARM7iBIOS[0x10000];
+u8 ARM9iBIOS[0x10000] = { 0 };
+u8 ARM7iBIOS[0x10000] = { 0 };
u32 MBK[2][9];
@@ -324,8 +324,8 @@ void DecryptModcryptArea(u32 offset, u32 size, u8* iv)
DSi_AES::DeriveNormalKey(keyX, keyY, tmp);
}
- DSi_AES::Swap16(key, tmp);
- DSi_AES::Swap16(tmp, iv);
+ Bswap128(key, tmp);
+ Bswap128(tmp, iv);
AES_init_ctx_iv(&ctx, key, tmp);
// find a matching binary area
@@ -367,21 +367,21 @@ void DecryptModcryptArea(u32 offset, u32 size, u8* iv)
for (u32 i = 0; i < size; i+=16)
{
- u8 data[16];
+ u32 data[4];
- *(u32*)&data[0] = ARM9Read32(binaryaddr+i);
- *(u32*)&data[4] = ARM9Read32(binaryaddr+i+4);
- *(u32*)&data[8] = ARM9Read32(binaryaddr+i+8);
- *(u32*)&data[12] = ARM9Read32(binaryaddr+i+12);
+ data[0] = ARM9Read32(binaryaddr+i);
+ data[1] = ARM9Read32(binaryaddr+i+4);
+ data[2] = ARM9Read32(binaryaddr+i+8);
+ data[3] = ARM9Read32(binaryaddr+i+12);
- DSi_AES::Swap16(tmp, data);
- AES_CTR_xcrypt_buffer(&ctx, tmp, 16);
- DSi_AES::Swap16(data, tmp);
+ Bswap128(tmp, data);
+ AES_CTR_xcrypt_buffer(&ctx, tmp, sizeof(tmp));
+ Bswap128(data, tmp);
- ARM9Write32(binaryaddr+i, *(u32*)&data[0]);
- ARM9Write32(binaryaddr+i+4, *(u32*)&data[4]);
- ARM9Write32(binaryaddr+i+8, *(u32*)&data[8]);
- ARM9Write32(binaryaddr+i+12, *(u32*)&data[12]);
+ ARM9Write32(binaryaddr+i, data[0]);
+ ARM9Write32(binaryaddr+i+4, data[1]);
+ ARM9Write32(binaryaddr+i+8, data[2]);
+ ARM9Write32(binaryaddr+i+12, data[3]);
}
}
@@ -893,7 +893,7 @@ bool LoadNAND()
*(u32*)&tmp[4] = -bootparams[3];
*(u32*)&tmp[8] = ~bootparams[3];
*(u32*)&tmp[12] = 0;
- for (int i = 0; i < 16; i++) boot2iv[i] = tmp[15-i];
+ Bswap128(boot2iv, tmp);
AES_init_ctx_iv(&ctx, boot2key, boot2iv);
@@ -901,24 +901,24 @@ bool LoadNAND()
dstaddr = bootparams[2];
for (u32 i = 0; i < bootparams[3]; i += 16)
{
- u8 data[16];
+ u32 data[4];
FileRead(data, 16, 1, nand);
- for (int j = 0; j < 16; j++) tmp[j] = data[15-j];
+ Bswap128(tmp, data);
AES_CTR_xcrypt_buffer(&ctx, tmp, 16);
- for (int j = 0; j < 16; j++) data[j] = tmp[15-j];
+ Bswap128(data, tmp);
- ARM9Write32(dstaddr, *(u32*)&data[0]); dstaddr += 4;
- ARM9Write32(dstaddr, *(u32*)&data[4]); dstaddr += 4;
- ARM9Write32(dstaddr, *(u32*)&data[8]); dstaddr += 4;
- ARM9Write32(dstaddr, *(u32*)&data[12]); dstaddr += 4;
+ ARM9Write32(dstaddr, data[0]); dstaddr += 4;
+ ARM9Write32(dstaddr, data[1]); dstaddr += 4;
+ ARM9Write32(dstaddr, data[2]); dstaddr += 4;
+ ARM9Write32(dstaddr, data[3]); dstaddr += 4;
}
*(u32*)&tmp[0] = bootparams[7];
*(u32*)&tmp[4] = -bootparams[7];
*(u32*)&tmp[8] = ~bootparams[7];
*(u32*)&tmp[12] = 0;
- for (int i = 0; i < 16; i++) boot2iv[i] = tmp[15-i];
+ Bswap128(boot2iv, tmp);
AES_init_ctx_iv(&ctx, boot2key, boot2iv);
@@ -926,17 +926,17 @@ bool LoadNAND()
dstaddr = bootparams[6];
for (u32 i = 0; i < bootparams[7]; i += 16)
{
- u8 data[16];
+ u32 data[4];
FileRead(data, 16, 1, nand);
- for (int j = 0; j < 16; j++) tmp[j] = data[15-j];
+ Bswap128(tmp, data);
AES_CTR_xcrypt_buffer(&ctx, tmp, 16);
- for (int j = 0; j < 16; j++) data[j] = tmp[15-j];
+ Bswap128(data, tmp);
- ARM7Write32(dstaddr, *(u32*)&data[0]); dstaddr += 4;
- ARM7Write32(dstaddr, *(u32*)&data[4]); dstaddr += 4;
- ARM7Write32(dstaddr, *(u32*)&data[8]); dstaddr += 4;
- ARM7Write32(dstaddr, *(u32*)&data[12]); dstaddr += 4;
+ ARM7Write32(dstaddr, data[0]); dstaddr += 4;
+ ARM7Write32(dstaddr, data[1]); dstaddr += 4;
+ ARM7Write32(dstaddr, data[2]); dstaddr += 4;
+ ARM7Write32(dstaddr, data[3]); dstaddr += 4;
}
}