Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1 | /* |
| 2 | |
| 3 | mpaux.c |
| 4 | |
| 5 | Author: Tatu Ylonen <ylo@cs.hut.fi> |
| 6 | |
| 7 | Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
| 8 | All rights reserved |
| 9 | |
| 10 | Created: Sun Jul 16 04:29:30 1995 ylo |
| 11 | |
| 12 | This file contains various auxiliary functions related to multiple |
| 13 | precision integers. |
| 14 | |
| 15 | */ |
| 16 | |
Damien Miller | 7f6ea02 | 1999-10-28 13:25:17 +1000 | [diff] [blame] | 17 | #include "config.h" |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 18 | #include "includes.h" |
Damien Miller | 01ab4a2 | 1999-10-28 15:23:30 +1000 | [diff] [blame^] | 19 | RCSID("$Id: mpaux.c,v 1.3 1999/10/28 05:23:30 damien Exp $"); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 20 | |
Damien Miller | 7f6ea02 | 1999-10-28 13:25:17 +1000 | [diff] [blame] | 21 | #ifdef HAVE_OPENSSL |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 22 | #include <openssl/bn.h> |
Damien Miller | 7f6ea02 | 1999-10-28 13:25:17 +1000 | [diff] [blame] | 23 | #include <openssl/md5.h> |
| 24 | #endif |
| 25 | #ifdef HAVE_SSL |
| 26 | #include <ssl/bn.h> |
| 27 | #include <ssl/md5.h> |
| 28 | #endif |
| 29 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 30 | #include "getput.h" |
| 31 | #include "xmalloc.h" |
| 32 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 33 | |
| 34 | void |
| 35 | compute_session_id(unsigned char session_id[16], |
| 36 | unsigned char cookie[8], |
| 37 | unsigned int host_key_bits, |
| 38 | BIGNUM *host_key_n, |
| 39 | unsigned int session_key_bits, |
| 40 | BIGNUM *session_key_n) |
| 41 | { |
| 42 | unsigned int bytes = (host_key_bits + 7) / 8 + (session_key_bits + 7) / 8 + 8; |
| 43 | unsigned char *buf = xmalloc(bytes); |
| 44 | MD5_CTX md; |
| 45 | |
| 46 | BN_bn2bin(host_key_n, buf); |
| 47 | BN_bn2bin(session_key_n, buf + (host_key_bits + 7 ) / 8); |
| 48 | memcpy(buf + (host_key_bits + 7) / 8 + (session_key_bits + 7) / 8, |
| 49 | cookie, 8); |
| 50 | MD5_Init(&md); |
| 51 | MD5_Update(&md, buf, bytes); |
| 52 | MD5_Final(session_id, &md); |
| 53 | xfree(buf); |
| 54 | } |