chenxiaolong / avbroot

Sign (and root) Android A/B OTAs with custom keys while preserving Android Verified Boot
GNU General Public License v3.0
436 stars 41 forks source link

hashtree: Precompute salted SHA-256 context #257

Closed chenxiaolong closed 5 months ago

chenxiaolong commented 5 months ago

With the dm-verity hash tree format, each digest is salted, meaning it first hashes the salt byte string and then the actual data. Previously, the salt was being rehashed for each digest operation. Instead, the salted SHA-256 context can be computed once and then cloned when needed.

The performance improvement is pretty minor, but it's worth doing anyway since it's not any more complex.