blob: 1ee8df19482bcd103dfdc6924f0b1343b70f50d0 [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"
Damien Millere4340be2000-09-16 13:29:08 +110016RCSID("$OpenBSD: mpaux.c,v 1.14 2000/09/07 20:27:52 deraadt 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
25compute_session_id(unsigned char session_id[16],
Damien Millerb38eff82000-04-01 11:09:21 +100026 unsigned char cookie[8],
27 BIGNUM* host_key_n,
28 BIGNUM* session_key_n)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100029{
Damien Millera34a28b1999-12-14 10:47:15 +110030 unsigned int host_key_bytes = BN_num_bytes(host_key_n);
31 unsigned int session_key_bytes = BN_num_bytes(session_key_n);
32 unsigned int bytes = host_key_bytes + session_key_bytes;
Damien Miller95def091999-11-25 00:26:21 +110033 unsigned char *buf = xmalloc(bytes);
34 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}