1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-18 16:32:05 +00:00

exo2: correct pkg2 encryption key load

This commit is contained in:
Michael Scire 2020-06-12 12:09:49 -07:00 committed by SciresM
parent c129256dd0
commit b966345b25

View file

@ -37,6 +37,25 @@ namespace ams::secmon::boot {
return VerifySignature(header.signature, sizeof(header.signature), mod, mod_size, std::addressof(header.meta), sizeof(header.meta));
}
int PrepareMasterKey(int key_generation) {
if (key_generation == GetKeyGeneration()) {
return pkg1::AesKeySlot_Master;
}
constexpr int Slot = pkg1::AesKeySlot_Temporary;
LoadMasterKey(Slot, key_generation);
return Slot;
}
void PreparePackage2Key(int pkg2_slot, int key_generation, const void *key, size_t key_size) {
/* Get keyslot for the desired master key. */
const int master_slot = PrepareMasterKey(key_generation);
/* Load the package2 key into the desired keyslot. */
se::SetEncryptedAesKey128(pkg2_slot, master_slot, key, key_size);
}
void DecryptPackage2(void *dst, size_t dst_size, const void *src, size_t src_size, const void *key, size_t key_size, const void *iv, size_t iv_size, u8 key_generation) {
/* Ensure that the SE sees consistent data. */
hw::FlushDataCache(key, key_size);
@ -44,14 +63,11 @@ namespace ams::secmon::boot {
hw::FlushDataCache(dst, dst_size);
hw::DataSynchronizationBarrierInnerShareable();
/* Load the needed master key into the temporary keyslot. */
secmon::LoadMasterKey(pkg1::AesKeySlot_Temporary, key_generation);
/* Load the package2 key into the temporary keyslot. */
se::SetEncryptedAesKey128(pkg1::AesKeySlot_Temporary, pkg1::AesKeySlot_Temporary, key, key_size);
PreparePackage2Key(pkg1::AesKeySlot_Temporary, key_generation, key, key_size);
/* Decrypt the data. */
se::ComputeAes128Ctr(dst, dst_size, pkg1::AesKeySlot_Temporary, src, src_size, iv, iv_size);
se::ComputeAes128Ctr(dst, dst_size, pkg1::AesKeySlot_Temporary, src, src_size, iv, iv_size);
/* Clear the keyslot we just used. */
se::ClearAesKeySlot(pkg1::AesKeySlot_Temporary);