blob: 0c486275ffbcd650f0c5ac03043eac6d88f40fd1 [file] [log] [blame]
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001/*
Damien Miller95def091999-11-25 00:26:21 +11002 * Author: Tatu Ylonen <ylo@cs.hut.fi>
Damien Miller95def091999-11-25 00:26:21 +11003 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved
Damien Miller95def091999-11-25 00:26:21 +11005 * This file contains various auxiliary functions related to multiple
6 * precision integers.
Damien Miller4af51302000-04-16 11:18:38 +10007 *
Damien Millere4340be2000-09-16 13:29:08 +11008 * As far as I am concerned, the code I have written for this software
9 * can be used freely for any purpose. Any derived versions of this
10 * software must be clearly marked as such, and if the derived work is
11 * incompatible with the protocol description in the RFC file, it must be
12 * called by a name other than "ssh" or "Secure Shell".
13 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100014
15#include "includes.h"
Ben Lindstrom31ca54a2001-02-09 02:11:24 +000016RCSID("$OpenBSD: mpaux.c,v 1.16 2001/02/08 19:30:52 itojun Exp $");
Damien Miller95def091999-11-25 00:26:21 +110017
Damien Miller5f056372000-04-16 12:31:48 +100018#include <openssl/bn.h>
Damien Miller95def091999-11-25 00:26:21 +110019#include "getput.h"
20#include "xmalloc.h"
Damien Millerd4a8b7e1999-10-27 13:42:43 +100021
Damien Miller7f6ea021999-10-28 13:25:17 +100022#include <openssl/md5.h>
Damien Miller7f6ea021999-10-28 13:25:17 +100023
Ben Lindstrom31ca54a2001-02-09 02:11:24 +000024#include "mpaux.h"
25
Damien Millerd4a8b7e1999-10-27 13:42:43 +100026void
Ben Lindstrom46c16222000-12-22 01:43:59 +000027compute_session_id(u_char session_id[16],
28 u_char cookie[8],
Damien Millerb38eff82000-04-01 11:09:21 +100029 BIGNUM* host_key_n,
30 BIGNUM* session_key_n)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100031{
Ben Lindstrom46c16222000-12-22 01:43:59 +000032 u_int host_key_bytes = BN_num_bytes(host_key_n);
33 u_int session_key_bytes = BN_num_bytes(session_key_n);
34 u_int bytes = host_key_bytes + session_key_bytes;
35 u_char *buf = xmalloc(bytes);
Damien Miller95def091999-11-25 00:26:21 +110036 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}