mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 21:52:48 +00:00
Virtual memory: otp_dec.bin support without boot9.bin
This commit is contained in:
parent
0fd5261516
commit
e245c576cc
@ -71,8 +71,7 @@ bool GetOtp0x90(void* otp0x90, u32 len)
|
|||||||
if (len > 0x90) len = 0x90;
|
if (len > 0x90) len = 0x90;
|
||||||
memcpy(otp0x90, (u8*) 0x01FFB800, len);
|
memcpy(otp0x90, (u8*) 0x01FFB800, len);
|
||||||
if ((LoadKeyFromFile(otp_key, 0x11, 'N', "OTP") == 0) &&
|
if ((LoadKeyFromFile(otp_key, 0x11, 'N', "OTP") == 0) &&
|
||||||
((LoadKeyFromFile(otp_iv, 0x11, 'I', "IVOTP") == 0) ||
|
(LoadKeyFromFile(otp_iv, 0x11, 'I', "OTP") == 0)) {
|
||||||
(LoadKeyFromFile(otp_iv, 0x11, 'I', "OTP") == 0))) {
|
|
||||||
setup_aeskey(0x11, otp_key);
|
setup_aeskey(0x11, otp_key);
|
||||||
use_aeskey(0x11);
|
use_aeskey(0x11);
|
||||||
cbc_encrypt(otp0x90, otp0x90, len / 0x10, AES_CNT_TITLEKEY_ENCRYPT_MODE, otp_iv);
|
cbc_encrypt(otp0x90, otp0x90, len / 0x10, AES_CNT_TITLEKEY_ENCRYPT_MODE, otp_iv);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "unittype.h"
|
#include "unittype.h"
|
||||||
#include "sha.h"
|
#include "sha.h"
|
||||||
#include "aes.h"
|
#include "aes.h"
|
||||||
|
#include "keydb.h"
|
||||||
#include "sdmmc.h"
|
#include "sdmmc.h"
|
||||||
#include "itcm.h"
|
#include "itcm.h"
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
@ -78,7 +79,7 @@ static const VirtualFile vMemFileTemplates[] = {
|
|||||||
|
|
||||||
// Custom callback implementations.
|
// Custom callback implementations.
|
||||||
// Keyslot field has arbitrary meaning, and may not actually be a keyslot.
|
// Keyslot field has arbitrary meaning, and may not actually be a keyslot.
|
||||||
{ "otp_dec.mem" , VMEM_CALLBACK_OTP_DECRYPTED, OTP_LEN , 0x11, VFLAG_CALLBACK | VFLAG_READONLY | VFLAG_OTP | VFLAG_BOOT9 },
|
{ "otp_dec.mem" , VMEM_CALLBACK_OTP_DECRYPTED, OTP_LEN , 0x11, VFLAG_CALLBACK | VFLAG_READONLY | VFLAG_OTP },
|
||||||
{ "mcu_3ds_regs.mem" , VMEM_CALLBACK_MCU_REGISTERS, 0x00000100, I2C_DEV_MCU, VFLAG_CALLBACK | VFLAG_READONLY },
|
{ "mcu_3ds_regs.mem" , VMEM_CALLBACK_MCU_REGISTERS, 0x00000100, I2C_DEV_MCU, VFLAG_CALLBACK | VFLAG_READONLY },
|
||||||
{ "mcu_dsi_regs.mem" , VMEM_CALLBACK_MCU_REGISTERS, 0x00000100, I2C_DEV_POWER, VFLAG_CALLBACK | VFLAG_READONLY },
|
{ "mcu_dsi_regs.mem" , VMEM_CALLBACK_MCU_REGISTERS, 0x00000100, I2C_DEV_POWER, VFLAG_CALLBACK | VFLAG_READONLY },
|
||||||
{ "sd_cid.mem" , VMEM_CALLBACK_FLASH_CID , 0x00000010, 0x01, VFLAG_CALLBACK | VFLAG_READONLY },
|
{ "sd_cid.mem" , VMEM_CALLBACK_FLASH_CID , 0x00000010, 0x01, VFLAG_CALLBACK | VFLAG_READONLY },
|
||||||
@ -113,9 +114,19 @@ int ReadVMemOTPDecrypted(const VirtualFile* vfile, void* buffer, u64 offset, u64
|
|||||||
|
|
||||||
alignas(32) u8 otp_local[OTP_LEN];
|
alignas(32) u8 otp_local[OTP_LEN];
|
||||||
alignas(32) u8 otp_iv[0x10];
|
alignas(32) u8 otp_iv[0x10];
|
||||||
|
alignas(32) u8 otp_key[0x10];
|
||||||
u8* otp_mem = (u8*) OTP_POS;
|
u8* otp_mem = (u8*) OTP_POS;
|
||||||
memcpy(otp_iv, OTP_IV, 0x10);
|
|
||||||
setup_aeskey(0x11, OTP_KEY);
|
if (HAS_BOOT9) { // easy setup when boot9 available
|
||||||
|
memcpy(otp_iv, OTP_IV, 0x10);
|
||||||
|
memcpy(otp_key, OTP_KEY, 0x10);
|
||||||
|
} else { // a little bit more complicated without
|
||||||
|
if ((LoadKeyFromFile(otp_key, 0x11, 'N', "OTP") != 0) ||
|
||||||
|
(LoadKeyFromFile(otp_iv , 0x11, 'I', "OTP") != 0))
|
||||||
|
return 1; // crypto not available
|
||||||
|
}
|
||||||
|
|
||||||
|
setup_aeskey(0x11, otp_key);
|
||||||
use_aeskey(0x11);
|
use_aeskey(0x11);
|
||||||
cbc_decrypt(otp_mem, otp_local, OTP_LEN / 0x10, AES_CNT_TITLEKEY_DECRYPT_MODE, otp_iv);
|
cbc_decrypt(otp_mem, otp_local, OTP_LEN / 0x10, AES_CNT_TITLEKEY_DECRYPT_MODE, otp_iv);
|
||||||
memcpy(buffer, otp_local + offset, count);
|
memcpy(buffer, otp_local + offset, count);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user