microsoft / security-utilities

Security utilities for key generation, string redaction, etc.
MIT License
24 stars 9 forks source link

Rust/His: Initial work to generalize scan definitions #21

Closed beaubelgrave closed 4 months ago

beaubelgrave commented 4 months ago

Today we have a very fast, but labor intensive, way to add signatures. If we need to add more or have a way to gracefully have some but not others for performance, that is currently very hard to achieve.

Add a generic ScanDefinition struct that can take either a 3 or 4 byte signature along with the character to check for in every 16 bytes. Right now keep the enum and static checking, however, add a closure slot in the definition to indicate the final match behavior in the future.

Each ScanDefinition includes how far back from the siganture and how far forward from the signature to get for a final pass. The underlying structure handles the UTF8 vs UTF16 differences. Callers just need to define UTF8 once, UTF16 LE and BE are auto-calculated.

Currently the performance is around 60-80% slower than hand curated switch/jump tables. However, it is still quite a bit faster than any alternative methods.