blob: 9a9b6358397bf06da50ba961ad215819c34a35e8 [file] [log] [blame]
Damien Miller10f6f6b1999-11-17 17:29:08 +11001#include "includes.h"
Damien Miller58fc4731999-11-19 12:05:01 +11002RCSID("$Id: fingerprint.c,v 1.1 1999/11/17 06:29:08 damien Exp $");
Damien Miller10f6f6b1999-11-17 17:29:08 +11003
4#include "ssh.h"
5#include "xmalloc.h"
Damien Miller58fc4731999-11-19 12:05:01 +11006
7#ifdef HAVE_OPENSSL
8#include <openssl/md5.h>
9#endif
10#ifdef HAVE_SSL
Damien Miller10f6f6b1999-11-17 17:29:08 +110011#include <ssl/md5.h>
Damien Miller58fc4731999-11-19 12:05:01 +110012#endif
Damien Miller10f6f6b1999-11-17 17:29:08 +110013
14#define FPRINT "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x"
15
16/* Generate key fingerprint in ascii format.
17 Based on ideas and code from Bjoern Groenvall <bg@sics.se> */
18
19char *
20fingerprint(BIGNUM *e, BIGNUM *n)
21{
22 static char retval[80];
23 MD5_CTX md;
24 unsigned char d[16];
25 char *buf;
26 int nlen, elen;
27
28 nlen = BN_num_bytes(n);
29 elen = BN_num_bytes(e);
30
31 buf = xmalloc(nlen + elen);
32
33 BN_bn2bin(n, buf);
34 BN_bn2bin(e, buf + nlen);
35
36 MD5_Init(&md);
37 MD5_Update(&md, buf, nlen + elen);
38 MD5_Final(d, &md);
39 snprintf(retval, sizeof(retval), FPRINT,
40 d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],
41 d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]);
42 memset(buf, 0, nlen + elen);
43 xfree(buf);
44 return retval;
45}