X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=d0_blind_id.c;h=e138642c240a7d490a76ee722b68a779c125cf67;hb=503ed535983a12b4333428712ac404d062519782;hp=cc85624e5cc8e680f8251dc09da0366135e81496;hpb=4145420d34f05696e610e2f414874312ad572479;p=xonotic%2Fd0_blind_id.git diff --git a/d0_blind_id.c b/d0_blind_id.c index cc85624..e138642 100644 --- a/d0_blind_id.c +++ b/d0_blind_id.c @@ -88,9 +88,9 @@ struct d0_blind_id_s static d0_bignum_t *zero, *one, *four, *temp0, *temp1, *temp2, *temp3, *temp4; -void d0_blind_id_INITIALIZE(void) +WARN_UNUSED_RESULT BOOL d0_blind_id_INITIALIZE(void) { - d0_bignum_INITIALIZE(); + CHECK(d0_bignum_INITIALIZE()); CHECK_ASSIGN(zero, d0_bignum_int(zero, 0)); CHECK_ASSIGN(one, d0_bignum_int(one, 1)); CHECK_ASSIGN(four, d0_bignum_int(four, 4)); @@ -99,8 +99,9 @@ void d0_blind_id_INITIALIZE(void) CHECK_ASSIGN(temp2, d0_bignum_int(temp2, 0)); CHECK_ASSIGN(temp3, d0_bignum_int(temp3, 0)); CHECK_ASSIGN(temp4, d0_bignum_int(temp4, 0)); + return 1; fail: - ; + return 0; } void d0_blind_id_SHUTDOWN(void) @@ -979,6 +980,31 @@ fail: return 0; } +WARN_UNUSED_RESULT BOOL d0_blind_id_authenticate_with_private_id_generate_missing_signature(d0_blind_id_t *ctx) +{ + size_t sz; + static unsigned char shabuf[2048]; + + REPLACING(schnorr_H_g_to_s_signature); + USING(schnorr_g_to_s); USING(rsa_d); USING(rsa_n); + + // we will actually sign SHA(4^s) to prevent a malleability attack! + CHECK(d0_bignum_mov(temp2, ctx->schnorr_g_to_s)); + sz = (d0_bignum_size(ctx->rsa_n) + 7) / 8; // this is too long, so we have to take the value % rsa_n when "decrypting" + if(sz > sizeof(shabuf)) + sz = sizeof(shabuf); + CHECK(d0_longhash_destructive(temp2, shabuf, sz)); + CHECK(d0_bignum_import_unsigned(temp2, shabuf, sz)); + + // + 7 / 8 is too large, so let's mod it + CHECK(d0_bignum_divmod(NULL, temp1, temp2, ctx->rsa_n)); + CHECK(d0_bignum_mod_pow(ctx->schnorr_H_g_to_s_signature, temp1, ctx->rsa_d, ctx->rsa_n)); + return 1; + +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_iobuf_t *out = NULL;