1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * Author: Tatu Ylonen <ylo@cs.hut.fi>
3*0Sstevel@tonic-gate * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4*0Sstevel@tonic-gate * All rights reserved
5*0Sstevel@tonic-gate * This file contains various auxiliary functions related to multiple
6*0Sstevel@tonic-gate * precision integers.
7*0Sstevel@tonic-gate *
8*0Sstevel@tonic-gate * As far as I am concerned, the code I have written for this software
9*0Sstevel@tonic-gate * can be used freely for any purpose. Any derived versions of this
10*0Sstevel@tonic-gate * software must be clearly marked as such, and if the derived work is
11*0Sstevel@tonic-gate * incompatible with the protocol description in the RFC file, it must be
12*0Sstevel@tonic-gate * called by a name other than "ssh" or "Secure Shell".
13*0Sstevel@tonic-gate */
14*0Sstevel@tonic-gate
15*0Sstevel@tonic-gate #include "includes.h"
16*0Sstevel@tonic-gate RCSID("$OpenBSD: mpaux.c,v 1.16 2001/02/08 19:30:52 itojun Exp $");
17*0Sstevel@tonic-gate
18*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
19*0Sstevel@tonic-gate
20*0Sstevel@tonic-gate #include <openssl/bn.h>
21*0Sstevel@tonic-gate #include "getput.h"
22*0Sstevel@tonic-gate #include "xmalloc.h"
23*0Sstevel@tonic-gate
24*0Sstevel@tonic-gate #include <openssl/md5.h>
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gate #include "mpaux.h"
27*0Sstevel@tonic-gate
28*0Sstevel@tonic-gate void
compute_session_id(u_char session_id[16],u_char cookie[8],BIGNUM * host_key_n,BIGNUM * session_key_n)29*0Sstevel@tonic-gate compute_session_id(u_char session_id[16],
30*0Sstevel@tonic-gate u_char cookie[8],
31*0Sstevel@tonic-gate BIGNUM* host_key_n,
32*0Sstevel@tonic-gate BIGNUM* session_key_n)
33*0Sstevel@tonic-gate {
34*0Sstevel@tonic-gate u_int host_key_bytes = BN_num_bytes(host_key_n);
35*0Sstevel@tonic-gate u_int session_key_bytes = BN_num_bytes(session_key_n);
36*0Sstevel@tonic-gate u_int bytes = host_key_bytes + session_key_bytes;
37*0Sstevel@tonic-gate u_char *buf = xmalloc(bytes);
38*0Sstevel@tonic-gate MD5_CTX md;
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gate BN_bn2bin(host_key_n, buf);
41*0Sstevel@tonic-gate BN_bn2bin(session_key_n, buf + host_key_bytes);
42*0Sstevel@tonic-gate MD5_Init(&md);
43*0Sstevel@tonic-gate MD5_Update(&md, buf, bytes);
44*0Sstevel@tonic-gate MD5_Update(&md, cookie, 8);
45*0Sstevel@tonic-gate MD5_Final(session_id, &md);
46*0Sstevel@tonic-gate memset(buf, 0, bytes);
47*0Sstevel@tonic-gate xfree(buf);
48*0Sstevel@tonic-gate }
49