From: Rudolf Polzer Date: Wed, 14 Jul 2010 06:05:51 +0000 (+0200) Subject: add a longer hash function (no protocol change, but now longer session keys can be... X-Git-Tag: xonotic-v0.1.0preview~38^2~16 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=52d4581a785dd0ac9ae0b51b4ed35d06bb6cff15;p=xonotic%2Fd0_blind_id.git add a longer hash function (no protocol change, but now longer session keys can be generated) --- diff --git a/d0_blind_id.c b/d0_blind_id.c index 7c1f010..9a1ddc3 100644 --- a/d0_blind_id.c +++ b/d0_blind_id.c @@ -198,6 +198,39 @@ fail: return 0; } +WARN_UNUSED_RESULT BOOL d0_longhash_destructive(d0_bignum_t *clobberme, char *outbuf, size_t *outbuflen) +{ + d0_iobuf_t *out = NULL; + static unsigned char convbuf[1024]; + d0_iobuf_t *conv = NULL; + size_t n, sz; + + n = *outbuflen; + while(n > SHA_DIGESTSIZE) + { + conv = d0_iobuf_open_write(convbuf, sizeof(convbuf)); + CHECK(d0_iobuf_write_bignum(conv, temp0)); + CHECK(d0_iobuf_close(conv, &sz)); + conv = NULL; + memcpy(outbuf, sha(convbuf, sz), SHA_DIGESTSIZE); + outbuf += SHA_DIGESTSIZE; + n -= SHA_DIGESTSIZE; + CHECK(d0_bignum_add(temp0, temp0, one)); + } + conv = d0_iobuf_open_write(convbuf, sizeof(convbuf)); + CHECK(d0_iobuf_write_bignum(conv, temp0)); + CHECK(d0_iobuf_close(conv, &sz)); + conv = NULL; + memcpy(outbuf, sha(convbuf, sz), n); + + return d0_iobuf_close(out, outbuflen); + +fail: + if(conv) + d0_iobuf_close(conv, &sz); + return 0; +} + void d0_blind_id_clear(d0_blind_id_t *ctx) { if(ctx->rsa_n) d0_bignum_free(ctx->rsa_n); @@ -841,33 +874,13 @@ fail: BOOL d0_blind_id_sessionkey_public_id(d0_blind_id_t *ctx, char *outbuf, size_t *outbuflen) { - d0_iobuf_t *out = NULL; - static unsigned char convbuf[1024]; - d0_iobuf_t *conv = NULL; - size_t n, sz; - USING(r); USING(other_4_to_r); USING(schnorr_G); - out = d0_iobuf_open_write(outbuf, *outbuflen); - conv = d0_iobuf_open_write(convbuf, sizeof(convbuf)); - // temps: temp0 result CHECK(d0_bignum_mod_pow(temp0, ctx->other_4_to_r, ctx->r, ctx->schnorr_G)); - CHECK(d0_iobuf_write_bignum(conv, temp0)); - CHECK(d0_iobuf_close(conv, &sz)); - conv = NULL; - - n = *outbuflen; - if(n > SHA_DIGESTSIZE) - n = SHA_DIGESTSIZE; - CHECK(d0_iobuf_write_raw(out, sha(convbuf, sz), n) == n); - - return d0_iobuf_close(out, outbuflen); + return d0_longhash_destructive(temp0, outbuf, outbuflen); fail: - if(conv) - d0_iobuf_close(conv, &sz); - d0_iobuf_close(out, outbuflen); return 0; }