blob: 24e9ce138e51983788a636c13c646b52156f1e3b [file] [log] [blame]
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001/*
Damien Miller95def091999-11-25 00:26:21 +11002 *
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 *
Damien Millerd4a8b7e1999-10-27 13:42:43 +100015*/
16
17#include "includes.h"
Damien Millera34a28b1999-12-14 10:47:15 +110018RCSID("$Id: mpaux.c,v 1.8 1999/12/13 23:47:16 damien Exp $");
Damien Miller95def091999-11-25 00:26:21 +110019
20#include "getput.h"
21#include "xmalloc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100022
Damien Miller7f6ea021999-10-28 13:25:17 +100023#ifdef HAVE_OPENSSL
Damien Millerd4a8b7e1999-10-27 13:42:43 +100024#include <openssl/bn.h>
Damien Miller7f6ea021999-10-28 13:25:17 +100025#include <openssl/md5.h>
26#endif
27#ifdef HAVE_SSL
28#include <ssl/bn.h>
29#include <ssl/md5.h>
30#endif
31
Damien Millerd4a8b7e1999-10-27 13:42:43 +100032void
33compute_session_id(unsigned char session_id[16],
34 unsigned char cookie[8],
Damien Miller95def091999-11-25 00:26:21 +110035 BIGNUM* host_key_n,
36 BIGNUM* session_key_n)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100037{
Damien Millera34a28b1999-12-14 10:47:15 +110038 unsigned int host_key_bytes = BN_num_bytes(host_key_n);
39 unsigned int session_key_bytes = BN_num_bytes(session_key_n);
40 unsigned int bytes = host_key_bytes + session_key_bytes;
Damien Miller95def091999-11-25 00:26:21 +110041 unsigned char *buf = xmalloc(bytes);
42 MD5_CTX md;
Damien Miller7e8e8201999-11-16 13:37:16 +110043
Damien Miller95def091999-11-25 00:26:21 +110044 BN_bn2bin(host_key_n, buf);
Damien Millera34a28b1999-12-14 10:47:15 +110045 BN_bn2bin(session_key_n, buf + host_key_bytes);
Damien Miller95def091999-11-25 00:26:21 +110046 MD5_Init(&md);
47 MD5_Update(&md, buf, bytes);
Damien Millera34a28b1999-12-14 10:47:15 +110048 MD5_Update(&md, cookie, 8);
Damien Miller95def091999-11-25 00:26:21 +110049 MD5_Final(session_id, &md);
50 memset(buf, 0, bytes);
51 xfree(buf);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100052}