mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-01 16:05:07 +01:00
Adressed review comments
This commit is contained in:
parent
ebeea43fb8
commit
eaaa76b922
@ -242,14 +242,11 @@ void LoadNativeFirmKeysOld3DS() {
|
||||
auto asn1 = RSA::CreateASN1Message(secret_data);
|
||||
auto result = rsa.GetSignature(asn1);
|
||||
if (result.size() < 0x100) {
|
||||
std::vector<u8> temp;
|
||||
temp.resize(0x100 - result.size());
|
||||
std::fill(temp.begin(), temp.end(), 0);
|
||||
std::copy(result.begin(), result.end(), std::back_inserter(temp));
|
||||
std::vector<u8> temp(0x100);
|
||||
std::copy(result.begin(), result.end(), temp.end() - result.size());
|
||||
result = temp;
|
||||
} else if (result.size() > 0x100) {
|
||||
std::vector<u8> temp(result.begin(), result.begin() + 0x100);
|
||||
result = temp;
|
||||
result.resize(0x100);
|
||||
}
|
||||
|
||||
CryptoPP::SHA256 sha;
|
||||
@ -262,13 +259,13 @@ void LoadNativeFirmKeysOld3DS() {
|
||||
key_slots.at(0x25).SetKeyX(key);
|
||||
}
|
||||
|
||||
void LoadSaveModeNativeFirmKeysOld3DS() {
|
||||
// Use the save mode native firm instead of the normal mode since there are only 2 version of it
|
||||
void LoadSafeModeNativeFirmKeysOld3DS() {
|
||||
// Use the safe mode native firm instead of the normal mode since there are only 2 version of it
|
||||
// and thus we can use fixed offsets
|
||||
|
||||
constexpr u64 save_mode_native_firm_id = 0x00040138'00000003;
|
||||
constexpr u64 safe_mode_native_firm_id = 0x00040138'00000003;
|
||||
|
||||
FileSys::NCCHArchive archive(save_mode_native_firm_id, Service::FS::MediaType::NAND);
|
||||
FileSys::NCCHArchive archive(safe_mode_native_firm_id, Service::FS::MediaType::NAND);
|
||||
std::array<char, 8> exefs_filepath = {'.', 'f', 'i', 'r', 'm', 0, 0, 0};
|
||||
FileSys::Path file_path = FileSys::MakeNCCHFilePath(
|
||||
FileSys::NCCHFileOpenType::NCCHData, 0, FileSys::NCCHFilePathType::ExeFS, exefs_filepath);
|
||||
@ -281,7 +278,7 @@ void LoadSaveModeNativeFirmKeysOld3DS() {
|
||||
auto firm = std::move(file_result).Unwrap();
|
||||
const std::size_t size = firm->GetSize();
|
||||
if (size != 843776) {
|
||||
LOG_ERROR(HW_AES, "save mode native firm has wrong size {}", size);
|
||||
LOG_ERROR(HW_AES, "safe mode native firm has wrong size {}", size);
|
||||
return;
|
||||
}
|
||||
std::vector<u8> firm_buffer(size);
|
||||
@ -323,16 +320,16 @@ void LoadNativeFirmKeysNew3DS() {
|
||||
AESKey secret_key;
|
||||
secret.ReadArray(secret_key.data(), secret_key.size());
|
||||
|
||||
// Use the save mode native firm instead of the normal mode since there are only 1 version of it
|
||||
// Use the safe mode native firm instead of the normal mode since there are only 1 version of it
|
||||
// and thus we can use fixed offsets
|
||||
constexpr u64 save_mode_native_firm_id = 0x00040138'20000003;
|
||||
constexpr u64 safe_mode_native_firm_id = 0x00040138'20000003;
|
||||
|
||||
// TODO(B3N30): Add the 0x25 KeyX that gets initalized by native_firm
|
||||
|
||||
// TODO(B3N30): Add the 0x18 - 0x1F KeyX that gets initalized by native_firm. This probably
|
||||
// requires the normal native firm with version > 9.6.0-X
|
||||
|
||||
FileSys::NCCHArchive archive(save_mode_native_firm_id, Service::FS::MediaType::NAND);
|
||||
FileSys::NCCHArchive archive(safe_mode_native_firm_id, Service::FS::MediaType::NAND);
|
||||
std::array<char, 8> exefs_filepath = {'.', 'f', 'i', 'r', 'm', 0, 0, 0};
|
||||
FileSys::Path file_path = FileSys::MakeNCCHFilePath(
|
||||
FileSys::NCCHFileOpenType::NCCHData, 0, FileSys::NCCHFilePathType::ExeFS, exefs_filepath);
|
||||
@ -354,7 +351,7 @@ void LoadNativeFirmKeysNew3DS() {
|
||||
return a | b << 8 | c << 16 | d << 24;
|
||||
};
|
||||
if (MakeMagic('F', 'I', 'R', 'M') != header.magic) {
|
||||
LOG_ERROR(HW_AES, "N3DS SAVE MODE Native Firm has wrong header {}", header.magic);
|
||||
LOG_ERROR(HW_AES, "N3DS SAFE MODE Native Firm has wrong header {}", header.magic);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -505,7 +502,7 @@ void InitKeys() {
|
||||
HW::RSA::InitSlots();
|
||||
LoadBootromKeys();
|
||||
LoadNativeFirmKeysOld3DS();
|
||||
LoadSaveModeNativeFirmKeysOld3DS();
|
||||
LoadSafeModeNativeFirmKeysOld3DS();
|
||||
LoadNativeFirmKeysNew3DS();
|
||||
LoadPresetKeys();
|
||||
}
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include "common/common_paths.h"
|
||||
#include "common/file_util.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "common/string_util.h"
|
||||
#include "core/hw/rsa/rsa.h"
|
||||
|
||||
namespace HW::RSA {
|
||||
@ -21,7 +20,7 @@ std::vector<u8> HexToBytes(const std::string& hex) {
|
||||
|
||||
for (unsigned int i = 0; i < hex.length(); i += 2) {
|
||||
std::string byteString = hex.substr(i, 2);
|
||||
u8 byte = (u8)strtol(byteString.c_str(), NULL, 16);
|
||||
u8 byte = static_cast<u8>(std::strtol(byteString.c_str(), nullptr, 16));
|
||||
bytes.push_back(byte);
|
||||
}
|
||||
return bytes;
|
||||
@ -48,7 +47,7 @@ void InitSlots() {
|
||||
initialized = true;
|
||||
|
||||
const std::string filepath = FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir) + BOOTROM9;
|
||||
auto file = FileUtil::IOFile(filepath, "rb");
|
||||
FileUtil::IOFile file(filepath, "rb");
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
@ -61,14 +60,12 @@ void InitSlots() {
|
||||
|
||||
constexpr std::size_t RSA_MODULUS_POS = 0xB3E0;
|
||||
file.Seek(RSA_MODULUS_POS, SEEK_SET);
|
||||
std::vector<u8> modulus;
|
||||
modulus.resize(256);
|
||||
std::vector<u8> modulus(256);
|
||||
file.ReadArray(modulus.data(), modulus.size());
|
||||
|
||||
constexpr std::size_t RSA_EXPONENT_POS = 0xB4E0;
|
||||
file.Seek(RSA_EXPONENT_POS, SEEK_SET);
|
||||
std::vector<u8> exponent;
|
||||
exponent.resize(256);
|
||||
std::vector<u8> exponent(256);
|
||||
file.ReadArray(exponent.data(), exponent.size());
|
||||
|
||||
rsa_slots[0] = RsaSlot(exponent, modulus);
|
||||
|
Loading…
Reference in New Issue
Block a user