5 Author: Tatu Ylonen <ylo@cs.hut.fi>
7 Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
10 Created: Sun Jul 16 04:29:30 1995 ylo
12 This file contains various auxiliary functions related to multiple
21 #include <openssl/bn.h>
22 #include <openssl/md5.h>
34 compute_session_id(unsigned char session_id[16],
35 unsigned char cookie[8],
37 BIGNUM *session_key_n)
39 unsigned int host_key_bits = BN_num_bits(host_key_n);
40 unsigned int session_key_bits = BN_num_bits(session_key_n);
41 unsigned int bytes = (host_key_bits + 7) / 8 + (session_key_bits + 7) / 8 + 8;
42 unsigned char *buf = xmalloc(bytes);
45 BN_bn2bin(host_key_n, buf);
46 BN_bn2bin(session_key_n, buf + (host_key_bits + 7 ) / 8);
47 memcpy(buf + (host_key_bits + 7) / 8 + (session_key_bits + 7) / 8,
50 MD5_Update(&md, buf, bytes);
51 MD5_Final(session_id, &md);
52 memset(buf, 0, bytes);