fix and optimise native digest calculations, and introduce test