Annotation of src/usr.bin/ssh/mpaux.c, Revision 1.15
1.1 deraadt 1: /*
1.8 deraadt 2: * Author: Tatu Ylonen <ylo@cs.hut.fi>
3: * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4: * All rights reserved
5: * This file contains various auxiliary functions related to multiple
6: * precision integers.
1.12 markus 7: *
1.14 deraadt 8: * 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: */
1.1 deraadt 14:
15: #include "includes.h"
1.15 ! markus 16: RCSID("$OpenBSD: mpaux.c,v 1.14 2000/09/07 20:27:52 deraadt Exp $");
1.1 deraadt 17:
1.11 markus 18: #include <openssl/bn.h>
1.1 deraadt 19: #include "getput.h"
20: #include "xmalloc.h"
1.3 deraadt 21:
1.11 markus 22: #include <openssl/md5.h>
1.1 deraadt 23:
1.2 provos 24: void
1.15 ! markus 25: compute_session_id(u_char session_id[16],
! 26: u_char cookie[8],
1.10 markus 27: BIGNUM* host_key_n,
28: BIGNUM* session_key_n)
1.1 deraadt 29: {
1.15 ! markus 30: 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);
1.7 markus 34: MD5_CTX md;
1.6 markus 35:
1.7 markus 36: BN_bn2bin(host_key_n, buf);
1.9 markus 37: BN_bn2bin(session_key_n, buf + host_key_bytes);
1.7 markus 38: MD5_Init(&md);
39: MD5_Update(&md, buf, bytes);
1.9 markus 40: MD5_Update(&md, cookie, 8);
1.7 markus 41: MD5_Final(session_id, &md);
42: memset(buf, 0, bytes);
43: xfree(buf);
1.1 deraadt 44: }