Move hash computation code into a separate class and file.

No functional change intended.