add GCI decryption function

This commit is contained in:
Martin Michelsen
2022-09-10 01:29:35 -07:00
parent 42d12e2a18
commit 1a3dd26cb3
9 changed files with 855 additions and 81 deletions
+40
View File
@@ -105,6 +105,25 @@ void PSOV2Encryption::encrypt_big_endian(void* vdata, size_t size, bool advance)
this->encrypt_t<be_uint32_t>(vdata, size, advance);
}
void PSOV2Encryption::encrypt_both_endian(
void* le_vdata, void* be_vdata, size_t size, bool advance) {
if (size & 3) {
throw invalid_argument("size must be a multiple of 4");
}
if (!advance && (size != 4)) {
throw logic_error("cannot peek-encrypt/decrypt with size > 4");
}
size >>= 2;
le_uint32_t* le_data = reinterpret_cast<le_uint32_t*>(le_vdata);
be_uint32_t* be_data = reinterpret_cast<be_uint32_t*>(be_vdata);
for (size_t x = 0; x < size; x++) {
uint32_t key = this->next(advance);
le_data[x] ^= key;
be_data[x] ^= key;
}
}
PSOEncryption::Type PSOV2Encryption::type() const {
return Type::V2;
}
@@ -195,6 +214,27 @@ void PSOV3Encryption::encrypt_big_endian(void* vdata, size_t size, bool advance)
this->encrypt_t<be_uint32_t>(vdata, size, advance);
}
// TODO: PSOV2Encryption an PSOV3Encryption should have a base class in common
// that implements this function, because it's identical in both classes
void PSOV3Encryption::encrypt_both_endian(
void* le_vdata, void* be_vdata, size_t size, bool advance) {
if (size & 3) {
throw invalid_argument("size must be a multiple of 4");
}
if (!advance && (size != 4)) {
throw logic_error("cannot peek-encrypt/decrypt with size > 4");
}
size >>= 2;
le_uint32_t* le_data = reinterpret_cast<le_uint32_t*>(le_vdata);
be_uint32_t* be_data = reinterpret_cast<be_uint32_t*>(be_vdata);
for (size_t x = 0; x < size; x++) {
uint32_t key = this->next(advance);
le_data[x] ^= key;
be_data[x] ^= key;
}
}
PSOEncryption::Type PSOV3Encryption::type() const {
return Type::V3;
}