Hm, if the task is to identify a set of fixed headers at a variety of file offsets, what you really want is a rolling hash (https://en.wikipedia.org/wiki/Rolling_hash). Select a rolling hash of size N, no bigger than the smallest fixed header. At each step, update the rolling hash with the next byte seen. If it matches one of the known header hashes, branch to code to check if it actually is. Otherwise, continue to the next byte. As long as the rolling hash function isn't too low quality, and you can check if a hatch matches a known header, you can find all the headers in the block in O(F) time for an F-byte file, rather than O(F*P) time for an F-byte file and P patterns. That is, on average you inspect every byte of the file way fewer times with a rolling hash.