1 // Copyright 2017 Citra Emulator Project
2 // Licensed under GPLv2 or any later version
3 // Refer to the license.txt file included.
4 
5 #pragma once
6 
7 #include <array>
8 #include <cstddef>
9 #include "common/common_types.h"
10 
11 namespace HW::AES {
12 
13 enum KeySlotID : std::size_t {
14 
15     // Used to decrypt the SSL client cert/private-key stored in ClCertA.
16     SSLKey = 0x0D,
17 
18     // AES keyslots used to decrypt NCCH
19     NCCHSecure1 = 0x2C,
20     NCCHSecure2 = 0x25,
21     NCCHSecure3 = 0x18,
22     NCCHSecure4 = 0x1B,
23 
24     // AES Keyslot used to generate the UDS data frame CCMP key.
25     UDSDataKey = 0x2D,
26 
27     // AES Keyslot used to encrypt the BOSS container data.
28     BOSSDataKey = 0x38,
29 
30     // AES Keyslot used to calculate DLP data frame checksum.
31     DLPDataKey = 0x39,
32 
33     // AES Keyslot used to generate the StreetPass CCMP key.
34     CECDDataKey = 0x2E,
35 
36     // AES Keyslot used by the friends module.
37     FRDKey = 0x36,
38 
39     // AES Keyslot used by the NFC module.
40     NFCKey = 0x39,
41 
42     // AES keyslot used for APT:Wrap/Unwrap functions
43     APTWrap = 0x31,
44 
45     // AES keyslot used for decrypting ticket title key
46     TicketCommonKey = 0x3D,
47 
48     MaxKeySlotID = 0x40,
49 };
50 
51 constexpr std::size_t AES_BLOCK_SIZE = 16;
52 
53 using AESKey = std::array<u8, AES_BLOCK_SIZE>;
54 
55 void InitKeys();
56 
57 void SetGeneratorConstant(const AESKey& key);
58 void SetKeyX(std::size_t slot_id, const AESKey& key);
59 void SetKeyY(std::size_t slot_id, const AESKey& key);
60 void SetNormalKey(std::size_t slot_id, const AESKey& key);
61 
62 bool IsNormalKeyAvailable(std::size_t slot_id);
63 AESKey GetNormalKey(std::size_t slot_id);
64 
65 void SelectCommonKeyIndex(u8 index);
66 
67 } // namespace HW::AES
68