]> git.xonotic.org Git - xonotic/d0_blind_id.git/commitdiff
version 0.3: allow variable length for sign data buffer xonotic-v0.5.0
authorRudolf Polzer <divVerent@xonotic.org>
Thu, 18 Aug 2011 09:57:29 +0000 (11:57 +0200)
committerRudolf Polzer <divVerent@xonotic.org>
Thu, 18 Aug 2011 09:57:29 +0000 (11:57 +0200)
Makefile.am
configure.ac
d0_blind_id.c
d0_iobuf.c
d0_iobuf.h

index 2912c1b807f1c6be3cb54abf1bd373d922fa028e..aa3e6e5625e34cc79614b5b49234d25665ddafc7 100644 (file)
@@ -23,7 +23,7 @@ else
 libd0_blind_id_la_SOURCES += d0_bignum-gmp.c
 endif
 endif
-libd0_blind_id_la_LDFLAGS = -versioninfo 4:0:4
+libd0_blind_id_la_LDFLAGS = -versioninfo 5:0:5
 libd0_blind_id_la_CFLAGS = -fvisibility=hidden -Wold-style-definition -Wstrict-prototypes -Wsign-compare -Wdeclaration-after-statement
 library_includedir = $(includedir)/d0_blind_id
 library_include_HEADERS = d0_blind_id.h d0.h
index 46853a16748fe1d77471804a05f22486fd851ccc..b5d4e11ebac567cd265832f45e5684f96c8a4788 100644 (file)
@@ -1,4 +1,4 @@
-AC_INIT([d0_blind_id], [0.2], [divVerent@xonotic.org])
+AC_INIT([d0_blind_id], [0.3], [divVerent@xonotic.org])
 AC_CONFIG_MACRO_DIR([m4])
 AM_INIT_AUTOMAKE([-Wall foreign])
 AC_PROG_CC
index a02aaa7c7cde0a8bce248f7ffaac7ed323f7d950..8852402cfe544e317bdd4c429b0ee3c192f4d8cc 100644 (file)
@@ -1052,8 +1052,8 @@ fail:
 D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_sign_with_private_id_sign_internal(d0_blind_id_t *ctx, D0_BOOL is_first, D0_BOOL send_modulus, D0_BOOL with_msg, const char *message, size_t msglen, char *outbuf, size_t *outbuflen)
 {
        d0_iobuf_t *out = NULL;
-       static unsigned char convbuf[1024];
-       static unsigned char shabuf[1024];
+       unsigned char *convbuf = NULL;
+       static unsigned char shabuf[2048];
        d0_iobuf_t *conv = NULL;
        size_t sz = 0;
 
@@ -1083,12 +1083,14 @@ D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_sign_with_private_id_sign_internal(d0_
        CHECK(d0_bignum_mod_pow(temp1, four, ctx->r, ctx->schnorr_G));
 
        // hash it, hash it, everybody hash it
-       conv = d0_iobuf_open_write(convbuf, sizeof(convbuf));
+       conv = d0_iobuf_open_write_p((void **) &convbuf, 0);
        CHECK(d0_iobuf_write_packet(conv, message, msglen));
        CHECK(d0_iobuf_write_bignum(conv, temp1));
        d0_iobuf_close(conv, &sz);
        conv = NULL;
        CHECK(d0_longhash_destructive(convbuf, sz, shabuf, (d0_bignum_size(temp0) + 7) / 8));
+       d0_free(convbuf);
+       convbuf = NULL;
        CHECK(d0_bignum_import_unsigned(temp2, shabuf, (d0_bignum_size(temp0) + 7) / 8));
        CHECK(d0_iobuf_write_bignum(out, temp2));
 
@@ -1124,7 +1126,7 @@ D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_sign_with_private_id_verify_internal(d
 {
        d0_iobuf_t *in = NULL;
        d0_iobuf_t *conv = NULL;
-       static unsigned char convbuf[2048];
+       unsigned char *convbuf = NULL;
        static unsigned char shabuf[2048];
        size_t sz;
 
@@ -1202,12 +1204,14 @@ D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_sign_with_private_id_verify_internal(d
        CHECK_ASSIGN(temp3, d0_bignum_mod_mul(temp3, temp1, temp2, ctx->schnorr_G)); // temp3 now is g^r
 
        // hash it, hash it, everybody hash it
-       conv = d0_iobuf_open_write(convbuf, sizeof(convbuf));
+       conv = d0_iobuf_open_write_p((void **) &convbuf, 0);
        CHECK(d0_iobuf_write_packet(conv, msg, *msglen));
        CHECK(d0_iobuf_write_bignum(conv, temp3));
        d0_iobuf_close(conv, &sz);
        conv = NULL;
        CHECK(d0_longhash_destructive(convbuf, sz, shabuf, (d0_bignum_size(temp4) + 7) / 8));
+       d0_free(convbuf);
+       convbuf = NULL;
        CHECK(d0_bignum_import_unsigned(temp1, shabuf, (d0_bignum_size(temp4) + 7) / 8));
 
        // verify signature
index ce8e58d66912c6a82c6d17d036dad57c5cf15231..4fa37e2e1455de52a892fc8acbee4e228a010e44 100644 (file)
@@ -41,8 +41,10 @@ struct d0_iobuf_s
 {
        const unsigned char *inbuf;
        unsigned char *outbuf;
+       unsigned char **outbufp;
        size_t inpos, outpos, inbuflen, outbuflen;
        D0_BOOL ok;
+       D0_BOOL pdata;
 };
 
 d0_iobuf_t *d0_iobuf_open_read(const void *buf, size_t len)
@@ -50,6 +52,7 @@ d0_iobuf_t *d0_iobuf_open_read(const void *buf, size_t len)
        d0_iobuf_t *b = d0_malloc(sizeof(d0_iobuf_t));
        b->inbuf = (const unsigned char *) buf;
        b->outbuf = NULL;
+       b->outbufp = NULL;
        b->inpos = b->outpos = 0;
        b->inbuflen = len;
        b->outbuflen = 0;
@@ -62,8 +65,22 @@ d0_iobuf_t *d0_iobuf_open_write(void *buf, size_t len)
        d0_iobuf_t *b = d0_malloc(sizeof(d0_iobuf_t));
        b->inbuf = (const unsigned char *) buf;
        b->outbuf = (unsigned char *) buf;
+       b->outbufp = NULL;
        b->inpos = b->outpos = 0;
-       b->inbuflen = len;
+       b->inbuflen = 0;
+       b->outbuflen = len;
+       b->ok = 1;
+       return b;
+}
+
+d0_iobuf_t *d0_iobuf_open_write_p(void **buf, size_t len)
+{
+       d0_iobuf_t *b = d0_malloc(sizeof(d0_iobuf_t));
+       b->inbuf = (const unsigned char *) *buf;
+       b->outbuf = (unsigned char *) *buf;
+       b->outbufp = (unsigned char **) buf;
+       b->inpos = b->outpos = 0;
+       b->inbuflen = 0;
        b->outbuflen = len;
        b->ok = 1;
        return b;
@@ -81,6 +98,27 @@ D0_BOOL d0_iobuf_close(d0_iobuf_t *buf, size_t *len)
 size_t d0_iobuf_write_raw(d0_iobuf_t *buf, const void *s, size_t n)
 {
        size_t nreal = n;
+
+       // if packet doesn't fit, expand buffer
+       if(buf->outbufp && nreal > buf->outbuflen - buf->outpos)
+       {
+               size_t newsize = 1;
+               while(nreal + buf->outpos > newsize)
+                       newsize <<= 1;
+
+               {
+                       char *newbuf = d0_malloc(newsize);
+                       if(buf->outbuf)
+                       {
+                               memcpy(newbuf, buf->outbuf, buf->outbuflen);
+                               d0_free(buf->outbuf);
+                       }
+                       buf->outbuf = newbuf;
+                       *buf->outbufp = newbuf;
+                       buf->outbuflen = newsize;
+               }
+       }
+
        if(nreal > buf->outbuflen - buf->outpos)
        {
                buf->ok = 0;
@@ -88,6 +126,7 @@ size_t d0_iobuf_write_raw(d0_iobuf_t *buf, const void *s, size_t n)
        }
        memcpy(buf->outbuf + buf->outpos, s, nreal);
        buf->outpos += nreal;
+       buf->inbuflen = buf->outpos;
        return nreal;
 }
 
index d774e67ac33949acf4e9e0037fdc8de5875a69ab..9705e2c9ae812b7e2560ec0d2b60c7223a2a44b4 100644 (file)
@@ -40,8 +40,9 @@
 
 typedef struct d0_iobuf_s d0_iobuf_t;
 
-D0_WARN_UNUSED_RESULT d0_iobuf_t *d0_iobuf_open_read(const void *buf, size_t len); // note: can read AND write!
+D0_WARN_UNUSED_RESULT d0_iobuf_t *d0_iobuf_open_read(const void *buf, size_t len); // note: can read
 D0_WARN_UNUSED_RESULT d0_iobuf_t *d0_iobuf_open_write(void *buf, size_t len); // note: can read AND write!
+D0_WARN_UNUSED_RESULT d0_iobuf_t *d0_iobuf_open_write_p(void **buf, size_t len); // note: can read AND write!
 D0_WARN_UNUSED_RESULT D0_BOOL d0_iobuf_conv_base64_in(d0_iobuf_t *buf);
 D0_WARN_UNUSED_RESULT D0_BOOL d0_iobuf_conv_base64_out(d0_iobuf_t *buf);
 D0_BOOL d0_iobuf_close(d0_iobuf_t *buf, size_t *len); // don't warn