blob: e1b97a1583d0982f4e688bca235a0e4e2216e637 [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
Damien Miller7f6ea021999-10-28 13:25:17 +100017#include "config.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100018#include "includes.h"
Damien Miller01ab4a21999-10-28 15:23:30 +100019RCSID("$Id: mpaux.c,v 1.3 1999/10/28 05:23:30 damien Exp $");
Damien Millerd4a8b7e1999-10-27 13:42:43 +100020
Damien Miller7f6ea021999-10-28 13:25:17 +100021#ifdef HAVE_OPENSSL
Damien Millerd4a8b7e1999-10-27 13:42:43 +100022#include <openssl/bn.h>
Damien Miller7f6ea021999-10-28 13:25:17 +100023#include <openssl/md5.h>
24#endif
25#ifdef HAVE_SSL
26#include <ssl/bn.h>
27#include <ssl/md5.h>
28#endif
29
Damien Millerd4a8b7e1999-10-27 13:42:43 +100030#include "getput.h"
31#include "xmalloc.h"
32
Damien Millerd4a8b7e1999-10-27 13:42:43 +100033
34void
35compute_session_id(unsigned char session_id[16],
36 unsigned char cookie[8],
37 unsigned int host_key_bits,
38 BIGNUM *host_key_n,
39 unsigned int session_key_bits,
40 BIGNUM *session_key_n)
41{
42 unsigned int bytes = (host_key_bits + 7) / 8 + (session_key_bits + 7) / 8 + 8;
43 unsigned char *buf = xmalloc(bytes);
44 MD5_CTX md;
45
46 BN_bn2bin(host_key_n, buf);
47 BN_bn2bin(session_key_n, buf + (host_key_bits + 7 ) / 8);
48 memcpy(buf + (host_key_bits + 7) / 8 + (session_key_bits + 7) / 8,
49 cookie, 8);
50 MD5_Init(&md);
51 MD5_Update(&md, buf, bytes);
52 MD5_Final(session_id, &md);
53 xfree(buf);
54}