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.
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
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 notr == 0
. We should check for division by zero at the top, otherwise the algorithm just goes into a loop.Tested:
cargo test
passes.