bufaux.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
* All rights reserved
* Buffers.
*
* As far as I am concerned, the code I have written for this software
* can be used freely for any purpose. Any derived versions of this
* software must be clearly marked as such, and if the derived work is
* incompatible with the protocol description in the RFC file, it must be
* called by a name other than "ssh" or "Secure Shell".
*
*
* SSH2 packet format added by Markus Friedl
* Copyright (c) 2000 Markus Friedl. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "includes.h"
#pragma ident "%Z%%M% %I% %E% SMI"
#include <langinfo.h>
#include "bufaux.h"
#include "xmalloc.h"
#include "getput.h"
#include "log.h"
#include "g11n.h"
/*
* Stores an BIGNUM in the buffer with a 2-byte msb first bit count, followed
* by (bits+7)/8 bytes of binary data, msb first.
*/
void
{
int oi;
char msg[2];
/* Get the value of in binary */
fatal("buffer_put_bignum: BN_bn2bin() failed: oi %d != bin_size %d",
/* Store the number of bits in the buffer in two bytes, msb first. */
/* Store the binary data. */
}
/*
* Retrieves an BIGNUM from the buffer.
*/
void
{
/* Get the number for bits. */
/* Compute the number of binary bytes that follow. */
fatal("buffer_get_bignum: input buffer too small");
}
/*
* Stores an BIGNUM in the buffer in SSH2 format.
*/
void
{
int oi;
int hasnohigh = 0;
buf[0] = '\0';
/* Get the value of in binary */
fatal("buffer_put_bignum: BN_bn2bin() failed: oi %d != bin_size %d",
/**XXX should be two's-complement */
int i, carry;
log("negativ!");
uc[i] ^= 0xff;
if (carry)
}
}
}
/* XXX does not handle negative BNs */
void
{
}
/*
* Returns integers from the buffer (msb first).
*/
{
}
{
}
#ifdef HAVE_U_INT64_T
{
}
#endif
/*
* Stores integers in the buffer, msb first.
*/
void
{
char buf[2];
}
void
{
char buf[4];
}
#ifdef HAVE_U_INT64_T
void
{
char buf[8];
}
#endif
/*
* Returns an arbitrary binary string from the buffer. The string cannot
* be longer than 256k. The returned value points to memory allocated
* with xmalloc; it is the responsibility of the calling function to free
* the data. If length_ptr is non-NULL, the length of the returned data
* will be stored there. A null character will be automatically appended
* to the returned string, and is not counted in length.
*/
void *
{
/* Get the length. */
/* Allocate space for the string. Add one byte for a null character. */
/* Get the string. */
/* Append a null character to make processing easier. */
/* Optionally return the length of the string. */
if (length_ptr)
*length_ptr = len;
return value;
}
char *
{
char *value;
u_char *p;
/* Look for NULL or high-bit set bytes */
p++) ;
/* If there were any, bomb */
return NULL;
}
return value;
}
u_char *
{
int err;
return value;
}
if (err)
return converted;
}
/*
* Stores and arbitrary binary string in the buffer.
*/
void
{
}
void
{
if (s == NULL)
fatal("buffer_put_cstring: s == NULL");
}
/*
* ASCII versions of the above
*/
#if 0
void
{
u_char *p;
p++) ;
verbose("buffer_put_ascii_string: storing a non-ASCII string");
}
#endif
void
{
if (s == NULL)
fatal("buffer_put_cstring: s == NULL");
buffer_put_cstring(buffer, s);
}
/*
* UTF-8 versions of the above.
*/
#if 0
void
{
if (err)
return;
}
#endif
void
{
int err;
if (s == NULL)
fatal("buffer_put_cstring: s == NULL");
if (err)
return;
}
/*
* Returns a character from the buffer (0 - 255).
*/
int
{
char ch;
}
/*
* Stores a character in the buffer.
*/
void
{
}