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 | |
| 17 | #include "includes.h" |
Damien Miller | 4956d2c | 1999-11-13 10:51:58 +1100 | [diff] [blame] | 18 | RCSID("$Id: mpaux.c,v 1.5 1999/11/12 23:51:58 damien Exp $"); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 19 | |
Damien Miller | 7f6ea02 | 1999-10-28 13:25:17 +1000 | [diff] [blame] | 20 | #ifdef HAVE_OPENSSL |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 21 | #include <openssl/bn.h> |
Damien Miller | 7f6ea02 | 1999-10-28 13:25:17 +1000 | [diff] [blame] | 22 | #include <openssl/md5.h> |
| 23 | #endif |
| 24 | #ifdef HAVE_SSL |
| 25 | #include <ssl/bn.h> |
| 26 | #include <ssl/md5.h> |
| 27 | #endif |
| 28 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 29 | #include "getput.h" |
| 30 | #include "xmalloc.h" |
| 31 | |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 32 | |
| 33 | void |
| 34 | compute_session_id(unsigned char session_id[16], |
| 35 | unsigned char cookie[8], |
| 36 | unsigned int host_key_bits, |
| 37 | BIGNUM *host_key_n, |
| 38 | unsigned int session_key_bits, |
| 39 | BIGNUM *session_key_n) |
| 40 | { |
| 41 | unsigned int bytes = (host_key_bits + 7) / 8 + (session_key_bits + 7) / 8 + 8; |
| 42 | unsigned char *buf = xmalloc(bytes); |
| 43 | MD5_CTX md; |
| 44 | |
| 45 | BN_bn2bin(host_key_n, buf); |
| 46 | BN_bn2bin(session_key_n, buf + (host_key_bits + 7 ) / 8); |
| 47 | memcpy(buf + (host_key_bits + 7) / 8 + (session_key_bits + 7) / 8, |
| 48 | cookie, 8); |
| 49 | MD5_Init(&md); |
| 50 | MD5_Update(&md, buf, bytes); |
| 51 | MD5_Final(session_id, &md); |
Damien Miller | 6d7b2cd | 1999-11-12 15:19:27 +1100 | [diff] [blame] | 52 | memset(buf, 0, bytes); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 53 | xfree(buf); |
| 54 | } |