static d0_bignum_t *zero, *one, *four, *temp0, *temp1, *temp2, *temp3, *temp4;
-void d0_blind_id_INITIALIZE()
+void d0_blind_id_INITIALIZE(void)
{
d0_bignum_INITIALIZE();
CHECK_ASSIGN(zero, d0_bignum_int(zero, 0));
;
}
-void d0_blind_id_SHUTDOWN()
+void d0_blind_id_SHUTDOWN(void)
{
d0_bignum_free(zero);
d0_bignum_free(one);
// uses temp0 to temp4
int fail = 0;
int gcdfail = 0;
- if(size < 16)
- size = 16;
int pb = (size + 1)/2;
int qb = size - pb;
+ if(pb < 8)
+ pb = 8;
+ if(qb < 8)
+ qb = 8;
for (;;)
{
CHECK(d0_bignum_rand_bit_exact(temp0, pb));
}
#define USING(x) if(!(ctx->x)) return 0
-#define WRITING(x,f) if(ctx->x) { f(ctx->x); ctx->x = NULL; }
#define REPLACING(x)
WARN_UNUSED_RESULT BOOL d0_blind_id_write_private_keys(d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen)
{
+ d0_iobuf_t *out;
+
USING(rsa_n); USING(rsa_e); USING(rsa_d);
- d0_iobuf_t *out = d0_iobuf_open_write(outbuf, *outbuflen);
+ out = d0_iobuf_open_write(outbuf, *outbuflen);
CHECK(d0_iobuf_write_bignum(out, ctx->schnorr_G));
CHECK(d0_iobuf_write_bignum(out, ctx->rsa_n));
CHECK(d0_iobuf_write_bignum(out, ctx->rsa_e));
WARN_UNUSED_RESULT BOOL d0_blind_id_write_public_keys(d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen)
{
+ d0_iobuf_t *out;
+
USING(rsa_n); USING(rsa_e); USING(rsa_d);
- d0_iobuf_t *out = d0_iobuf_open_write(outbuf, *outbuflen);
+ out = d0_iobuf_open_write(outbuf, *outbuflen);
CHECK(d0_iobuf_write_bignum(out, ctx->schnorr_G));
CHECK(d0_iobuf_write_bignum(out, ctx->rsa_n));
CHECK(d0_iobuf_write_bignum(out, ctx->rsa_e));
WARN_UNUSED_RESULT BOOL d0_blind_id_generate_private_id_request(d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen)
{
+ d0_iobuf_t *out;
+
// temps: temp0 temp1
USING(rsa_n); USING(rsa_e); USING(schnorr_4_to_s);
REPLACING(rn);
- d0_iobuf_t *out = d0_iobuf_open_write(outbuf, *outbuflen);
+ out = d0_iobuf_open_write(outbuf, *outbuflen);
CHECK_ASSIGN(ctx->rn, d0_bignum_rand_bit_atmost(ctx->rn, d0_bignum_size(ctx->rsa_n)));
CHECK(d0_bignum_mod_pow(temp0, ctx->rn, ctx->rsa_e, ctx->rsa_n));
WARN_UNUSED_RESULT BOOL d0_blind_id_answer_private_id_request(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen, char *outbuf, size_t *outbuflen)
{
+ d0_iobuf_t *in;
+ d0_iobuf_t *out;
+
// temps: temp0 temp1
USING(rsa_d); USING(rsa_n);
- d0_iobuf_t *in = d0_iobuf_open_read(inbuf, inbuflen);
- d0_iobuf_t *out = d0_iobuf_open_write(outbuf, *outbuflen);
+ in = d0_iobuf_open_read(inbuf, inbuflen);
+ out = d0_iobuf_open_write(outbuf, *outbuflen);
CHECK(d0_iobuf_read_bignum(in, temp0));
CHECK(d0_bignum_mod_pow(temp1, temp0, ctx->rsa_d, ctx->rsa_n));
WARN_UNUSED_RESULT BOOL d0_blind_id_finish_private_id_request(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen)
{
+ d0_iobuf_t *in;
+
// temps: temp0 temp1
USING(rn); USING(rsa_n);
REPLACING(schnorr_4_to_s_signature);
- d0_iobuf_t *in = d0_iobuf_open_read(inbuf, inbuflen);
+ in = d0_iobuf_open_read(inbuf, inbuflen);
CHECK(d0_iobuf_read_bignum(in, temp0));
CHECK(d0_bignum_mod_inv(temp1, ctx->rn, ctx->rsa_n));
WARN_UNUSED_RESULT BOOL d0_blind_id_read_private_id(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen)
{
+ d0_iobuf_t *in;
+
REPLACING(schnorr_s); REPLACING(schnorr_4_to_s); REPLACING(schnorr_4_to_s_signature);
- d0_iobuf_t *in = d0_iobuf_open_read(inbuf, inbuflen);
+ in = d0_iobuf_open_read(inbuf, inbuflen);
CHECK_ASSIGN(ctx->schnorr_s, d0_iobuf_read_bignum(in, ctx->schnorr_s));
CHECK_ASSIGN(ctx->schnorr_4_to_s, d0_iobuf_read_bignum(in, ctx->schnorr_4_to_s));
WARN_UNUSED_RESULT BOOL d0_blind_id_read_public_id(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen)
{
+ d0_iobuf_t *in;
+
REPLACING(schnorr_4_to_s); REPLACING(schnorr_4_to_s_signature);
- d0_iobuf_t *in = d0_iobuf_open_read(inbuf, inbuflen);
+ in = d0_iobuf_open_read(inbuf, inbuflen);
CHECK_ASSIGN(ctx->schnorr_4_to_s, d0_iobuf_read_bignum(in, ctx->schnorr_4_to_s));
CHECK_ASSIGN(ctx->schnorr_4_to_s_signature, d0_iobuf_read_bignum(in, ctx->schnorr_4_to_s_signature));
WARN_UNUSED_RESULT BOOL d0_blind_id_write_private_id(d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen)
{
+ d0_iobuf_t *out;
+
USING(schnorr_s); USING(schnorr_4_to_s); USING(schnorr_4_to_s_signature);
- d0_iobuf_t *out = d0_iobuf_open_write(outbuf, *outbuflen);
+ out = d0_iobuf_open_write(outbuf, *outbuflen);
CHECK(d0_iobuf_write_bignum(out, ctx->schnorr_s));
CHECK(d0_iobuf_write_bignum(out, ctx->schnorr_4_to_s));
WARN_UNUSED_RESULT BOOL d0_blind_id_write_public_id(d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen)
{
+ d0_iobuf_t *out;
+
USING(schnorr_4_to_s); USING(schnorr_4_to_s_signature);
- d0_iobuf_t *out = d0_iobuf_open_write(outbuf, *outbuflen);
+ out = d0_iobuf_open_write(outbuf, *outbuflen);
CHECK(d0_iobuf_write_bignum(out, ctx->schnorr_4_to_s));
CHECK(d0_iobuf_write_bignum(out, ctx->schnorr_4_to_s_signature));
// first run: send 4^s, 4^s signature
// 1. get random r, send HASH(4^r)
{
+ d0_iobuf_t *out;
+ unsigned char convbuf[1024];
+ d0_iobuf_t *conv;
+ size_t sz;
+
if(is_first)
{
USING(schnorr_4_to_s); USING(schnorr_4_to_s_signature);
USING(schnorr_G);
REPLACING(r);
- d0_iobuf_t *out = d0_iobuf_open_write(outbuf, *outbuflen);
+ out = d0_iobuf_open_write(outbuf, *outbuflen);
if(is_first)
{
CHECK(d0_bignum_mod_pow(temp0, four, ctx->r, ctx->schnorr_G));
// hash it, hash it, everybody hash it
- unsigned char convbuf[1024];
- d0_iobuf_t *conv = d0_iobuf_open_write(convbuf, sizeof(convbuf));
- size_t sz;
+ conv = d0_iobuf_open_write(convbuf, sizeof(convbuf));
CHECK(d0_iobuf_write_bignum(conv, temp0));
CHECK(d0_iobuf_write_packet(conv, msg, msglen));
CHECK(d0_iobuf_write_bignum(conv, temp0));
// 2. save HASH(4^r)
// 3. send challenge e of SCHNORR_BITS
{
+ d0_iobuf_t *in;
+ d0_iobuf_t *out;
+
if(is_first)
{
REPLACING(schnorr_4_to_s); REPLACING(k); REPLACING(schnorr_4_to_s_signature);
USING(rsa_e); USING(rsa_n);
REPLACING(e); REPLACING(msg); REPLACING(msglen);
- d0_iobuf_t *in = d0_iobuf_open_read(inbuf, inbuflen);
- d0_iobuf_t *out = d0_iobuf_open_write(outbuf, *outbuflen);
+ in = d0_iobuf_open_read(inbuf, inbuflen);
+ out = d0_iobuf_open_write(outbuf, *outbuflen);
if(is_first)
{
// 1. read challenge e of SCHNORR_BITS
// 2. reply with r + s * e mod order
{
+ d0_iobuf_t *in;
+ d0_iobuf_t *out;
+
// temps: 0 order, 1 prod, 2 y, 3 e
USING(schnorr_G); USING(schnorr_s); USING(r);
- d0_iobuf_t *in = d0_iobuf_open_read(inbuf, inbuflen);
- d0_iobuf_t *out = d0_iobuf_open_write(outbuf, *outbuflen);
+ in = d0_iobuf_open_read(inbuf, inbuflen);
+ out = d0_iobuf_open_write(outbuf, *outbuflen);
CHECK(d0_iobuf_read_bignum(in, temp3));
// TODO check if >= 2^SCHNORR_BITS or < 0, if yes, then fail (needed for zero knowledge)
// 2. verify: g^y (g^s)^-e = g^(r+s*e-s*e) = g^r
// (check using H(g^r) which we know)
{
+ d0_iobuf_t *in;
+ unsigned char convbuf[1024];
+ d0_iobuf_t *conv;
+ size_t sz;
+
// temps: 0 y 1 order
USING(e); USING(schnorr_G);
- d0_iobuf_t *in = d0_iobuf_open_read(inbuf, inbuflen);
+ in = d0_iobuf_open_read(inbuf, inbuflen);
*msglen = -1;
CHECK(d0_dl_get_order(temp1, ctx->schnorr_G));
// hash must be equal to xnbh
// hash it, hash it, everybody hash it
- unsigned char convbuf[1024];
- d0_iobuf_t *conv = d0_iobuf_open_write(convbuf, sizeof(convbuf));
- size_t sz;
+ conv = d0_iobuf_open_write(convbuf, sizeof(convbuf));
CHECK(d0_iobuf_write_bignum(conv, temp3));
CHECK(d0_iobuf_write_packet(conv, ctx->msg, ctx->msglen));
CHECK(d0_iobuf_write_bignum(conv, temp3));
WARN_UNUSED_RESULT BOOL d0_blind_id_fingerprint64_public_id(d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen)
{
- USING(schnorr_4_to_s);
-
+ d0_iobuf_t *out;
+ d0_iobuf_t *conv;
static unsigned char convbuf[1024];
- d0_iobuf_t *out = d0_iobuf_open_write(outbuf, *outbuflen);
- d0_iobuf_t *conv = d0_iobuf_open_write(convbuf, sizeof(convbuf));
+ size_t sz, n;
+
+ USING(schnorr_4_to_s);
- size_t n, sz;
+ out = d0_iobuf_open_write(outbuf, *outbuflen);
+ conv = d0_iobuf_open_write(convbuf, sizeof(convbuf));
CHECK(d0_iobuf_write_bignum(conv, ctx->schnorr_4_to_s));
CHECK(d0_iobuf_close(conv, &sz));
return 0;
}
-d0_blind_id_t *d0_blind_id_new()
+d0_blind_id_t *d0_blind_id_new(void)
{
d0_blind_id_t *b = d0_malloc(sizeof(d0_blind_id_t));
memset(b, 0, sizeof(*b));