cyphar / paperback

Paper backup generator suitable for long-term storage.
GNU General Public License v3.0
1.09k stars 40 forks source link

Small fixes to polynomial division and inverse #4

Closed filbranden closed 3 years ago

filbranden commented 3 years ago

There's an off-by-one issue in msb(), furthermore we should calculate the first rmsb only after the possible XOR when there's carry.

When looking for the inverse, we're expected to find r == 1 at the end (unless the polynomial is irreducible), and not r == 0. We should check for division by zero at the top, otherwise the algorithm just goes into a loop.

Tested: cargo test passes.

cyphar commented 3 years ago

I merged this manually and squashed it with my WIP commit -- but I added a Co-authored-by since you pretty much walked me through implementing this. Thank you so much! dfd56cf5bf4aadbc11180c96b52726adcf74afe9