Implement module hashing algorithm from tboot and refactor.