version 1.35.2.2, 2006/02/03 02:53:44 |
version 1.41, 2006/03/30 09:58:15 |
|
|
|
/* $OpenBSD$ */ |
/* |
/* |
* Author: Tatu Ylonen <ylo@cs.hut.fi> |
* Author: Tatu Ylonen <ylo@cs.hut.fi> |
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
|
|
*/ |
*/ |
|
|
#include "includes.h" |
#include "includes.h" |
RCSID("$OpenBSD$"); |
|
|
|
#include <openssl/bn.h> |
#include <openssl/bn.h> |
#include "bufaux.h" |
#include "bufaux.h" |
#include "xmalloc.h" |
#include "xmalloc.h" |
#include "getput.h" |
|
#include "log.h" |
#include "log.h" |
|
#include "misc.h" |
|
|
/* |
/* |
* Stores an BIGNUM in the buffer with a 2-byte msb first bit count, followed |
* Stores an BIGNUM in the buffer with a 2-byte msb first bit count, followed |
|
|
} |
} |
|
|
/* Store the number of bits in the buffer in two bytes, msb first. */ |
/* Store the number of bits in the buffer in two bytes, msb first. */ |
PUT_16BIT(msg, bits); |
put_u16(msg, bits); |
buffer_append(buffer, msg, 2); |
buffer_append(buffer, msg, 2); |
/* Store the binary data. */ |
/* Store the binary data. */ |
buffer_append(buffer, (char *)buf, oi); |
buffer_append(buffer, buf, oi); |
|
|
memset(buf, 0, bin_size); |
memset(buf, 0, bin_size); |
xfree(buf); |
xfree(buf); |
|
|
error("buffer_get_bignum_ret: invalid length"); |
error("buffer_get_bignum_ret: invalid length"); |
return (-1); |
return (-1); |
} |
} |
bits = GET_16BIT(buf); |
bits = get_u16(buf); |
/* Compute the number of binary bytes that follow. */ |
/* Compute the number of binary bytes that follow. */ |
bytes = (bits + 7) / 8; |
bytes = (bits + 7) / 8; |
if (bytes > 8 * 1024) { |
if (bytes > 8 * 1024) { |
|
|
|
|
if (buffer_get_ret(buffer, (char *) buf, 2) == -1) |
if (buffer_get_ret(buffer, (char *) buf, 2) == -1) |
return (-1); |
return (-1); |
*ret = GET_16BIT(buf); |
*ret = get_u16(buf); |
return (0); |
return (0); |
} |
} |
|
|
|
|
|
|
if (buffer_get_ret(buffer, (char *) buf, 4) == -1) |
if (buffer_get_ret(buffer, (char *) buf, 4) == -1) |
return (-1); |
return (-1); |
*ret = GET_32BIT(buf); |
*ret = get_u32(buf); |
return (0); |
return (0); |
} |
} |
|
|
|
|
|
|
if (buffer_get_ret(buffer, (char *) buf, 8) == -1) |
if (buffer_get_ret(buffer, (char *) buf, 8) == -1) |
return (-1); |
return (-1); |
*ret = GET_64BIT(buf); |
*ret = get_u64(buf); |
return (0); |
return (0); |
} |
} |
|
|
|
|
{ |
{ |
char buf[2]; |
char buf[2]; |
|
|
PUT_16BIT(buf, value); |
put_u16(buf, value); |
buffer_append(buffer, buf, 2); |
buffer_append(buffer, buf, 2); |
} |
} |
|
|
|
|
{ |
{ |
char buf[4]; |
char buf[4]; |
|
|
PUT_32BIT(buf, value); |
put_u32(buf, value); |
buffer_append(buffer, buf, 4); |
buffer_append(buffer, buf, 4); |
} |
} |
|
|
|
|
{ |
{ |
char buf[8]; |
char buf[8]; |
|
|
PUT_64BIT(buf, value); |
put_u64(buf, value); |
buffer_append(buffer, buf, 8); |
buffer_append(buffer, buf, 8); |
} |
} |
|
|