Obtain identity hashes better

Don't assume that they are always of length 27, support larger hash sizes.
Also ignore lines that start with "r " but are not formatted correctly to
contain a proper identity hash.
Use MAX(int, int) from compat.h