refactoring _secure_hash functions