blob: 2384c826b56dab9af564b31db1188c1a4c430cdd [file] [log] [blame]
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001/*
Damien Miller4af51302000-04-16 11:18:38 +10002 *
Damien Miller95def091999-11-25 00:26:21 +11003 * mpaux.c
Damien Miller4af51302000-04-16 11:18:38 +10004 *
Damien Miller95def091999-11-25 00:26:21 +11005 * Author: Tatu Ylonen <ylo@cs.hut.fi>
Damien Miller4af51302000-04-16 11:18:38 +10006 *
Damien Miller95def091999-11-25 00:26:21 +11007 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
8 * All rights reserved
Damien Miller4af51302000-04-16 11:18:38 +10009 *
Damien Miller95def091999-11-25 00:26:21 +110010 * Created: Sun Jul 16 04:29:30 1995 ylo
Damien Miller4af51302000-04-16 11:18:38 +100011 *
Damien Miller95def091999-11-25 00:26:21 +110012 * This file contains various auxiliary functions related to multiple
13 * precision integers.
Damien Miller4af51302000-04-16 11:18:38 +100014 *
Damien Millerd4a8b7e1999-10-27 13:42:43 +100015*/
16
17#include "includes.h"
Damien Miller5f056372000-04-16 12:31:48 +100018RCSID("$Id: mpaux.c,v 1.12 2000/04/16 02:31:51 damien Exp $");
Damien Miller95def091999-11-25 00:26:21 +110019
Damien Miller5f056372000-04-16 12:31:48 +100020#include <openssl/bn.h>
Damien Miller95def091999-11-25 00:26:21 +110021#include "getput.h"
22#include "xmalloc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100023
Damien Miller7f6ea021999-10-28 13:25:17 +100024#include <openssl/md5.h>
Damien Miller7f6ea021999-10-28 13:25:17 +100025
Damien Millerd4a8b7e1999-10-27 13:42:43 +100026void
27compute_session_id(unsigned char session_id[16],
Damien Millerb38eff82000-04-01 11:09:21 +100028 unsigned char cookie[8],
29 BIGNUM* host_key_n,
30 BIGNUM* session_key_n)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100031{
Damien Millera34a28b1999-12-14 10:47:15 +110032 unsigned int host_key_bytes = BN_num_bytes(host_key_n);
33 unsigned int session_key_bytes = BN_num_bytes(session_key_n);
34 unsigned int bytes = host_key_bytes + session_key_bytes;
Damien Miller95def091999-11-25 00:26:21 +110035 unsigned char *buf = xmalloc(bytes);
36 MD5_CTX md;
Damien Miller7e8e8201999-11-16 13:37:16 +110037
Damien Miller95def091999-11-25 00:26:21 +110038 BN_bn2bin(host_key_n, buf);
Damien Millera34a28b1999-12-14 10:47:15 +110039 BN_bn2bin(session_key_n, buf + host_key_bytes);
Damien Miller95def091999-11-25 00:26:21 +110040 MD5_Init(&md);
41 MD5_Update(&md, buf, bytes);
Damien Millera34a28b1999-12-14 10:47:15 +110042 MD5_Update(&md, cookie, 8);
Damien Miller95def091999-11-25 00:26:21 +110043 MD5_Final(session_id, &md);
44 memset(buf, 0, bytes);
45 xfree(buf);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100046}