diff options
author | kris <kris@FreeBSD.org> | 2000-05-15 04:37:24 +0000 |
---|---|---|
committer | kris <kris@FreeBSD.org> | 2000-05-15 04:37:24 +0000 |
commit | 4dc8aa85ced77e9e02dea6939edd4d3564b5086e (patch) | |
tree | 772b9de8852fb4c32957c00639a4fd5460f8a62b /crypto/openssh/bufaux.c | |
parent | b201b15ee1575ab28ed4f9b5a7d430e835a7c7ae (diff) | |
download | FreeBSD-src-4dc8aa85ced77e9e02dea6939edd4d3564b5086e.zip FreeBSD-src-4dc8aa85ced77e9e02dea6939edd4d3564b5086e.tar.gz |
Initial import of OpenSSH v2.1.
Diffstat (limited to 'crypto/openssh/bufaux.c')
-rw-r--r-- | crypto/openssh/bufaux.c | 75 |
1 files changed, 63 insertions, 12 deletions
diff --git a/crypto/openssh/bufaux.c b/crypto/openssh/bufaux.c index dddc41f..922acc4 100644 --- a/crypto/openssh/bufaux.c +++ b/crypto/openssh/bufaux.c @@ -1,24 +1,26 @@ /* - * + * * bufaux.c - * + * * Author: Tatu Ylonen <ylo@cs.hut.fi> - * + * * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland * All rights reserved - * + * * Created: Wed Mar 29 02:24:47 1995 ylo - * + * * Auxiliary functions for storing and retrieving various data types to/from * Buffers. * + * SSH2 packet format added by Markus Friedl + * */ #include "includes.h" -RCSID("$Id: bufaux.c,v 1.8 2000/03/16 20:56:14 markus Exp $"); +RCSID("$Id: bufaux.c,v 1.11 2000/04/14 10:30:30 markus Exp $"); #include "ssh.h" -#include <ssl/bn.h> +#include <openssl/bn.h> #include "bufaux.h" #include "xmalloc.h" #include "getput.h" @@ -76,9 +78,53 @@ buffer_get_bignum(Buffer *buffer, BIGNUM *value) } /* + * Stores an BIGNUM in the buffer in SSH2 format. + */ +void +buffer_put_bignum2(Buffer *buffer, BIGNUM *value) +{ + int bytes = BN_num_bytes(value) + 1; + unsigned char *buf = xmalloc(bytes); + int oi; + int hasnohigh = 0; + buf[0] = '\0'; + /* Get the value of in binary */ + oi = BN_bn2bin(value, buf+1); + if (oi != bytes-1) + fatal("buffer_put_bignum: BN_bn2bin() failed: oi %d != bin_size %d", + oi, bytes); + hasnohigh = (buf[1] & 0x80) ? 0 : 1; + if (value->neg) { + /**XXX should be two's-complement */ + int i, carry; + unsigned char *uc = buf; + log("negativ!"); + for(i = bytes-1, carry = 1; i>=0; i--) { + uc[i] ^= 0xff; + if(carry) + carry = !++uc[i]; + } + } + buffer_put_string(buffer, buf+hasnohigh, bytes-hasnohigh); + memset(buf, 0, bytes); + xfree(buf); +} + +int +buffer_get_bignum2(Buffer *buffer, BIGNUM *value) +{ + /**XXX should be two's-complement */ + int len; + unsigned char *bin = (unsigned char *)buffer_get_string(buffer, (unsigned int *)&len); + BN_bin2bn(bin, len, value); + xfree(bin); + return len; +} + +/* * Returns an integer from the buffer (4 bytes, msb first). */ -unsigned int +unsigned int buffer_get_int(Buffer *buffer) { unsigned char buf[4]; @@ -89,7 +135,7 @@ buffer_get_int(Buffer *buffer) /* * Stores an integer in the buffer in 4 bytes, msb first. */ -void +void buffer_put_int(Buffer *buffer, unsigned int value) { char buf[4]; @@ -129,17 +175,22 @@ buffer_get_string(Buffer *buffer, unsigned int *length_ptr) /* * Stores and arbitrary binary string in the buffer. */ -void +void buffer_put_string(Buffer *buffer, const void *buf, unsigned int len) { buffer_put_int(buffer, len); buffer_append(buffer, buf, len); } +void +buffer_put_cstring(Buffer *buffer, const char *s) +{ + buffer_put_string(buffer, s, strlen(s)); +} /* * Returns a character from the buffer (0 - 255). */ -int +int buffer_get_char(Buffer *buffer) { char ch; @@ -150,7 +201,7 @@ buffer_get_char(Buffer *buffer) /* * Stores a character in the buffer. */ -void +void buffer_put_char(Buffer *buffer, int value) { char ch = value; |