From 1849e8b09c8d3852b8f9de8151b8206ecb64e859 Mon Sep 17 00:00:00 2001 From: B3n30 Date: Wed, 17 Oct 2018 16:07:11 +0200 Subject: [PATCH] HW::AES: add generator_constant --- src/core/hw/aes/key.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/core/hw/aes/key.cpp b/src/core/hw/aes/key.cpp index 99e1b7fb5..b69aad977 100644 --- a/src/core/hw/aes/key.cpp +++ b/src/core/hw/aes/key.cpp @@ -19,7 +19,14 @@ namespace AES { namespace { -std::optional generator_constant; +// The generator constant was calculated using the 0x39 KeyX and KeyY retrieved from a 3DS and the +// normal key dumped from a Wii U solving the equation: +// NormalKey = (((KeyX ROL 2) XOR KeyY) + constant) ROL 87 +// On a real 3DS the generation for the normal key is hardware based, and thus the constant can't +// get dumped . generated normal keys are also not accesible on a 3DS. The used formula for +// calculating the constant is a software implementation of what the hardware generator does. +constexpr AESKey generator_constant = {{0x1F, 0xF9, 0xE9, 0xAA, 0xC5, 0xFE, 0x04, 0x08, 0x02, 0x45, + 0x91, 0xDC, 0x5D, 0x52, 0x76, 0x8A}}; struct KeyDesc { char key_type; @@ -48,8 +55,8 @@ struct KeySlot { } void GenerateNormalKey() { - if (x && y && generator_constant) { - normal = Lrot128(Add128(Xor128(Lrot128(*x, 2), *y), *generator_constant), 87); + if (x && y) { + normal = Lrot128(Add128(Xor128(Lrot128(*x, 2), *y), generator_constant), 87); } else { normal = {}; } @@ -181,11 +188,6 @@ void LoadPresetKeys() { continue; } - if (name == "generator") { - generator_constant = key; - continue; - } - std::size_t common_key_index; if (std::sscanf(name.c_str(), "common%zd", &common_key_index) == 1) { if (common_key_index >= common_key_y_slots.size()) { @@ -236,10 +238,6 @@ void InitKeys() { initialized = true; } -void SetGeneratorConstant(const AESKey& key) { - generator_constant = key; -} - void SetKeyX(std::size_t slot_id, const AESKey& key) { key_slots.at(slot_id).SetKeyX(key); }