summaryrefslogtreecommitdiffstats
path: root/crypto/openssh/bufaux.c
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2014-01-31 13:12:02 +0000
committerdes <des@FreeBSD.org>2014-01-31 13:12:02 +0000
commit7573e91b127f1c198210fd345d3ca198b598cfc6 (patch)
treed32fb61cec38c52314210c3459fd436685dacdba /crypto/openssh/bufaux.c
parentc692973c992c321bb10e631f572fab1500ae5b0e (diff)
parent45d0197dd79eceffb5bbc29f75199eb09af5a5f9 (diff)
downloadFreeBSD-src-7573e91b127f1c198210fd345d3ca198b598cfc6.zip
FreeBSD-src-7573e91b127f1c198210fd345d3ca198b598cfc6.tar.gz
Upgrade to OpenSSH 6.5p1.
Diffstat (limited to 'crypto/openssh/bufaux.c')
-rw-r--r--crypto/openssh/bufaux.c76
1 files changed, 75 insertions, 1 deletions
diff --git a/crypto/openssh/bufaux.c b/crypto/openssh/bufaux.c
index de5b3ca..9401fe1 100644
--- a/crypto/openssh/bufaux.c
+++ b/crypto/openssh/bufaux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bufaux.c,v 1.52 2013/07/12 00:19:58 djm Exp $ */
+/* $OpenBSD: bufaux.c,v 1.54 2014/01/12 08:13:13 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -45,6 +45,7 @@
#include <string.h>
#include <stdarg.h>
+#include <stdlib.h>
#include "xmalloc.h"
#include "buffer.h"
@@ -314,3 +315,76 @@ buffer_put_char(Buffer *buffer, int value)
buffer_append(buffer, &ch, 1);
}
+
+/* Pseudo bignum functions */
+
+void *
+buffer_get_bignum2_as_string_ret(Buffer *buffer, u_int *length_ptr)
+{
+ u_int len;
+ u_char *bin, *p, *ret;
+
+ if ((p = bin = buffer_get_string_ret(buffer, &len)) == NULL) {
+ error("%s: invalid bignum", __func__);
+ return NULL;
+ }
+
+ if (len > 0 && (bin[0] & 0x80)) {
+ error("%s: negative numbers not supported", __func__);
+ free(bin);
+ return NULL;
+ }
+ if (len > 8 * 1024) {
+ error("%s: cannot handle BN of size %d", __func__, len);
+ free(bin);
+ return NULL;
+ }
+ /* Skip zero prefix on numbers with the MSB set */
+ if (len > 1 && bin[0] == 0x00 && (bin[1] & 0x80) != 0) {
+ p++;
+ len--;
+ }
+ ret = xmalloc(len);
+ memcpy(ret, p, len);
+ memset(p, '\0', len);
+ free(bin);
+ return ret;
+}
+
+void *
+buffer_get_bignum2_as_string(Buffer *buffer, u_int *l)
+{
+ void *ret = buffer_get_bignum2_as_string_ret(buffer, l);
+
+ if (ret == NULL)
+ fatal("%s: buffer error", __func__);
+ return ret;
+}
+
+/*
+ * Stores a string using the bignum encoding rules (\0 pad if MSB set).
+ */
+void
+buffer_put_bignum2_from_string(Buffer *buffer, const u_char *s, u_int l)
+{
+ u_char *buf, *p;
+ int pad = 0;
+
+ if (l > 8 * 1024)
+ fatal("%s: length %u too long", __func__, l);
+ p = buf = xmalloc(l + 1);
+ /*
+ * If most significant bit is set then prepend a zero byte to
+ * avoid interpretation as a negative number.
+ */
+ if (l > 0 && (s[0] & 0x80) != 0) {
+ *p++ = '\0';
+ pad = 1;
+ }
+ memcpy(p, s, l);
+ buffer_put_string(buffer, buf, l + pad);
+ memset(buf, '\0', l + pad);
+ free(buf);
+}
+
+
OpenPOWER on IntegriCloud