]>
Commit | Line | Data |
---|---|---|
f095fcc7 | 1 | #include "includes.h" |
2 | RCSID("$Id$"); | |
3 | ||
4 | #include "ssh.h" | |
5 | #include "xmalloc.h" | |
7b1cc56c | 6 | |
7 | #ifdef HAVE_OPENSSL | |
8 | #include <openssl/md5.h> | |
9 | #endif | |
10 | #ifdef HAVE_SSL | |
f095fcc7 | 11 | #include <ssl/md5.h> |
7b1cc56c | 12 | #endif |
f095fcc7 | 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 | } |