blob: 6b586ec04149646fbaeab54311597fe30bf086eb [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 Lindstrom46c16222000-12-22 01:43:59 +000016RCSID("$OpenBSD: mpaux.c,v 1.15 2000/12/19 23:17:57 markus 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
Damien Millerd4a8b7e1999-10-27 13:42:43 +100024void
Ben Lindstrom46c16222000-12-22 01:43:59 +000025compute_session_id(u_char session_id[16],
26 u_char cookie[8],
Damien Millerb38eff82000-04-01 11:09:21 +100027 BIGNUM* host_key_n,
28 BIGNUM* session_key_n)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100029{
Ben Lindstrom46c16222000-12-22 01:43:59 +000030 u_int host_key_bytes = BN_num_bytes(host_key_n);
31 u_int session_key_bytes = BN_num_bytes(session_key_n);
32 u_int bytes = host_key_bytes + session_key_bytes;
33 u_char *buf = xmalloc(bytes);
Damien Miller95def091999-11-25 00:26:21 +110034 MD5_CTX md;
Damien Miller7e8e8201999-11-16 13:37:16 +110035
Damien Miller95def091999-11-25 00:26:21 +110036 BN_bn2bin(host_key_n, buf);
Damien Millera34a28b1999-12-14 10:47:15 +110037 BN_bn2bin(session_key_n, buf + host_key_bytes);
Damien Miller95def091999-11-25 00:26:21 +110038 MD5_Init(&md);
39 MD5_Update(&md, buf, bytes);
Damien Millera34a28b1999-12-14 10:47:15 +110040 MD5_Update(&md, cookie, 8);
Damien Miller95def091999-11-25 00:26:21 +110041 MD5_Final(session_id, &md);
42 memset(buf, 0, bytes);
43 xfree(buf);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100044}