Damien Miller | 10f6f6b | 1999-11-17 17:29:08 +1100 | [diff] [blame] | 1 | #include "includes.h" |
Damien Miller | 58fc473 | 1999-11-19 12:05:01 +1100 | [diff] [blame] | 2 | RCSID("$Id: fingerprint.c,v 1.1 1999/11/17 06:29:08 damien Exp $"); |
Damien Miller | 10f6f6b | 1999-11-17 17:29:08 +1100 | [diff] [blame] | 3 | |
| 4 | #include "ssh.h" |
| 5 | #include "xmalloc.h" |
Damien Miller | 58fc473 | 1999-11-19 12:05:01 +1100 | [diff] [blame] | 6 | |
| 7 | #ifdef HAVE_OPENSSL |
| 8 | #include <openssl/md5.h> |
| 9 | #endif |
| 10 | #ifdef HAVE_SSL |
Damien Miller | 10f6f6b | 1999-11-17 17:29:08 +1100 | [diff] [blame] | 11 | #include <ssl/md5.h> |
Damien Miller | 58fc473 | 1999-11-19 12:05:01 +1100 | [diff] [blame] | 12 | #endif |
Damien Miller | 10f6f6b | 1999-11-17 17:29:08 +1100 | [diff] [blame] | 13 | |
| 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 | |
| 19 | char * |
| 20 | fingerprint(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 | } |