Skip to content

Commit

Permalink
IOSC: Change misc_data to a u32
Browse files Browse the repository at this point in the history
It's always 4 bytes long, so let's just make it a u32.
  • Loading branch information
leoetlino committed Feb 19, 2018
1 parent 6a609e6 commit 1f4ddea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
13 changes: 6 additions & 7 deletions Source/Core/Core/IOS/IOSC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ ReturnCode IOSC::ImportPublicKey(Handle dest_handle, const u8* public_key,
if (dest_entry->subtype == SUBTYPE_RSA2048 || dest_entry->subtype == SUBTYPE_RSA4096)
{
_assert_(public_key_exponent);
std::copy_n(public_key_exponent, 4, dest_entry->misc_data.begin());
std::memcpy(&dest_entry->misc_data, public_key_exponent, 4);
}
return IPC_SUCCESS;
}
Expand Down Expand Up @@ -232,7 +232,7 @@ ReturnCode IOSC::VerifyPublicKeySign(const std::array<u8, 20>& sha1, Handle sign
Common::ScopeGuard context_guard{[&rsa] { mbedtls_rsa_free(&rsa); }};

mbedtls_mpi_read_binary(&rsa.N, entry->data.data(), entry->data.size());
mbedtls_mpi_read_binary(&rsa.E, entry->misc_data.data(), entry->misc_data.size());
mbedtls_mpi_read_binary(&rsa.E, reinterpret_cast<const u8*>(&entry->misc_data), 4);
rsa.len = entry->data.size();

const int ret = mbedtls_rsa_pkcs1_verify(&rsa, nullptr, nullptr, MBEDTLS_RSA_PUBLIC,
Expand Down Expand Up @@ -452,18 +452,17 @@ void IOSC::LoadDefaultEntries(ConsoleType console_type)
0xf2, 0xfe, 0xfb, 0xba, 0x4c, 0x9b, 0x7e}},
3};

std::array<u8, 4> root_exponent = {{0x0, 0x1, 0x0, 0x1}};
m_root_key_entry = {TYPE_PUBLIC_KEY, SUBTYPE_RSA4096,
std::vector<u8>(ROOT_PUBLIC_KEY.begin(), ROOT_PUBLIC_KEY.end()),
std::move(root_exponent), 0};
Common::swap32(0x00010001), 0};
}

IOSC::KeyEntry::KeyEntry() = default;

IOSC::KeyEntry::KeyEntry(ObjectType type_, ObjectSubType subtype_, std::vector<u8>&& data_,
std::array<u8, 4>&& misc_data_, u32 owner_mask_)
: in_use(true), type(type_), subtype(subtype_), data(std::move(data_)),
misc_data(std::move(misc_data_)), owner_mask(owner_mask_)
u32 misc_data_, u32 owner_mask_)
: in_use(true), type(type_), subtype(subtype_), data(std::move(data_)), misc_data(misc_data_),
owner_mask(owner_mask_)
{
}

Expand Down
6 changes: 3 additions & 3 deletions Source/Core/Core/IOS/IOSC.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,15 @@ class IOSC final
{
KeyEntry();
KeyEntry(ObjectType type_, ObjectSubType subtype_, std::vector<u8>&& data_, u32 owner_mask_);
KeyEntry(ObjectType type_, ObjectSubType subtype_, std::vector<u8>&& data_,
std::array<u8, 4>&& misc_data_, u32 owner_mask_);
KeyEntry(ObjectType type_, ObjectSubType subtype_, std::vector<u8>&& data_, u32 misc_data_,
u32 owner_mask_);
void DoState(PointerWrap& p);

bool in_use = false;
ObjectType type;
ObjectSubType subtype;
std::vector<u8> data;
std::array<u8, 4> misc_data{};
u32 misc_data = 0;
u32 owner_mask = 0;
};
// The Wii's IOSC is limited to 32 entries, including 12 built-in entries.
Expand Down

2 comments on commit 1f4ddea

@shuffle2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've noticed KeyEntry::misc_data is not handled by KeyEntry::DoState (but all other members are), is that a bug?

@leoetlino
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that does look like an oversight, good catch!

Please sign in to comment.