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