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