These routines look fancy, but do nothing more than converting between
byte objects of length 32 to/from integers in little endian byte order
and can be replaced by simple one-liners, using the int.{from,to}_bytes
methods (available since Python 3.2).
Backport of [[ https://github.com/bitcoin/bitcoin/pull/27516 | core#27516 ]]