blob: 311b1ed9df1dd686e6a4f3c3e41970a3a18908a9 [file] [log] [blame]
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001/*
2
3mpaux.c
4
5Author: Tatu Ylonen <ylo@cs.hut.fi>
6
7Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
8 All rights reserved
9
10Created: Sun Jul 16 04:29:30 1995 ylo
11
12This file contains various auxiliary functions related to multiple
13precision integers.
14
15*/
16
17#include "includes.h"
Damien Miller4956d2c1999-11-13 10:51:58 +110018RCSID("$Id: mpaux.c,v 1.5 1999/11/12 23:51:58 damien Exp $");
Damien Millerd4a8b7e1999-10-27 13:42:43 +100019
Damien Miller7f6ea021999-10-28 13:25:17 +100020#ifdef HAVE_OPENSSL
Damien Millerd4a8b7e1999-10-27 13:42:43 +100021#include <openssl/bn.h>
Damien Miller7f6ea021999-10-28 13:25:17 +100022#include <openssl/md5.h>
23#endif
24#ifdef HAVE_SSL
25#include <ssl/bn.h>
26#include <ssl/md5.h>
27#endif
28
Damien Millerd4a8b7e1999-10-27 13:42:43 +100029#include "getput.h"
30#include "xmalloc.h"
31
Damien Millerd4a8b7e1999-10-27 13:42:43 +100032
33void
34compute_session_id(unsigned char session_id[16],
35 unsigned char cookie[8],
36 unsigned int host_key_bits,
37 BIGNUM *host_key_n,
38 unsigned int session_key_bits,
39 BIGNUM *session_key_n)
40{
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);
Damien Miller6d7b2cd1999-11-12 15:19:27 +110052 memset(buf, 0, bytes);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100053 xfree(buf);
54}