Improve speed of finding FS keys

This commit is contained in:
shchmue
2019-01-04 13:40:30 -05:00
parent 49c6fd8dc7
commit 352c39ae8a
6 changed files with 81 additions and 49 deletions

View File

@ -124,7 +124,7 @@ byte_vector Key::cmac(byte_vector data) {
return dest;
}
void Key::find_key(const byte_vector &buffer) {
void Key::find_key(const byte_vector &buffer, size_t start) {
if ((buffer.size() == 0) || (found()))
return;
@ -136,10 +136,11 @@ void Key::find_key(const byte_vector &buffer) {
return;
std::copy(buffer.begin(), buffer.begin() + length, std::back_inserter(key));
is_found = true;
return;
}
// hash every length-sized byte chunk in buffer until it matches member hash
for (size_t i = 0; i < buffer.size() - length; i++) {
for (size_t i = start; i < buffer.size() - length; i++) {
if (xx_hash == XXHash64::hash(buffer.data() + i, length, 0)) {
// double-check sha256 since xxhash64 isn't as collision-safe
Common::sha256(buffer.data() + i, temp_hash, length);