From: Rudolf Polzer Date: Mon, 6 Sep 2010 13:56:49 +0000 (+0200) Subject: tag the macro identifiers (like BOOL, EXPORT) with a prefix D0_ to not clash with... X-Git-Tag: xonotic-v0.1.0preview~14 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=faa60e62ea00fc1a2c9d176ca5d69253466452ac;p=xonotic%2Fd0_blind_id.git tag the macro identifiers (like BOOL, EXPORT) with a prefix D0_ to not clash with --- diff --git a/d0.h b/d0.h index 53860da..8bcedf6 100644 --- a/d0.h +++ b/d0.h @@ -38,9 +38,9 @@ #include // size_t -#define EXPORT __attribute__((__visibility__("default"))) -#define WARN_UNUSED_RESULT __attribute__((warn_unused_result)) -#define BOOL int +#define D0_EXPORT __attribute__((__visibility__("default"))) +#define D0_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) +#define D0_BOOL int extern void *(*d0_malloc)(size_t len); extern void (*d0_free)(void *p); diff --git a/d0_bignum-gmp.c b/d0_bignum-gmp.c index eabbdfb..45f46a2 100644 --- a/d0_bignum-gmp.c +++ b/d0_bignum-gmp.c @@ -62,10 +62,10 @@ static d0_bignum_t temp; #include #include -WARN_UNUSED_RESULT BOOL d0_bignum_INITIALIZE(void) +D0_WARN_UNUSED_RESULT D0_BOOL d0_bignum_INITIALIZE(void) { FILE *f; - BOOL ret = 1; + D0_BOOL ret = 1; unsigned char buf[256]; d0_bignum_init(&temp); gmp_randinit_mt(RANDSTATE); @@ -131,7 +131,7 @@ void d0_bignum_SHUTDOWN(void) gmp_randclear(RANDSTATE); } -BOOL d0_iobuf_write_bignum(d0_iobuf_t *buf, const d0_bignum_t *bignum) +D0_BOOL d0_iobuf_write_bignum(d0_iobuf_t *buf, const d0_bignum_t *bignum) { static unsigned char numbuf[65536]; size_t count = 0; @@ -377,7 +377,7 @@ d0_bignum_t *d0_bignum_mod_pow(d0_bignum_t *r, const d0_bignum_t *a, const d0_bi return r; } -BOOL d0_bignum_mod_inv(d0_bignum_t *r, const d0_bignum_t *a, const d0_bignum_t *m) +D0_BOOL d0_bignum_mod_inv(d0_bignum_t *r, const d0_bignum_t *a, const d0_bignum_t *m) { // here, r MUST be set, as otherwise we cannot return error state! return mpz_invert(r->z, a->z, m->z); diff --git a/d0_bignum-openssl.c b/d0_bignum-openssl.c index c831690..b4fc873 100644 --- a/d0_bignum-openssl.c +++ b/d0_bignum-openssl.c @@ -57,7 +57,7 @@ static BN_CTX *ctx; #include #include -WARN_UNUSED_RESULT BOOL d0_bignum_INITIALIZE(void) +D0_WARN_UNUSED_RESULT D0_BOOL d0_bignum_INITIALIZE(void) { ctx = BN_CTX_new(); d0_bignum_init(&temp); @@ -71,7 +71,7 @@ void d0_bignum_SHUTDOWN(void) ctx = NULL; } -BOOL d0_iobuf_write_bignum(d0_iobuf_t *buf, const d0_bignum_t *bignum) +D0_BOOL d0_iobuf_write_bignum(d0_iobuf_t *buf, const d0_bignum_t *bignum) { static unsigned char numbuf[65536]; size_t count = 0; @@ -301,7 +301,7 @@ d0_bignum_t *d0_bignum_mod_pow(d0_bignum_t *r, const d0_bignum_t *a, const d0_bi return r; } -BOOL d0_bignum_mod_inv(d0_bignum_t *r, const d0_bignum_t *a, const d0_bignum_t *m) +D0_BOOL d0_bignum_mod_inv(d0_bignum_t *r, const d0_bignum_t *a, const d0_bignum_t *m) { // here, r MUST be set, as otherwise we cannot return error state! return !!BN_mod_inverse(&r->z, &a->z, &m->z, ctx); diff --git a/d0_bignum.h b/d0_bignum.h index 7128eae..9a23979 100644 --- a/d0_bignum.h +++ b/d0_bignum.h @@ -41,40 +41,40 @@ 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); // byte 0: 01=+ 11=- 00=0, rest = big endian number -WARN_UNUSED_RESULT d0_bignum_t *d0_iobuf_read_bignum(d0_iobuf_t *buf, d0_bignum_t *bignum); -WARN_UNUSED_RESULT ssize_t d0_bignum_export_unsigned(const d0_bignum_t *bignum, void *buf, size_t bufsize); // big endian, return value = number of significant bytes (or -1 on error) -WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_import_unsigned(d0_bignum_t *bignum, const void *buf, size_t bufsize); +D0_WARN_UNUSED_RESULT D0_BOOL d0_iobuf_write_bignum(d0_iobuf_t *buf, const d0_bignum_t *bignum); // byte 0: 01=+ 11=- 00=0, rest = big endian number +D0_WARN_UNUSED_RESULT d0_bignum_t *d0_iobuf_read_bignum(d0_iobuf_t *buf, d0_bignum_t *bignum); +D0_WARN_UNUSED_RESULT ssize_t d0_bignum_export_unsigned(const d0_bignum_t *bignum, void *buf, size_t bufsize); // big endian, return value = number of significant bytes (or -1 on error) +D0_WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_import_unsigned(d0_bignum_t *bignum, const void *buf, size_t bufsize); -WARN_UNUSED_RESULT BOOL d0_bignum_INITIALIZE(void); +D0_WARN_UNUSED_RESULT D0_BOOL d0_bignum_INITIALIZE(void); void d0_bignum_SHUTDOWN(void); -WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_new(void); +D0_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); -WARN_UNUSED_RESULT size_t d0_bignum_size(const d0_bignum_t *r); -WARN_UNUSED_RESULT int d0_bignum_cmp(const d0_bignum_t *a, const d0_bignum_t *b); -WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_rand_range(d0_bignum_t *r, const d0_bignum_t *min, const d0_bignum_t *max); -WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_rand_bit_atmost(d0_bignum_t *r, size_t n); -WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_rand_bit_exact(d0_bignum_t *r, size_t n); -WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_zero(d0_bignum_t *r); -WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_one(d0_bignum_t *r); -WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_int(d0_bignum_t *r, int n); -WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_mov(d0_bignum_t *r, const d0_bignum_t *a); -WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_neg(d0_bignum_t *r, const d0_bignum_t *a); -WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_shl(d0_bignum_t *r, const d0_bignum_t *a, ssize_t n); -WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_add(d0_bignum_t *r, const d0_bignum_t *a, const d0_bignum_t *b); -WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_sub(d0_bignum_t *r, const d0_bignum_t *a, const d0_bignum_t *b); -WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_mul(d0_bignum_t *r, const d0_bignum_t *a, const d0_bignum_t *b); -WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_divmod(d0_bignum_t *q, d0_bignum_t *m, const d0_bignum_t *a, const d0_bignum_t *b); // only do mod if both are NULL -WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_mod_add(d0_bignum_t *r, const d0_bignum_t *a, const d0_bignum_t *b, const d0_bignum_t *m); -WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_mod_mul(d0_bignum_t *r, const d0_bignum_t *a, const d0_bignum_t *b, const d0_bignum_t *m); -WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_mod_pow(d0_bignum_t *r, const d0_bignum_t *a, const d0_bignum_t *b, const d0_bignum_t *m); -WARN_UNUSED_RESULT BOOL d0_bignum_mod_inv(d0_bignum_t *r, const d0_bignum_t *a, const d0_bignum_t *m); -WARN_UNUSED_RESULT int d0_bignum_isprime(d0_bignum_t *r, int param); -WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_gcd(d0_bignum_t *r, d0_bignum_t *s, d0_bignum_t *t, const d0_bignum_t *a, const d0_bignum_t *b); +D0_WARN_UNUSED_RESULT size_t d0_bignum_size(const d0_bignum_t *r); +D0_WARN_UNUSED_RESULT int d0_bignum_cmp(const d0_bignum_t *a, const d0_bignum_t *b); +D0_WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_rand_range(d0_bignum_t *r, const d0_bignum_t *min, const d0_bignum_t *max); +D0_WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_rand_bit_atmost(d0_bignum_t *r, size_t n); +D0_WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_rand_bit_exact(d0_bignum_t *r, size_t n); +D0_WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_zero(d0_bignum_t *r); +D0_WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_one(d0_bignum_t *r); +D0_WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_int(d0_bignum_t *r, int n); +D0_WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_mov(d0_bignum_t *r, const d0_bignum_t *a); +D0_WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_neg(d0_bignum_t *r, const d0_bignum_t *a); +D0_WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_shl(d0_bignum_t *r, const d0_bignum_t *a, ssize_t n); +D0_WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_add(d0_bignum_t *r, const d0_bignum_t *a, const d0_bignum_t *b); +D0_WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_sub(d0_bignum_t *r, const d0_bignum_t *a, const d0_bignum_t *b); +D0_WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_mul(d0_bignum_t *r, const d0_bignum_t *a, const d0_bignum_t *b); +D0_WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_divmod(d0_bignum_t *q, d0_bignum_t *m, const d0_bignum_t *a, const d0_bignum_t *b); // only do mod if both are NULL +D0_WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_mod_add(d0_bignum_t *r, const d0_bignum_t *a, const d0_bignum_t *b, const d0_bignum_t *m); +D0_WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_mod_mul(d0_bignum_t *r, const d0_bignum_t *a, const d0_bignum_t *b, const d0_bignum_t *m); +D0_WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_mod_pow(d0_bignum_t *r, const d0_bignum_t *a, const d0_bignum_t *b, const d0_bignum_t *m); +D0_WARN_UNUSED_RESULT D0_BOOL d0_bignum_mod_inv(d0_bignum_t *r, const d0_bignum_t *a, const d0_bignum_t *m); +D0_WARN_UNUSED_RESULT int d0_bignum_isprime(d0_bignum_t *r, int param); +D0_WARN_UNUSED_RESULT d0_bignum_t *d0_bignum_gcd(d0_bignum_t *r, d0_bignum_t *s, d0_bignum_t *t, const d0_bignum_t *a, const d0_bignum_t *b); -WARN_UNUSED_RESULT char *d0_bignum_tostring(const d0_bignum_t *x, unsigned int base); // allocates! +D0_WARN_UNUSED_RESULT char *d0_bignum_tostring(const d0_bignum_t *x, unsigned int base); // allocates! #endif diff --git a/d0_blind_id.c b/d0_blind_id.c index bc9db70..9bb650c 100644 --- a/d0_blind_id.c +++ b/d0_blind_id.c @@ -104,7 +104,7 @@ struct d0_blind_id_s static d0_bignum_t *zero, *one, *four, *temp0, *temp1, *temp2, *temp3, *temp4; -WARN_UNUSED_RESULT BOOL d0_blind_id_INITIALIZE(void) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_INITIALIZE(void) { CHECK(d0_bignum_INITIALIZE()); CHECK_ASSIGN(zero, d0_bignum_int(zero, 0)); @@ -152,7 +152,7 @@ fail: return NULL; } -BOOL d0_dl_generate_key(size_t size, d0_bignum_t *G) +D0_BOOL d0_dl_generate_key(size_t size, d0_bignum_t *G) { // using: temp0 if(size < 16) @@ -174,7 +174,7 @@ fail: return 0; } -BOOL d0_rsa_generate_key(size_t size, const d0_bignum_t *challenge, d0_bignum_t *d, d0_bignum_t *n) +D0_BOOL d0_rsa_generate_key(size_t size, const d0_bignum_t *challenge, d0_bignum_t *d, d0_bignum_t *n) { // uses temp0 to temp4 int fail = 0; @@ -230,7 +230,7 @@ fail: return 0; } -BOOL d0_rsa_generate_key_fastreject(size_t size, d0_fastreject_function reject, d0_blind_id_t *ctx, void *pass) +D0_BOOL d0_rsa_generate_key_fastreject(size_t size, d0_fastreject_function reject, d0_blind_id_t *ctx, void *pass) { // uses temp0 to temp4 int fail = 0; @@ -289,7 +289,7 @@ fail: return 0; } -WARN_UNUSED_RESULT BOOL d0_longhash_destructive(d0_bignum_t *clobberme, char *outbuf, size_t outbuflen) +D0_WARN_UNUSED_RESULT D0_BOOL d0_longhash_destructive(d0_bignum_t *clobberme, char *outbuf, size_t outbuflen) { d0_iobuf_t *out = NULL; static unsigned char convbuf[1024]; @@ -332,7 +332,7 @@ void d0_blind_id_clear(d0_blind_id_t *ctx) memset(ctx, 0, sizeof(*ctx)); } -WARN_UNUSED_RESULT BOOL d0_blind_id_copy(d0_blind_id_t *ctx, const d0_blind_id_t *src) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_copy(d0_blind_id_t *ctx, const d0_blind_id_t *src) { d0_blind_id_clear(ctx); if(src->rsa_n) CHECK_ASSIGN(ctx->rsa_n, d0_bignum_mov(NULL, src->rsa_n)); @@ -357,7 +357,7 @@ fail: return 0; } -WARN_UNUSED_RESULT BOOL d0_blind_id_generate_private_key_fastreject(d0_blind_id_t *ctx, int k, d0_fastreject_function reject, void *pass) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_generate_private_key_fastreject(d0_blind_id_t *ctx, int k, d0_fastreject_function reject, void *pass) { REPLACING(rsa_e); REPLACING(rsa_d); REPLACING(rsa_n); @@ -373,12 +373,12 @@ fail: return 0; } -WARN_UNUSED_RESULT BOOL d0_blind_id_generate_private_key(d0_blind_id_t *ctx, int k) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_generate_private_key(d0_blind_id_t *ctx, int k) { return d0_blind_id_generate_private_key_fastreject(ctx, k, NULL, NULL); } -WARN_UNUSED_RESULT BOOL d0_blind_id_read_private_key(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_read_private_key(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen) { d0_iobuf_t *in = NULL; @@ -396,7 +396,7 @@ fail: return 0; } -WARN_UNUSED_RESULT BOOL d0_blind_id_read_public_key(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_read_public_key(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen) { d0_iobuf_t *in = NULL; @@ -412,7 +412,7 @@ fail: return 0; } -WARN_UNUSED_RESULT BOOL d0_blind_id_write_private_key(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_write_private_key(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen) { d0_iobuf_t *out = NULL; @@ -429,7 +429,7 @@ fail: return 0; } -WARN_UNUSED_RESULT BOOL d0_blind_id_write_public_key(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_write_public_key(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen) { d0_iobuf_t *out = NULL; @@ -446,7 +446,7 @@ fail: return 0; } -WARN_UNUSED_RESULT BOOL d0_blind_id_fingerprint64_public_key(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_fingerprint64_public_key(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen) { d0_iobuf_t *out = NULL; static unsigned char convbuf[2048]; @@ -478,7 +478,7 @@ fail: return 0; } -WARN_UNUSED_RESULT BOOL d0_blind_id_generate_private_id_modulus(d0_blind_id_t *ctx) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_generate_private_id_modulus(d0_blind_id_t *ctx) { USING(rsa_n); REPLACING(schnorr_G); @@ -490,7 +490,7 @@ fail: return 0; } -WARN_UNUSED_RESULT BOOL d0_blind_id_read_private_id_modulus(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_read_private_id_modulus(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen) { d0_iobuf_t *in = NULL; @@ -505,7 +505,7 @@ fail: return 0; } -WARN_UNUSED_RESULT BOOL d0_blind_id_write_private_id_modulus(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_write_private_id_modulus(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen) { d0_iobuf_t *out = NULL; @@ -520,7 +520,7 @@ fail: return 0; } -WARN_UNUSED_RESULT BOOL d0_blind_id_generate_private_id_start(d0_blind_id_t *ctx) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_generate_private_id_start(d0_blind_id_t *ctx) { // temps: temp0 = order USING(schnorr_G); @@ -536,7 +536,7 @@ fail: return 0; } -WARN_UNUSED_RESULT BOOL d0_blind_id_generate_private_id_request(d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_generate_private_id_request(d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen) { d0_iobuf_t *out = NULL; static unsigned char convbuf[2048], shabuf[2048]; @@ -569,7 +569,7 @@ fail: return 0; } -WARN_UNUSED_RESULT BOOL d0_blind_id_answer_private_id_request(const d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen, char *outbuf, size_t *outbuflen) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_answer_private_id_request(const d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen, char *outbuf, size_t *outbuflen) { d0_iobuf_t *in = NULL; d0_iobuf_t *out = NULL; @@ -593,7 +593,7 @@ fail: return 0; } -WARN_UNUSED_RESULT BOOL d0_blind_id_finish_private_id_request(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_finish_private_id_request(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen) { d0_iobuf_t *in = NULL; @@ -614,7 +614,7 @@ fail: return 0; } -WARN_UNUSED_RESULT BOOL d0_blind_id_read_private_id_request_camouflage(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_read_private_id_request_camouflage(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen) { d0_iobuf_t *in = NULL; @@ -631,7 +631,7 @@ fail: return 0; } -WARN_UNUSED_RESULT BOOL d0_blind_id_write_private_id_request_camouflage(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_write_private_id_request_camouflage(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen) { d0_iobuf_t *out = NULL; @@ -648,7 +648,7 @@ fail: return 0; } -WARN_UNUSED_RESULT BOOL d0_blind_id_read_private_id(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_read_private_id(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen) { d0_iobuf_t *in = NULL; @@ -667,7 +667,7 @@ fail: return 0; } -WARN_UNUSED_RESULT BOOL d0_blind_id_read_public_id(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_read_public_id(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen) { d0_iobuf_t *in = NULL; @@ -685,7 +685,7 @@ fail: return 0; } -WARN_UNUSED_RESULT BOOL d0_blind_id_write_private_id(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_write_private_id(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen) { d0_iobuf_t *out = NULL; @@ -704,7 +704,7 @@ fail: return 0; } -WARN_UNUSED_RESULT BOOL d0_blind_id_write_public_id(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_write_public_id(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen) { d0_iobuf_t *out = NULL; @@ -722,7 +722,7 @@ fail: return 0; } -WARN_UNUSED_RESULT BOOL d0_blind_id_authenticate_with_private_id_start(d0_blind_id_t *ctx, BOOL is_first, BOOL send_modulus, char *msg, size_t msglen, char *outbuf, size_t *outbuflen) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_authenticate_with_private_id_start(d0_blind_id_t *ctx, D0_BOOL is_first, D0_BOOL send_modulus, char *msg, size_t msglen, char *outbuf, size_t *outbuflen) // start = // first run: send 4^s, 4^s signature // 1. get random r, send HASH(4^r) @@ -731,7 +731,7 @@ WARN_UNUSED_RESULT BOOL d0_blind_id_authenticate_with_private_id_start(d0_blind_ static unsigned char convbuf[1024]; d0_iobuf_t *conv = NULL; size_t sz = 0; - BOOL failed = 0; + D0_BOOL failed = 0; // temps: temp0 order, temp0 4^r if(is_first) @@ -786,7 +786,7 @@ fail: return 0; } -WARN_UNUSED_RESULT BOOL d0_blind_id_authenticate_with_private_id_challenge(d0_blind_id_t *ctx, BOOL is_first, BOOL recv_modulus, const char *inbuf, size_t inbuflen, char *outbuf, size_t *outbuflen, BOOL *status) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_authenticate_with_private_id_challenge(d0_blind_id_t *ctx, D0_BOOL is_first, D0_BOOL recv_modulus, const char *inbuf, size_t inbuflen, char *outbuf, size_t *outbuflen, D0_BOOL *status) // first run: get 4^s, 4^s signature // 1. check sig // 2. save HASH(4^r) @@ -880,7 +880,7 @@ fail: return 0; } -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) +D0_WARN_UNUSED_RESULT D0_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) // 1. read challenge challenge of SCHNORR_BITS // 2. reply with r + s * challenge mod order { @@ -921,7 +921,7 @@ fail: return 0; } -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, size_t *msglen, BOOL *status) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_authenticate_with_private_id_verify(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen, char *msg, size_t *msglen, D0_BOOL *status) // 1. read y = r + s * challenge mod order // 2. verify: g^y (g^s)^-challenge = g^(r+s*challenge-s*challenge) = g^r // (check using H(g^r) which we know) @@ -986,7 +986,7 @@ fail: return 0; } -WARN_UNUSED_RESULT BOOL d0_blind_id_authenticate_with_private_id_generate_missing_signature(d0_blind_id_t *ctx) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_authenticate_with_private_id_generate_missing_signature(d0_blind_id_t *ctx) { size_t sz; static unsigned char shabuf[2048]; @@ -1011,7 +1011,7 @@ fail: return 0; } -WARN_UNUSED_RESULT BOOL d0_blind_id_fingerprint64_public_id(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen) +D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_fingerprint64_public_id(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen) { d0_iobuf_t *out = NULL; static unsigned char convbuf[1024]; @@ -1046,7 +1046,7 @@ fail: return 0; } -BOOL d0_blind_id_sessionkey_public_id(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen) +D0_BOOL d0_blind_id_sessionkey_public_id(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen) { USING(t); USING(other_g_to_t); USING(schnorr_G); diff --git a/d0_blind_id.h b/d0_blind_id.h index fde7c49..522a02d 100644 --- a/d0_blind_id.h +++ b/d0_blind_id.h @@ -39,43 +39,43 @@ #include "d0.h" typedef struct d0_blind_id_s d0_blind_id_t; -typedef BOOL (*d0_fastreject_function) (const d0_blind_id_t *ctx, void *pass); +typedef D0_BOOL (*d0_fastreject_function) (const d0_blind_id_t *ctx, void *pass); -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 WARN_UNUSED_RESULT BOOL d0_blind_id_copy(d0_blind_id_t *ctx, const d0_blind_id_t *src); -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_generate_private_key(d0_blind_id_t *ctx, int k); -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_generate_private_key_fastreject(d0_blind_id_t *ctx, int k, d0_fastreject_function reject, void *pass); -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_read_private_key(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen); -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_read_public_key(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen); -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_write_private_key(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen); -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_write_public_key(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen); -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_fingerprint64_public_key(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen); -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_generate_private_id_modulus(d0_blind_id_t *ctx); -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_read_private_id_modulus(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen); -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_write_private_id_modulus(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen); -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_generate_private_id_start(d0_blind_id_t *ctx); -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_generate_private_id_request(d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen); -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_answer_private_id_request(const d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen, char *outbuf, size_t *outbuflen); -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_finish_private_id_request(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen); -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_read_private_id_request_camouflage(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen); -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_write_private_id_request_camouflage(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen); -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_read_private_id(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen); -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_read_public_id(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen); -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_write_private_id(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen); -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_write_public_id(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen); -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_authenticate_with_private_id_start(d0_blind_id_t *ctx, BOOL is_first, BOOL send_modulus, char *message, size_t msglen, char *outbuf, size_t *outbuflen); -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_authenticate_with_private_id_challenge(d0_blind_id_t *ctx, BOOL is_first, BOOL recv_modulus, const char *inbuf, size_t inbuflen, char *outbuf, size_t *outbuflen, BOOL *status); -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, size_t *msglen, BOOL *status); -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_authenticate_with_private_id_generate_missing_signature(d0_blind_id_t *ctx); -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_fingerprint64_public_id(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen); -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_sessionkey_public_id(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen); // can only be done after successful key exchange, this performs a modpow; key length is limited by SHA_DIGESTSIZE for now; also ONLY valid after successful d0_blind_id_authenticate_with_private_id_verify/d0_blind_id_fingerprint64_public_id +D0_EXPORT D0_WARN_UNUSED_RESULT d0_blind_id_t *d0_blind_id_new(void); +D0_EXPORT void d0_blind_id_free(d0_blind_id_t *a); +D0_EXPORT void d0_blind_id_clear(d0_blind_id_t *ctx); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_copy(d0_blind_id_t *ctx, const d0_blind_id_t *src); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_generate_private_key(d0_blind_id_t *ctx, int k); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_generate_private_key_fastreject(d0_blind_id_t *ctx, int k, d0_fastreject_function reject, void *pass); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_read_private_key(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_read_public_key(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_write_private_key(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_write_public_key(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_fingerprint64_public_key(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_generate_private_id_modulus(d0_blind_id_t *ctx); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_read_private_id_modulus(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_write_private_id_modulus(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_generate_private_id_start(d0_blind_id_t *ctx); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_generate_private_id_request(d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_answer_private_id_request(const d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen, char *outbuf, size_t *outbuflen); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_finish_private_id_request(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_read_private_id_request_camouflage(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_write_private_id_request_camouflage(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_read_private_id(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_read_public_id(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_write_private_id(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_write_public_id(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_authenticate_with_private_id_start(d0_blind_id_t *ctx, D0_BOOL is_first, D0_BOOL send_modulus, char *message, size_t msglen, char *outbuf, size_t *outbuflen); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_authenticate_with_private_id_challenge(d0_blind_id_t *ctx, D0_BOOL is_first, D0_BOOL recv_modulus, const char *inbuf, size_t inbuflen, char *outbuf, size_t *outbuflen, D0_BOOL *status); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_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); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_authenticate_with_private_id_verify(d0_blind_id_t *ctx, const char *inbuf, size_t inbuflen, char *msg, size_t *msglen, D0_BOOL *status); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_authenticate_with_private_id_generate_missing_signature(d0_blind_id_t *ctx); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_fingerprint64_public_id(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_sessionkey_public_id(const d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen); // can only be done after successful key exchange, this performs a modpow; key length is limited by SHA_DIGESTSIZE for now; also ONLY valid after successful d0_blind_id_authenticate_with_private_id_verify/d0_blind_id_fingerprint64_public_id -EXPORT WARN_UNUSED_RESULT BOOL d0_blind_id_INITIALIZE(void); -EXPORT void d0_blind_id_SHUTDOWN(void); +D0_EXPORT D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_INITIALIZE(void); +D0_EXPORT void d0_blind_id_SHUTDOWN(void); -EXPORT void d0_blind_id_util_sha256(char *out, const char *in, size_t n); +D0_EXPORT void d0_blind_id_util_sha256(char *out, const char *in, size_t n); #endif diff --git a/d0_iobuf.c b/d0_iobuf.c index 60eb2cd..ce8e58d 100644 --- a/d0_iobuf.c +++ b/d0_iobuf.c @@ -42,7 +42,7 @@ struct d0_iobuf_s const unsigned char *inbuf; unsigned char *outbuf; size_t inpos, outpos, inbuflen, outbuflen; - BOOL ok; + D0_BOOL ok; }; d0_iobuf_t *d0_iobuf_open_read(const void *buf, size_t len) @@ -69,9 +69,9 @@ d0_iobuf_t *d0_iobuf_open_write(void *buf, size_t len) return b; } -BOOL d0_iobuf_close(d0_iobuf_t *buf, size_t *len) +D0_BOOL d0_iobuf_close(d0_iobuf_t *buf, size_t *len) { - BOOL r = buf->ok; + D0_BOOL r = buf->ok; if(len) *len = buf->outpos; d0_free(buf); @@ -104,7 +104,7 @@ size_t d0_iobuf_read_raw(d0_iobuf_t *buf, void *s, size_t n) return nreal; } -BOOL d0_iobuf_write_packet(d0_iobuf_t *buf, const void *s, size_t n) +D0_BOOL d0_iobuf_write_packet(d0_iobuf_t *buf, const void *s, size_t n) { unsigned char c; size_t nn = n; @@ -122,7 +122,7 @@ BOOL d0_iobuf_write_packet(d0_iobuf_t *buf, const void *s, size_t n) return 1; } -BOOL d0_iobuf_read_packet(d0_iobuf_t *buf, void *s, size_t *np) +D0_BOOL d0_iobuf_read_packet(d0_iobuf_t *buf, void *s, size_t *np) { unsigned char c; size_t n = 0; @@ -143,7 +143,7 @@ BOOL d0_iobuf_read_packet(d0_iobuf_t *buf, void *s, size_t *np) return 1; } -BOOL d0_iobuf_conv_base64_in(d0_iobuf_t *buf) +D0_BOOL d0_iobuf_conv_base64_in(d0_iobuf_t *buf) { // compand the in-buffer return 0; @@ -165,7 +165,7 @@ static void base64_3to4(const unsigned char *in, unsigned char *out, int bytes) out[3] = (bytes > 2) ? o3 : '='; } -BOOL d0_iobuf_conv_base64_out(d0_iobuf_t *buf) +D0_BOOL d0_iobuf_conv_base64_out(d0_iobuf_t *buf) { size_t blocks, i; // expand the out-buffer diff --git a/d0_iobuf.h b/d0_iobuf.h index 6df8ce7..d774e67 100644 --- a/d0_iobuf.h +++ b/d0_iobuf.h @@ -40,14 +40,14 @@ typedef struct d0_iobuf_s d0_iobuf_t; -WARN_UNUSED_RESULT d0_iobuf_t *d0_iobuf_open_read(const void *buf, size_t len); // note: can read AND write! -WARN_UNUSED_RESULT d0_iobuf_t *d0_iobuf_open_write(void *buf, size_t len); // note: can read AND write! -WARN_UNUSED_RESULT BOOL d0_iobuf_conv_base64_in(d0_iobuf_t *buf); -WARN_UNUSED_RESULT BOOL d0_iobuf_conv_base64_out(d0_iobuf_t *buf); -BOOL d0_iobuf_close(d0_iobuf_t *buf, size_t *len); // don't warn -WARN_UNUSED_RESULT size_t d0_iobuf_write_raw(d0_iobuf_t *buf, const void *s, size_t n); -WARN_UNUSED_RESULT size_t d0_iobuf_read_raw(d0_iobuf_t *buf, void *s, size_t n); -WARN_UNUSED_RESULT BOOL d0_iobuf_write_packet(d0_iobuf_t *buf, const void *s, size_t n); -WARN_UNUSED_RESULT BOOL d0_iobuf_read_packet(d0_iobuf_t *buf, void *s, size_t *n); +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_write(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 +D0_WARN_UNUSED_RESULT size_t d0_iobuf_write_raw(d0_iobuf_t *buf, const void *s, size_t n); +D0_WARN_UNUSED_RESULT size_t d0_iobuf_read_raw(d0_iobuf_t *buf, void *s, size_t n); +D0_WARN_UNUSED_RESULT D0_BOOL d0_iobuf_write_packet(d0_iobuf_t *buf, const void *s, size_t n); +D0_WARN_UNUSED_RESULT D0_BOOL d0_iobuf_read_packet(d0_iobuf_t *buf, void *s, size_t *n); #endif diff --git a/d0_rijndael.h b/d0_rijndael.h index 59db778..e1c8f71 100644 --- a/d0_rijndael.h +++ b/d0_rijndael.h @@ -5,13 +5,13 @@ #include "d0.h" -EXPORT int d0_rijndael_setup_encrypt(unsigned long *rk, const unsigned char *key, +D0_EXPORT int d0_rijndael_setup_encrypt(unsigned long *rk, const unsigned char *key, int keybits); -EXPORT int d0_rijndael_setup_decrypt(unsigned long *rk, const unsigned char *key, +D0_EXPORT int d0_rijndael_setup_decrypt(unsigned long *rk, const unsigned char *key, int keybits); -EXPORT void d0_rijndael_encrypt(const unsigned long *rk, int nrounds, +D0_EXPORT void d0_rijndael_encrypt(const unsigned long *rk, int nrounds, const unsigned char plaintext[16], unsigned char ciphertext[16]); -EXPORT void d0_rijndael_decrypt(const unsigned long *rk, int nrounds, +D0_EXPORT void d0_rijndael_decrypt(const unsigned long *rk, int nrounds, const unsigned char ciphertext[16], unsigned char plaintext[16]); #define D0_RIJNDAEL_KEYLENGTH(keybits) ((keybits)/8) diff --git a/main.c b/main.c index 0941c00..9506c1e 100644 --- a/main.c +++ b/main.c @@ -54,7 +54,7 @@ void bench(double *b) #ifndef WIN32 #include #endif -volatile BOOL quit = 0; +volatile D0_BOOL quit = 0; void mysignal(int signo) { (void) signo; @@ -142,7 +142,7 @@ int main(int argc, char **argv) n = 0; double bench_auth = 0, bench_chall = 0, bench_resp = 0, bench_verify = 0, bench_dhkey1 = 0, bench_dhkey2 = 0; - BOOL status; + D0_BOOL status; while(!quit) { bench(&bench_auth);