summaryrefslogtreecommitdiffstats
path: root/crypto/openssh/bufaux.c
diff options
context:
space:
mode:
authorkris <kris@FreeBSD.org>2000-05-15 05:24:25 +0000
committerkris <kris@FreeBSD.org>2000-05-15 05:24:25 +0000
commita632b4789caf015f977f45e2d106cc00efa1239f (patch)
treeeb8a772c0dc7204d341277f265caa0c7c543c32c /crypto/openssh/bufaux.c
parent8cf8ce7bb13515db269566309a8e9cd8b309ee56 (diff)
downloadFreeBSD-src-a632b4789caf015f977f45e2d106cc00efa1239f.zip
FreeBSD-src-a632b4789caf015f977f45e2d106cc00efa1239f.tar.gz
Resolve conflicts and update for FreeBSD.
Diffstat (limited to 'crypto/openssh/bufaux.c')
-rw-r--r--crypto/openssh/bufaux.c73
1 files changed, 62 insertions, 11 deletions
diff --git a/crypto/openssh/bufaux.c b/crypto/openssh/bufaux.c
index 6a0c559..d813594 100644
--- a/crypto/openssh/bufaux.c
+++ b/crypto/openssh/bufaux.c
@@ -1,22 +1,24 @@
/*
- *
+ *
* 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
+ *
* $FreeBSD$
*/
#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 <openssl/bn.h>
@@ -77,9 +79,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];
@@ -90,7 +136,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];
@@ -130,17 +176,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;
@@ -151,7 +202,7 @@ buffer_get_char(Buffer *buffer)
/*
* Stores a character in the buffer.
*/
-void
+void
buffer_put_char(Buffer *buffer, int value)
{
char ch = value;
OpenPOWER on IntegriCloud