]> git.rm.cloudns.org Git - xonotic/d0_blind_id.git/commitdiff
let's use more strict warnings, and help Visual Studio
authorRudolf Polzer <divverent@alientrap.org>
Sat, 24 Apr 2010 20:08:23 +0000 (22:08 +0200)
committerRudolf Polzer <divverent@alientrap.org>
Sat, 24 Apr 2010 20:08:23 +0000 (22:08 +0200)
Makefile.am
d0_bignum-gmp.c
d0_bignum.h
d0_blind_id.c
d0_blind_id.h

index 3d12334c290797b3e9d826d30e90bd9a9772e476..a0c7d26b0ca35c44f607420f47a06f1a309e9f84 100644 (file)
@@ -5,7 +5,7 @@ blind_id_LDADD = libblind_id.la
 lib_LTLIBRARIES = libblind_id.la
 libblind_id_la_SOURCES = d0_bignum-gmp.c d0_blind_id.c d0.c d0_iobuf.c sha1.c
 libblind_id_la_LDFLAGS = -versioninfo 0:0:0
-libblind_id_la_CFLAGS = -fvisibility=hidden
+libblind_id_la_CFLAGS = -fvisibility=hidden -Wold-style-definition -Wstrict-prototypes -Wsign-compare -Wdeclaration-after-statement
 # versioninfo:
 #   - compatible interface change: c:r:a -> c+1:0:a+1
 #   - incompatible interface change: c:r:a -> c+1:0:0
index a66096dff4b910835e52ae3b9ac1131030a7653f..93bf0f72154d3c5c5da75de81c58344eb7794434 100644 (file)
@@ -31,7 +31,7 @@ static d0_bignum_t temp;
 
 #include <time.h>
 #include <stdio.h>
-void d0_bignum_INITIALIZE()
+void d0_bignum_INITIALIZE(void)
 {
        FILE *f;
        d0_bignum_init(&temp);
@@ -51,7 +51,7 @@ void d0_bignum_INITIALIZE()
        }
 }
 
-void d0_bignum_SHUTDOWN()
+void d0_bignum_SHUTDOWN(void)
 {
        d0_bignum_clear(&temp);
        gmp_randclear(RANDSTATE);
@@ -94,7 +94,7 @@ d0_bignum_t *d0_iobuf_read_bignum(d0_iobuf_t *buf, d0_bignum_t *bignum)
        return bignum;
 }
 
-d0_bignum_t *d0_bignum_new()
+d0_bignum_t *d0_bignum_new(void)
 {
        d0_bignum_t *b = d0_malloc(sizeof(d0_bignum_t));
        mpz_init(b->z);
index 5f78c4967388f6f0fe786961795cf86908fe9b2d..26fafc3e56dfdbd47c3f93753b629e3d70045dd5 100644 (file)
@@ -9,10 +9,10 @@ typedef struct d0_bignum_s d0_bignum_t;
 WARN_UNUSED_RESULT BOOL d0_iobuf_write_bignum(d0_iobuf_t *buf, const d0_bignum_t *bignum);
 WARN_UNUSED_RESULT d0_bignum_t *d0_iobuf_read_bignum(d0_iobuf_t *buf, d0_bignum_t *bignum);
 
-void d0_bignum_INITIALIZE();
-void d0_bignum_SHUTDOWN();
+void d0_bignum_INITIALIZE(void);
+void d0_bignum_SHUTDOWN(void);
 
-WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_new();
+WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_new(void);
 void d0_bignum_free(d0_bignum_t *a);
 void d0_bignum_init(d0_bignum_t *b);
 void d0_bignum_clear(d0_bignum_t *a);
index 617b473f4d4fb6edd5c3368fa5039569dc98ed18..0b4d99ff4fad4816223bd84d3ed58566626d9f8b 100644 (file)
@@ -67,7 +67,7 @@ struct d0_blind_id_s
 
 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));
@@ -82,7 +82,7 @@ fail:
        ;
 }
 
-void d0_blind_id_SHUTDOWN()
+void d0_blind_id_SHUTDOWN(void)
 {
        d0_bignum_free(zero);
        d0_bignum_free(one);
@@ -141,10 +141,12 @@ BOOL d0_rsa_generate_key(size_t size, const d0_bignum_t *e, d0_bignum_t *d, d0_b
        // 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));
@@ -265,14 +267,15 @@ fail:
 }
 
 #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));
@@ -286,9 +289,11 @@ fail:
 
 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));
@@ -317,11 +322,13 @@ fail:
 
 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));
@@ -336,11 +343,14 @@ fail:
 
 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));
@@ -357,11 +367,13 @@ fail:
 
 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));
@@ -376,9 +388,11 @@ fail:
 
 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));
@@ -393,9 +407,11 @@ fail:
 
 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));
@@ -409,9 +425,11 @@ fail:
 
 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));
@@ -426,9 +444,11 @@ fail:
 
 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));
@@ -445,6 +465,11 @@ WARN_UNUSED_RESULT BOOL d0_blind_id_authenticate_with_private_id_start(d0_blind_
 //   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);
@@ -452,7 +477,7 @@ WARN_UNUSED_RESULT BOOL d0_blind_id_authenticate_with_private_id_start(d0_blind_
        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)
        {
@@ -468,9 +493,7 @@ WARN_UNUSED_RESULT BOOL d0_blind_id_authenticate_with_private_id_start(d0_blind_
        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));
@@ -492,6 +515,9 @@ WARN_UNUSED_RESULT BOOL d0_blind_id_authenticate_with_private_id_challenge(d0_bl
 //   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);
@@ -504,8 +530,8 @@ WARN_UNUSED_RESULT BOOL d0_blind_id_authenticate_with_private_id_challenge(d0_bl
        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)
        {
@@ -548,11 +574,14 @@ WARN_UNUSED_RESULT BOOL d0_blind_id_authenticate_with_private_id_response(d0_bli
 //   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)
@@ -580,10 +609,15 @@ WARN_UNUSED_RESULT BOOL d0_blind_id_authenticate_with_private_id_verify(d0_blind
 //   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));
@@ -600,9 +634,7 @@ WARN_UNUSED_RESULT BOOL d0_blind_id_authenticate_with_private_id_verify(d0_blind
        // 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));
@@ -630,13 +662,15 @@ fail:
 
 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));
@@ -660,7 +694,7 @@ fail:
        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));
index 485d1a9264fb420984f66b0c30068a7185457d11..4877c93229b9b70ccf84d8cde6376a966b0b54d1 100644 (file)
@@ -5,7 +5,7 @@
 
 typedef struct d0_blind_id_s d0_blind_id_t;
 
-EXPORT WARN_UNUSED_RESULT d0_blind_id_t *d0_blind_id_new();
+EXPORT WARN_UNUSED_RESULT d0_blind_id_t *d0_blind_id_new(void);
 EXPORT void d0_blind_id_free(d0_blind_id_t *a);
 EXPORT void d0_blind_id_clear(d0_blind_id_t *ctx);
 EXPORT void d0_blind_id_copy(d0_blind_id_t *ctx, const d0_blind_id_t *src);
@@ -27,8 +27,8 @@ EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_authenticate_with_private_id_challeng
 EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_authenticate_with_private_id_response(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen, char *outbuf, size_t *outbuflen);
 EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_authenticate_with_private_id_verify(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen, char *msg, ssize_t *msglen);
 EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_fingerprint64_public_id(d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen);
-EXPORT 
-EXPORT void d0_blind_id_INITIALIZE();
-EXPORT void d0_blind_id_SHUTDOWN();
+
+EXPORT void d0_blind_id_INITIALIZE(void);
+EXPORT void d0_blind_id_SHUTDOWN(void);
 
 #endif