def hash_host(hostname, salt=None):
if salt is None:<EOL><INDENT>salt = rng.read(SHA.digest_size)<EOL><DEDENT>else:<EOL><INDENT>if salt.startswith('<STR_LIT>'):<EOL><INDENT>salt = salt.split('<STR_LIT:|>')[<NUM_LIT:2>]<EOL><DEDENT>salt = base64.decodestring(salt)<EOL><DEDENT>assert len(salt) == SHA.digest_size<EOL>hmac = HMAC.HMAC(salt, hostname, SHA).digest()<EOL>hostkey = '<STR_LIT>' % (base64.encodestring(salt), base64.encodestring(hmac))<EOL>return hostkey.replace('<STR_LIT:\n>', '<STR_LIT>')<EOL>
Return a "hashed" form of the hostname, as used by openssh when storing
hashed hostnames in the known_hosts file.

@param hostname: the hostname to hash
@type hostname: str
@param salt: optional salt to use when hashing (must be 20 bytes long)
@type salt: str
@return: the hashed hostname
@rtype: str