Improve slightly FSB key testing performance

This commit is contained in:
bnnm 2024-04-08 22:42:54 +02:00
parent 673ce6362a
commit cd468a9b1f
2 changed files with 21 additions and 3 deletions

View File

@ -65,8 +65,7 @@ static VGMSTREAM* test_fsbkey(STREAMFILE* sf, const uint8_t* key, size_t key_siz
int test_std = flags & FLAG_STD;
int test_alt = flags & FLAG_ALT;
if (!vc && test_std) {
if (!vc && test_std && test_fsb_streamfile(sf, key, key_size, 0)) {
temp_sf = setup_fsb_streamfile(sf, key, key_size, 0);
if (!temp_sf) return NULL;
//;dump_streamfile(temp_sf, 0);
@ -77,7 +76,7 @@ static VGMSTREAM* test_fsbkey(STREAMFILE* sf, const uint8_t* key, size_t key_siz
close_streamfile(temp_sf);
}
if (!vc && test_alt) {
if (!vc && test_alt && test_fsb_streamfile(sf, key, key_size, 1)) {
temp_sf = setup_fsb_streamfile(sf, key, key_size, 1);
if (!temp_sf) return NULL;
//;dump_streamfile(temp_sf, 1);

View File

@ -71,4 +71,23 @@ static STREAMFILE* setup_fsb_streamfile(STREAMFILE* sf, const uint8_t* key, size
return new_sf;
}
/* same as above but doesn't open streamfile, so it's a tiny bit faster */
static bool test_fsb_streamfile(STREAMFILE* sf, const uint8_t* key, size_t key_size, int is_alt) {
fsb_decryption_data io_data = {0};
if (!key_size || key_size >= FSB_KEY_MAX)
return false;
memcpy(io_data.key, key, key_size);
io_data.key_size = key_size;
io_data.is_alt = is_alt;
/* setup subfile */
uint8_t tmp[0x04];
int bytes = fsb_decryption_read(sf, tmp, 0x00, 0x04, &io_data);
if (bytes != 0x04)
return false;
return (get_u32be(tmp) & 0xFFFFFF00) == get_id32be("FSB\0");
}
#endif /* _FSB_ENCRYPTED_STREAMFILE_H_ */