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
-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
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;
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));
{
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;
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
{
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)
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;
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;
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;
}
memcpy(buf->outbuf + buf->outpos, s, nreal);
buf->outpos += nreal;
+ buf->inbuflen = buf->outpos;
return nreal;
}
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