blob: 0622f5b479a6ac249c01c0cfb67abf5cced7b62e [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 Miller6d7b2cd1999-11-12 15:19:27 +110019RCSID("$Id: mpaux.c,v 1.4 1999/11/12 04:19:27 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);
Damien Miller6d7b2cd1999-11-12 15:19:27 +110053 memset(buf, 0, bytes);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100054 xfree(buf);
55}