]> andersk Git - openssh.git/blob - mpaux.c
- Merged OpenBSD CVS changes:
[openssh.git] / mpaux.c
1 /*
2
3 mpaux.c
4
5 Author: Tatu Ylonen <ylo@cs.hut.fi>
6
7 Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
8                    All rights reserved
9
10 Created: Sun Jul 16 04:29:30 1995 ylo
11
12 This file contains various auxiliary functions related to multiple
13 precision integers.
14
15 */
16
17 #include "includes.h"
18 RCSID("$Id$");
19
20 #ifdef HAVE_OPENSSL
21 #include <openssl/bn.h>
22 #include <openssl/md5.h>
23 #endif
24 #ifdef HAVE_SSL
25 #include <ssl/bn.h>
26 #include <ssl/md5.h>
27 #endif
28
29 #include "getput.h"
30 #include "xmalloc.h"
31
32
33 void
34 compute_session_id(unsigned char session_id[16],
35                    unsigned char cookie[8],
36                    BIGNUM *host_key_n,
37                    BIGNUM *session_key_n)
38 {
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);
43   MD5_CTX md;
44
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,
48          cookie, 8);
49   MD5_Init(&md);
50   MD5_Update(&md, buf, bytes);
51   MD5_Final(session_id, &md);
52   memset(buf, 0, bytes);
53   xfree(buf);
54 }
This page took 0.069239 seconds and 5 git commands to generate.