summaryrefslogtreecommitdiff
path: root/src/core/crypto/key_manager.h
diff options
context:
space:
mode:
authorGravatar Zach Hilman2018-09-23 21:04:13 -0400
committerGravatar Zach Hilman2018-10-07 13:15:11 -0400
commitd041d6231c97ea0c8af788da251ae019ee560e6a (patch)
tree1d779bb315a626d7c4e5805c466313a9f1e18980 /src/core/crypto/key_manager.h
parentkey_manager: Add base key derivation (diff)
downloadyuzu-d041d6231c97ea0c8af788da251ae019ee560e6a.tar.gz
yuzu-d041d6231c97ea0c8af788da251ae019ee560e6a.tar.xz
yuzu-d041d6231c97ea0c8af788da251ae019ee560e6a.zip
key_manager: Add ETicket key derivation
Derives titlekeys
Diffstat (limited to 'src/core/crypto/key_manager.h')
-rw-r--r--src/core/crypto/key_manager.h29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/core/crypto/key_manager.h b/src/core/crypto/key_manager.h
index 8de65ec4e..58afcdcac 100644
--- a/src/core/crypto/key_manager.h
+++ b/src/core/crypto/key_manager.h
@@ -5,11 +5,18 @@
5#pragma once 5#pragma once
6 6
7#include <array> 7#include <array>
8#include <map>
8#include <string> 9#include <string>
9#include <boost/container/flat_map.hpp> 10#include <boost/container/flat_map.hpp>
10#include <boost/optional.hpp> 11#include <boost/optional.hpp>
11#include <fmt/format.h> 12#include <fmt/format.h>
12#include "common/common_types.h" 13#include "common/common_types.h"
14#include "core/file_sys/vfs_types.h"
15#include "partition_data_manager.h"
16
17namespace FileUtil {
18class IOFile;
19}
13 20
14namespace Loader { 21namespace Loader {
15enum class ResultStatus : u16; 22enum class ResultStatus : u16;
@@ -22,9 +29,18 @@ constexpr u64 TICKET_FILE_TITLEKEY_OFFSET = 0x180;
22using Key128 = std::array<u8, 0x10>; 29using Key128 = std::array<u8, 0x10>;
23using Key256 = std::array<u8, 0x20>; 30using Key256 = std::array<u8, 0x20>;
24using SHA256Hash = std::array<u8, 0x20>; 31using SHA256Hash = std::array<u8, 0x20>;
32using TicketRaw = std::array<u8, 0x400>;
25 33
26static_assert(sizeof(Key128) == 16, "Key128 must be 128 bytes big."); 34static_assert(sizeof(Key128) == 16, "Key128 must be 128 bytes big.");
27static_assert(sizeof(Key256) == 32, "Key128 must be 128 bytes big."); 35static_assert(sizeof(Key256) == 32, "Key256 must be 256 bytes big.");
36
37template <size_t bit_size, size_t byte_size = (bit_size >> 3)>
38struct RSAKeyPair {
39 std::array<u8, byte_size> encryption_key;
40 std::array<u8, byte_size> decryption_key;
41 std::array<u8, byte_size> modulus;
42 std::array<u8, 4> exponent;
43};
28 44
29enum class KeyCategory : u8 { 45enum class KeyCategory : u8 {
30 Standard, 46 Standard,
@@ -140,6 +156,8 @@ public:
140 156
141 bool BaseDeriveNecessary(); 157 bool BaseDeriveNecessary();
142 void DeriveBase(); 158 void DeriveBase();
159 void DeriveETicket(PartitionDataManager data);
160
143private: 161private:
144 std::map<KeyIndex<S128KeyType>, Key128> s128_keys; 162 std::map<KeyIndex<S128KeyType>, Key128> s128_keys;
145 std::map<KeyIndex<S256KeyType>, Key256> s256_keys; 163 std::map<KeyIndex<S256KeyType>, Key256> s256_keys;
@@ -166,6 +184,13 @@ Key128 GenerateKeyEncryptionKey(Key128 source, Key128 master, Key128 kek_seed, K
166Key128 DeriveKeyblobKey(Key128 sbk, Key128 tsec, Key128 source); 184Key128 DeriveKeyblobKey(Key128 sbk, Key128 tsec, Key128 source);
167 185
168boost::optional<Key128> DeriveSDSeed(); 186boost::optional<Key128> DeriveSDSeed();
169Loader::ResultStatus DeriveSDKeys(std::array<Key256, 2>& sd_keys, const KeyManager& keys); 187Loader::ResultStatus DeriveSDKeys(std::array<Key256, 2>& sd_keys, KeyManager& keys);
188
189std::vector<TicketRaw> GetTicketblob(const FileUtil::IOFile& ticket_save);
190
191// Returns a pair of {rights_id, titlekey}. Fails if the ticket has no certificate authority (offset
192// 0x140-0x144 is zero)
193boost::optional<std::pair<Key128, Key128>> ParseTicket(
194 const TicketRaw& ticket, const RSAKeyPair<2048>& eticket_extended_key);
170 195
171} // namespace Core::Crypto 196} // namespace Core::Crypto