summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2004-02-24 09:21:41 +1100
committerDarren Tucker <dtucker@zip.com.au>2004-02-24 09:21:41 +1100
commit0acc92a93cf66305042bfe27a19d9767b39599b2 (patch)
tree057d9b4775f0ed68c65f169c4986ee31a59160d1
parentefa3706f053895ffa6fca255585c20e55b11f769 (diff)
- markus@cvs.openbsd.org 2004/02/23 15:12:46
[bufaux.c] encode 0 correctly in buffer_put_bignum2; noted by Mikulas Patocka and drop support for negative BNs; ok otto@
-rw-r--r--ChangeLog6
-rw-r--r--bufaux.c35
2 files changed, 23 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index 5628b943f..ce4550384 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,10 @@
6 - markus@cvs.openbsd.org 2004/02/23 12:02:33 6 - markus@cvs.openbsd.org 2004/02/23 12:02:33
7 [sshd.c] 7 [sshd.c]
8 backout revision 1.279; set listen socket to non-block; ok henning. 8 backout revision 1.279; set listen socket to non-block; ok henning.
9 - markus@cvs.openbsd.org 2004/02/23 15:12:46
10 [bufaux.c]
11 encode 0 correctly in buffer_put_bignum2; noted by Mikulas Patocka
12 and drop support for negative BNs; ok otto@
9 13
1020040223 1420040223
11 - (dtucker) [session.c] Bug #789: Only make setcred call for !privsep in the 15 - (dtucker) [session.c] Bug #789: Only make setcred call for !privsep in the
@@ -1909,4 +1913,4 @@
1909 - Fix sshd BindAddress and -b options for systems using fake-getaddrinfo. 1913 - Fix sshd BindAddress and -b options for systems using fake-getaddrinfo.
1910 Report from murple@murple.net, diagnosis from dtucker@zip.com.au 1914 Report from murple@murple.net, diagnosis from dtucker@zip.com.au
1911 1915
1912$Id: ChangeLog,v 1.3245 2004/02/23 22:20:29 dtucker Exp $ 1916$Id: ChangeLog,v 1.3246 2004/02/23 22:21:41 dtucker Exp $
diff --git a/bufaux.c b/bufaux.c
index 339d74435..bf148316d 100644
--- a/bufaux.c
+++ b/bufaux.c
@@ -37,7 +37,7 @@
37 */ 37 */
38 38
39#include "includes.h" 39#include "includes.h"
40RCSID("$OpenBSD: bufaux.c,v 1.31 2003/11/10 16:23:41 jakob Exp $"); 40RCSID("$OpenBSD: bufaux.c,v 1.32 2004/02/23 15:12:46 markus Exp $");
41 41
42#include <openssl/bn.h> 42#include <openssl/bn.h>
43#include "bufaux.h" 43#include "bufaux.h"
@@ -103,46 +103,47 @@ buffer_get_bignum(Buffer *buffer, BIGNUM *value)
103void 103void
104buffer_put_bignum2(Buffer *buffer, const BIGNUM *value) 104buffer_put_bignum2(Buffer *buffer, const BIGNUM *value)
105{ 105{
106 u_int bytes = BN_num_bytes(value) + 1; 106 u_int bytes;
107 u_char *buf = xmalloc(bytes); 107 u_char *buf;
108 int oi; 108 int oi;
109 u_int hasnohigh = 0; 109 u_int hasnohigh = 0;
110 110
111 if (BN_is_zero(value)) {
112 buffer_put_int(buffer, 0);
113 return;
114 }
115 if (value->neg)
116 fatal("buffer_put_bignum2: negative numbers not supported");
117 bytes = BN_num_bytes(value) + 1; /* extra padding byte */
118 if (bytes < 2)
119 fatal("buffer_put_bignum2: BN too small");
120 buf = xmalloc(bytes);
111 buf[0] = '\0'; 121 buf[0] = '\0';
112 /* Get the value of in binary */ 122 /* Get the value of in binary */
113 oi = BN_bn2bin(value, buf+1); 123 oi = BN_bn2bin(value, buf+1);
114 if (oi != bytes-1) 124 if (oi != bytes-1)
115 fatal("buffer_put_bignum: BN_bn2bin() failed: oi %d != bin_size %d", 125 fatal("buffer_put_bignum2: BN_bn2bin() failed: "
116 oi, bytes); 126 "oi %d != bin_size %d", oi, bytes);
117 hasnohigh = (buf[1] & 0x80) ? 0 : 1; 127 hasnohigh = (buf[1] & 0x80) ? 0 : 1;
118 if (value->neg) {
119 /**XXX should be two's-complement */
120 int i, carry;
121 u_char *uc = buf;
122 logit("negativ!");
123 for (i = bytes-1, carry = 1; i>=0; i--) {
124 uc[i] ^= 0xff;
125 if (carry)
126 carry = !++uc[i];
127 }
128 }
129 buffer_put_string(buffer, buf+hasnohigh, bytes-hasnohigh); 128 buffer_put_string(buffer, buf+hasnohigh, bytes-hasnohigh);
130 memset(buf, 0, bytes); 129 memset(buf, 0, bytes);
131 xfree(buf); 130 xfree(buf);
132} 131}
133 132
134/* XXX does not handle negative BNs */
135void 133void
136buffer_get_bignum2(Buffer *buffer, BIGNUM *value) 134buffer_get_bignum2(Buffer *buffer, BIGNUM *value)
137{ 135{
138 u_int len; 136 u_int len;
139 u_char *bin = buffer_get_string(buffer, &len); 137 u_char *bin = buffer_get_string(buffer, &len);
140 138
139 if (len > 0 && (bin[0] & 0x80))
140 fatal("buffer_get_bignum2: negative numbers not supported");
141 if (len > 8 * 1024) 141 if (len > 8 * 1024)
142 fatal("buffer_get_bignum2: cannot handle BN of size %d", len); 142 fatal("buffer_get_bignum2: cannot handle BN of size %d", len);
143 BN_bin2bn(bin, len, value); 143 BN_bin2bn(bin, len, value);
144 xfree(bin); 144 xfree(bin);
145} 145}
146
146/* 147/*
147 * Returns integers from the buffer (msb first). 148 * Returns integers from the buffer (msb first).
148 */ 149 */