briansmith / ring

Safe, fast, small crypto using Rust
Other
3.65k stars 684 forks source link

digest internals: Help the compiler understand minimum/maximum output/block sizes. #1995

Closed briansmith closed 4 months ago

briansmith commented 4 months ago

Previously, the compiler would bounds-check the array slicing in Digest::as_ref(). It would also do (and still does, to a lesser extent) unnecessary bounds checks in BlockContext::{update, finish} and Context::{update, finish}. By using enums instead, the compiler is better able to understand the range (at least) of valid lengths, so it can optimize better. In particular, the compiler can elide some runtime bounds checks with these changes.

codecov[bot] commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 96.28%. Comparing base (a83de3c) to head (e8e508b).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1995 +/- ## ======================================= Coverage 96.28% 96.28% ======================================= Files 139 139 Lines 20800 20806 +6 Branches 226 226 ======================================= + Hits 20027 20033 +6 Misses 739 739 Partials 34 34 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.