use Digest::SHA, fix state generator