I want to generate something like VisualHostKey for a SHA checksum. But it should work with any hexadecimal checksum.
The generated artifact could be an ASCII art, a 2D colour palette, or just some random garbage in a PNG. Personally I like the VisualHostKey approach but I am open for suggestions.
The idea is to be able to quickly identify that two checksums are the same using just the human eye. And when faced with a bunch of sums, quickly find the one you are looking for.
You could just use the actual OpenSSH VisualHostKey code, which is found in the
key_fingerprint_randomart()
function in thekey.c
file in the OpenSSH source code. The algorithm is fairly simple, and can take any array of bytes as input. In OpenSSH, the input is a cryptographic hash of the key; you could do the same.(As defined in the OpenSSH source code, the function also takes a pointer to the key structure itself, but that's only used to print the type and size of the key at the top of the picture.)
In fact, since the code is freely licensed, let me just include a copy here. This is extracted from OpenSSH 6.1,
$OpenBSD: key.c,v 1.99 2012/05/23 03:28:28 djm Exp $
:It doesn't seem to have an significant dependencies on the rest of the OpenSSH code, aside from the
const Key *k
parameter, which is only used on one line as an argument to thekey_type()
andkey_size()
functions (or macros?). The nonstandard typesu_char
andu_int
appear to be just aliases forunsigned char
andunsigned int
respectively, and thexcalloc()
function seems to be just a replacement or wrapper for the standardcalloc()
.