blob: fd2c180319efbce77d80372e91e4f6aa488668f6 [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"
18RCSID("$Id: mpaux.c,v 1.1 1999/10/27 03:42:44 damien Exp $");
19
20#include <openssl/bn.h>
21#include "getput.h"
22#include "xmalloc.h"
23
24#include <openssl/md5.h>
25
26void
27compute_session_id(unsigned char session_id[16],
28 unsigned char cookie[8],
29 unsigned int host_key_bits,
30 BIGNUM *host_key_n,
31 unsigned int session_key_bits,
32 BIGNUM *session_key_n)
33{
34 unsigned int bytes = (host_key_bits + 7) / 8 + (session_key_bits + 7) / 8 + 8;
35 unsigned char *buf = xmalloc(bytes);
36 MD5_CTX md;
37
38 BN_bn2bin(host_key_n, buf);
39 BN_bn2bin(session_key_n, buf + (host_key_bits + 7 ) / 8);
40 memcpy(buf + (host_key_bits + 7) / 8 + (session_key_bits + 7) / 8,
41 cookie, 8);
42 MD5_Init(&md);
43 MD5_Update(&md, buf, bytes);
44 MD5_Final(session_id, &md);
45 xfree(buf);
46}