From d7398283e3cab47bac3571c0a56903415ffa44e6 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Sun, 23 Sep 2018 20:57:20 -0400 Subject: key_manager: Add BIS key getter --- src/core/crypto/key_manager.cpp | 19 +++++++++++++++++-- src/core/crypto/key_manager.h | 2 ++ 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp index 2a0b0b574..9cb7124d2 100644 --- a/src/core/crypto/key_manager.cpp +++ b/src/core/crypto/key_manager.cpp @@ -282,8 +282,23 @@ Key256 KeyManager::GetKey(S256KeyType id, u64 field1, u64 field2) const { return s256_keys.at({id, field1, field2}); } -template -void KeyManager::WriteKeyToFile(bool title_key, std::string_view keyname, +Key256 KeyManager::GetBISKey(u8 partition_id) const { + Key256 out{}; + + for (const auto& bis_type : {BISKeyType::Crypto, BISKeyType::Tweak}) { + if (HasKey(S128KeyType::BIS, partition_id, static_cast(bis_type))) { + std::memcpy( + out.data() + sizeof(Key128) * static_cast(bis_type), + s128_keys.at({S128KeyType::BIS, partition_id, static_cast(bis_type)}).data(), + sizeof(Key128)); + } + } + + return out; +} + +template +void KeyManager::WriteKeyToFile(KeyCategory category, std::string_view keyname, const std::array& key) { const std::string yuzu_keys_dir = FileUtil::GetUserPath(FileUtil::UserPath::KeysDir); std::string filename = "title.keys_autogenerated"; diff --git a/src/core/crypto/key_manager.h b/src/core/crypto/key_manager.h index 1cb62c2dc..a729fa7a0 100644 --- a/src/core/crypto/key_manager.h +++ b/src/core/crypto/key_manager.h @@ -127,6 +127,8 @@ public: Key128 GetKey(S128KeyType id, u64 field1 = 0, u64 field2 = 0) const; Key256 GetKey(S256KeyType id, u64 field1 = 0, u64 field2 = 0) const; + Key256 GetBISKey(u8 partition_id) const; + void SetKey(S128KeyType id, Key128 key, u64 field1 = 0, u64 field2 = 0); void SetKey(S256KeyType id, Key256 key, u64 field1 = 0, u64 field2 = 0); -- cgit v1.2.3