nfc: Use existing secrets infrastructure for amiibo encryption. (#6652)

This commit is contained in:
Steveice10 2023-07-06 11:45:46 -07:00 committed by GitHub
parent 4383f6d80a
commit c00768d6d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 68 additions and 80 deletions

View file

@ -593,8 +593,18 @@ void SelectDlpNfcKeyYIndex(u8 index) {
key_slots[KeySlotID::DLPNFCDataKey].SetKeyY(dlp_nfc_key_y_slots.at(index));
}
const NfcSecret& GetNfcSecret(u8 index) {
return nfc_secrets[index];
bool NfcSecretsAvailable() {
auto missing_secret =
std::find_if(nfc_secrets.begin(), nfc_secrets.end(), [](auto& nfc_secret) {
return nfc_secret.phrase.empty() || nfc_secret.seed.empty() ||
nfc_secret.hmac_key.empty();
});
SelectDlpNfcKeyYIndex(DlpNfcKeyY::Nfc);
return IsNormalKeyAvailable(KeySlotID::DLPNFCDataKey) && missing_secret == nfc_secrets.end();
}
const NfcSecret& GetNfcSecret(NfcSecretId secret_id) {
return nfc_secrets[secret_id];
}
const AESIV& GetNfcIv() {

View file

@ -60,6 +60,11 @@ struct NfcSecret {
std::vector<u8> hmac_key;
};
enum NfcSecretId : std::size_t {
UnfixedInfo = 0,
LockedSecret = 1,
};
constexpr std::size_t MaxCommonKeySlot = 6;
constexpr std::size_t NumDlpNfcKeyYs = 2;
constexpr std::size_t NumNfcSecrets = 2;
@ -83,7 +88,8 @@ AESKey GetNormalKey(std::size_t slot_id);
void SelectCommonKeyIndex(u8 index);
void SelectDlpNfcKeyYIndex(u8 index);
const NfcSecret& GetNfcSecret(u8 index);
bool NfcSecretsAvailable();
const NfcSecret& GetNfcSecret(NfcSecretId secret_id);
const AESIV& GetNfcIv();
} // namespace HW::AES