diff options
author | Zach Hilman <zachhilman@gmail.com> | 2019-05-26 19:01:42 +0200 |
---|---|---|
committer | Zach Hilman <zachhilman@gmail.com> | 2019-07-08 03:38:33 +0200 |
commit | 50d541407507edc2f29ad6a46f3f17724e52f7f7 (patch) | |
tree | 2a63feb14069c769a85a512a42d1447c05634027 /src/core/crypto/key_manager.h | |
parent | es: Populate/synthesize tickets on construction (diff) | |
download | yuzu-50d541407507edc2f29ad6a46f3f17724e52f7f7.tar yuzu-50d541407507edc2f29ad6a46f3f17724e52f7f7.tar.gz yuzu-50d541407507edc2f29ad6a46f3f17724e52f7f7.tar.bz2 yuzu-50d541407507edc2f29ad6a46f3f17724e52f7f7.tar.lz yuzu-50d541407507edc2f29ad6a46f3f17724e52f7f7.tar.xz yuzu-50d541407507edc2f29ad6a46f3f17724e52f7f7.tar.zst yuzu-50d541407507edc2f29ad6a46f3f17724e52f7f7.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/crypto/key_manager.h | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/src/core/crypto/key_manager.h b/src/core/crypto/key_manager.h index d4e89d35c..7265c4171 100644 --- a/src/core/crypto/key_manager.h +++ b/src/core/crypto/key_manager.h @@ -9,6 +9,7 @@ #include <optional> #include <string> +#include <variant> #include <boost/container/flat_map.hpp> #include <fmt/format.h> #include "common/common_funcs.h" @@ -73,33 +74,36 @@ struct TicketData { }; static_assert(sizeof(TicketData) == 0x2C0, "TicketData has incorrect size."); -struct Ticket { +struct RSA4096Ticket { SignatureType sig_type; - union { - struct { - std::array<u8, 0x200> sig_data; - INSERT_PADDING_BYTES(0x3C); - TicketData data; - } rsa_4096; + std::array<u8, 0x200> sig_data; + INSERT_PADDING_BYTES(0x3C); + TicketData data; +}; - struct { - std::array<u8, 0x100> sig_data; - INSERT_PADDING_BYTES(0x3C); - TicketData data; - } rsa_2048; +struct RSA2048Ticket { + SignatureType sig_type; + std::array<u8, 0x100> sig_data; + INSERT_PADDING_BYTES(0x3C); + TicketData data; +}; - struct { - std::array<u8, 0x3C> sig_data; - INSERT_PADDING_BYTES(0x40); - TicketData data; - } ecdsa; - }; +struct ECDSATicket { + SignatureType sig_type; + std::array<u8, 0x3C> sig_data; + INSERT_PADDING_BYTES(0x40); + TicketData data; +}; + +struct Ticket { + std::variant<RSA4096Ticket, RSA2048Ticket, ECDSATicket> data; + SignatureType GetSignatureType() const; TicketData& GetData(); const TicketData& GetData() const; u64 GetSize() const; - static Ticket SynthesizeCommon(Key128 title_key, std::array<u8, 0x10> rights_id); + static Ticket SynthesizeCommon(Key128 title_key, const std::array<u8, 0x10>& rights_id); }; static_assert(sizeof(Key128) == 16, "Key128 must be 128 bytes big."); @@ -120,6 +124,12 @@ bool operator==(const RSAKeyPair<bit_size, byte_size>& lhs, std::tie(rhs.encryption_key, rhs.decryption_key, rhs.modulus, rhs.exponent); } +template <size_t bit_size, size_t byte_size> +bool operator!=(const RSAKeyPair<bit_size, byte_size>& lhs, + const RSAKeyPair<bit_size, byte_size>& rhs) { + return !(lhs == rhs); +} + enum class KeyCategory : u8 { Standard, Title, @@ -268,7 +278,7 @@ private: void DeriveGeneralPurposeKeys(std::size_t crypto_revision); - RSAKeyPair<2048> GetETicketRSAKey(); + RSAKeyPair<2048> GetETicketRSAKey() const; void SetKeyWrapped(S128KeyType id, Key128 key, u64 field1 = 0, u64 field2 = 0); void SetKeyWrapped(S256KeyType id, Key256 key, u64 field1 = 0, u64 field2 = 0); |