Ensure counter is digested high order byte first.
Minor refactor.
Simplify encode_digest.