fiddling with constant-time compare
python3 compat
refactor to allow different algorithms