NTR_Launcher/BootLoader/source/modcrypt/f_xy.c
ApacheThunder de31f9cb2b 1.3 Refactor
* Added DSOnei kernel to included nds files for Stage2 menu.
* Added N-Card rom dump to included nds files for Stage2 menu.
* Added CycloDS, and DSTWo bootloader dumps to included nds files for
Stage2 menu.
* DSTwo now boots correctly from cart launcher.
* R4 SDHC Gold and other similar DEMON time bomb DSTTi clones now boot
correctly from cart launcher.
* Added back option for enabling/disabling TWL ram.
* Added fixes to allow DS only carts to run with TWL ram enabled.
* Initial modcrypt code added for TWL carts. Currently works in
emulation however TWL carts will fail to boot on hardware (when twl
mode, ram, etc is enabled).
* If TWL mode and ram is enabled, cart loader will now load the DSi
extended binaries into ram. Currently however they will only boot in
emulation. Have not resolved why it's not working on hardware yet.
* Stage2 menu now allowed to load dsi extended binaries of SRLs if TWL
mode and TWL ram is enabled. Booting rom dumps as a method of booting
into TWL carts is confirmed working. At least for System Flaw it does.
:D
* Despite the improvents Acekard 2i still appears to require using the
stage2 menu to boot into.
* Fixes that allowed Demon timebomb carts to boot from cart
launcher/autoboot may allow other non working carts to work. Further
testing needed.
2024-11-27 21:50:32 -06:00

51 lines
1.7 KiB
C

/* f_xy.c
*
* This file was imported from godmode9i, but it is liely not the
* original source. twltool uses the same file.
*
* If you happen to know whom to credit I'd love to add the name
*
* Refactored to reduce the pointer casts and remove the dependency
* from tonccpy.
*/
#include <string.h>
#include <stdint.h>
#include "u128_math.h"
/************************ Constants / Defines *********************************/
const uint8_t DSi_KEY_MAGIC[16] = { 0x79, 0x3e, 0x4f, 0x1a, 0x5f, 0x0f, 0x68, 0x2a,
0x58, 0x02, 0x59, 0x29, 0x4e, 0xfb, 0xfe, 0xff };
const uint8_t DSi_NAND_KEY_Y[16] = { 0x76, 0xdc, 0xb9, 0x0a, 0xd3, 0xc4, 0x4d, 0xbd,
0x1d, 0xdd, 0x2d, 0x20, 0x05, 0x00, 0xa0, 0xe1 };
const uint8_t DSi_ES_KEY_Y[16] = { 0xe5, 0xcc, 0x5a, 0x8b, 0x56, 0xd0, 0xc9,0x72,
0x9c, 0x17, 0xe8, 0xdc, 0x39, 0x12, 0x36, 0xa9 };
const uint8_t DSi_BOOT2_KEY[16] = { 0x98, 0xee, 0x80, 0x80, 0x00, 0x6c, 0xb4, 0xf6,
0x3a, 0xc2, 0x6e, 0x62, 0xf9, 0xec, 0x34, 0xad };
/************************ Functions *******************************************/
void F_XY(uint8_t *key, const uint8_t *key_x, const uint8_t *key_y)
{
uint8_t key_xy[16];
for (int i=0; i<16; i++)
key_xy[i] = key_x[i] ^ key_y[i];
memcpy(key, DSi_KEY_MAGIC, sizeof(DSi_KEY_MAGIC));
u128_add(key, key_xy);
u128_lrot(key, 42);
}
//F_XY_reverse does the reverse of F(X^Y): takes (normal)key, and does F in reverse to generate the original X^Y key_xy.
void F_XY_reverse(const uint8_t *key, uint8_t *key_xy)
{
memcpy(key_xy, key, 16);
u128_rrot(key_xy, 42);
u128_sub(key_xy, DSi_KEY_MAGIC);
}