bufaux.c (57464) | bufaux.c (58585) |
---|---|
1/* 2 * 3 * bufaux.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: Wed Mar 29 02:24:47 1995 ylo 11 * 12 * Auxiliary functions for storing and retrieving various data types to/from 13 * Buffers. 14 * | 1/* 2 * 3 * bufaux.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: Wed Mar 29 02:24:47 1995 ylo 11 * 12 * Auxiliary functions for storing and retrieving various data types to/from 13 * Buffers. 14 * |
15 * $FreeBSD: head/crypto/openssh/bufaux.c 57464 2000-02-25 01:53:12Z green $ | 15 * $FreeBSD: head/crypto/openssh/bufaux.c 58585 2000-03-26 07:37:48Z kris $ |
16 */ 17 18#include "includes.h" | 16 */ 17 18#include "includes.h" |
19RCSID("$Id: bufaux.c,v 1.7 1999/11/24 19:53:44 markus Exp $"); | 19RCSID("$Id: bufaux.c,v 1.8 2000/03/16 20:56:14 markus Exp $"); |
20 21#include "ssh.h" 22#include <openssl/bn.h> 23#include "bufaux.h" 24#include "xmalloc.h" 25#include "getput.h" 26 27/* 28 * Stores an BIGNUM in the buffer with a 2-byte msb first bit count, followed 29 * by (bits+7)/8 bytes of binary data, msb first. 30 */ 31void 32buffer_put_bignum(Buffer *buffer, BIGNUM *value) 33{ 34 int bits = BN_num_bits(value); 35 int bin_size = (bits + 7) / 8; | 20 21#include "ssh.h" 22#include <openssl/bn.h> 23#include "bufaux.h" 24#include "xmalloc.h" 25#include "getput.h" 26 27/* 28 * Stores an BIGNUM in the buffer with a 2-byte msb first bit count, followed 29 * by (bits+7)/8 bytes of binary data, msb first. 30 */ 31void 32buffer_put_bignum(Buffer *buffer, BIGNUM *value) 33{ 34 int bits = BN_num_bits(value); 35 int bin_size = (bits + 7) / 8; |
36 char *buf = xmalloc(bin_size); | 36 char unsigned *buf = xmalloc(bin_size); |
37 int oi; 38 char msg[2]; 39 40 /* Get the value of in binary */ 41 oi = BN_bn2bin(value, buf); 42 if (oi != bin_size) 43 fatal("buffer_put_bignum: BN_bn2bin() failed: oi %d != bin_size %d", 44 oi, bin_size); 45 46 /* Store the number of bits in the buffer in two bytes, msb first. */ 47 PUT_16BIT(msg, bits); 48 buffer_append(buffer, msg, 2); 49 /* Store the binary data. */ | 37 int oi; 38 char msg[2]; 39 40 /* Get the value of in binary */ 41 oi = BN_bn2bin(value, buf); 42 if (oi != bin_size) 43 fatal("buffer_put_bignum: BN_bn2bin() failed: oi %d != bin_size %d", 44 oi, bin_size); 45 46 /* Store the number of bits in the buffer in two bytes, msb first. */ 47 PUT_16BIT(msg, bits); 48 buffer_append(buffer, msg, 2); 49 /* Store the binary data. */ |
50 buffer_append(buffer, buf, oi); | 50 buffer_append(buffer, (char *)buf, oi); |
51 52 memset(buf, 0, bin_size); 53 xfree(buf); 54} 55 56/* 57 * Retrieves an BIGNUM from the buffer. 58 */ --- 5 unchanged lines hidden (view full) --- 64 65 /* Get the number for bits. */ 66 buffer_get(buffer, (char *) buf, 2); 67 bits = GET_16BIT(buf); 68 /* Compute the number of binary bytes that follow. */ 69 bytes = (bits + 7) / 8; 70 if (buffer_len(buffer) < bytes) 71 fatal("buffer_get_bignum: input buffer too small"); | 51 52 memset(buf, 0, bin_size); 53 xfree(buf); 54} 55 56/* 57 * Retrieves an BIGNUM from the buffer. 58 */ --- 5 unchanged lines hidden (view full) --- 64 65 /* Get the number for bits. */ 66 buffer_get(buffer, (char *) buf, 2); 67 bits = GET_16BIT(buf); 68 /* Compute the number of binary bytes that follow. */ 69 bytes = (bits + 7) / 8; 70 if (buffer_len(buffer) < bytes) 71 fatal("buffer_get_bignum: input buffer too small"); |
72 bin = buffer_ptr(buffer); | 72 bin = (unsigned char*) buffer_ptr(buffer); |
73 BN_bin2bn(bin, bytes, value); 74 buffer_consume(buffer, bytes); 75 76 return 2 + bytes; 77} 78 79/* 80 * Returns an integer from the buffer (4 bytes, msb first). --- 79 unchanged lines hidden --- | 73 BN_bin2bn(bin, bytes, value); 74 buffer_consume(buffer, bytes); 75 76 return 2 + bytes; 77} 78 79/* 80 * Returns an integer from the buffer (4 bytes, msb first). --- 79 unchanged lines hidden --- |