CHECK(d0_bignum_gcd(temp4, NULL, NULL, temp2, ctx->rsa_e));
if(!d0_bignum_cmp(temp4, one))
break;
- if(++gcdfail == 3)
+ if(++gcdfail == 16)
goto fail;
- ++gcdfail;
}
UNLOCKTEMPS();
if(!d0_bignum_cmp(temp1, ctx->rsa_d))
{
UNLOCKTEMPS();
- if(++fail == 3)
+ if(++fail == 16)
goto fail;
continue;
}
break;
}
UNLOCKTEMPS();
- if(++gcdfail == 3)
+ if(++gcdfail == 16)
goto fail;
- ++gcdfail;
}
// ctx->rsa_n = ctx->rsa_d*temp1
// ctx->rsa_d = ctx->rsa_e^-1 mod (ctx->rsa_d-1)(temp1-1)
CHECK(d0_bignum_sub(temp2, ctx->rsa_d, one)); // we can't reuse the value from above because temps were unlocked
- CHECK(d0_bignum_mul(temp0, temp2, temp3));
- CHECK(d0_bignum_mod_inv(ctx->rsa_d, ctx->rsa_e, temp0));
+ CHECK(d0_bignum_mul(temp1, temp2, temp3));
+ CHECK(d0_bignum_mod_inv(ctx->rsa_d, ctx->rsa_e, temp1));
UNLOCKTEMPS();
return 1;
fail:
CHECK(d0_bignum_gcd(temp4, NULL, NULL, temp2, ctx->rsa_e));
if(!d0_bignum_cmp(temp4, one))
break;
- if(++gcdfail == 3)
+ if(++gcdfail == 16)
return 0;
- ++gcdfail;
}
UNLOCKTEMPS();
if(!d0_bignum_cmp(temp1, ctx->rsa_d))
{
UNLOCKTEMPS();
- if(++fail == 3)
+ if(++fail == 16)
return 0;
continue;
}
break;
}
UNLOCKTEMPS();
- if(++gcdfail == 3)
+ if(++gcdfail == 16)
return 0;
- ++gcdfail;
}
// ctx->rsa_d = ctx->rsa_e^-1 mod (ctx->rsa_d-1)(temp1-1)
CHECK(d0_bignum_sub(temp2, ctx->rsa_d, one)); // we can't reuse the value from above because temps were unlocked
- CHECK(d0_bignum_mul(ctx->rsa_d, temp2, temp3));
- CHECK(d0_bignum_mod_inv(ctx->rsa_d, ctx->rsa_e, temp0));
+ CHECK(d0_bignum_mul(temp1, temp2, temp3));
+ CHECK(d0_bignum_mod_inv(ctx->rsa_d, ctx->rsa_e, temp1));
UNLOCKTEMPS();
return 1;
fail:
// we will actually sign HA(4^s) to prevent a malleability attack!
LOCKTEMPS();
- 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(hashbuf))
sz = sizeof(hashbuf);
- CHECK(d0_longhash_bignum(temp2, hashbuf, sz));
+ CHECK(d0_longhash_bignum(ctx->schnorr_g_to_s, hashbuf, sz));
CHECK(d0_bignum_import_unsigned(temp2, hashbuf, sz));
// hash complete
CHECK(d0_bignum_cmp(ctx->schnorr_H_g_to_s_signature, zero) >= 0);
CHECK(d0_bignum_cmp(ctx->schnorr_H_g_to_s_signature, ctx->rsa_n) < 0);
- // check signature of key (t = k^d, so, t^challenge = k)
- LOCKTEMPS();
- CHECK(d0_bignum_mod_pow(temp0, ctx->schnorr_H_g_to_s_signature, ctx->rsa_e, ctx->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(hashbuf))
- sz = sizeof(hashbuf);
- CHECK(d0_longhash_bignum(temp2, hashbuf, sz));
- CHECK(d0_bignum_import_unsigned(temp2, hashbuf, sz));
-
- // + 7 / 8 is too large, so let's mod it
- CHECK(d0_bignum_divmod(NULL, temp1, temp2, ctx->rsa_n));
-
- // hash complete
- if(d0_bignum_cmp(temp0, temp1))
+ if(d0_bignum_cmp(ctx->schnorr_H_g_to_s_signature, zero))
{
- // accept the key anyway, but mark as failed signature! will later return 0 in status
- CHECK(d0_bignum_zero(ctx->schnorr_H_g_to_s_signature));
+ // check signature of key (t = k^d, so, t^challenge = k)
+ LOCKTEMPS();
+ CHECK(d0_bignum_mod_pow(temp0, ctx->schnorr_H_g_to_s_signature, ctx->rsa_e, ctx->rsa_n));
+
+ // we will actually sign SHA(4^s) to prevent a malleability attack!
+ 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(hashbuf))
+ sz = sizeof(hashbuf);
+ CHECK(d0_longhash_bignum(ctx->schnorr_g_to_s, hashbuf, sz));
+ CHECK(d0_bignum_import_unsigned(temp2, hashbuf, sz));
+
+ // + 7 / 8 is too large, so let's mod it
+ CHECK(d0_bignum_divmod(NULL, temp1, temp2, ctx->rsa_n));
+
+ // hash complete
+ CHECK(d0_bignum_cmp(temp0, temp1) == 0);
}
}
return 0;
}
+D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_verify_public_id(const d0_blind_id_t *ctx, D0_BOOL *status)
+{
+ unsigned char hashbuf[2048];
+ size_t sz;
+
+ USINGTEMPS(); // temps: temp0 temp1 temp2
+ USING(schnorr_H_g_to_s_signature); USING(rsa_e); USING(rsa_n); USING(schnorr_g_to_s);
+
+ if(d0_bignum_cmp(ctx->schnorr_H_g_to_s_signature, zero))
+ {
+ // check signature of key (t = k^d, so, t^challenge = k)
+ LOCKTEMPS();
+
+ CHECK(d0_bignum_mod_pow(temp0, ctx->schnorr_H_g_to_s_signature, ctx->rsa_e, ctx->rsa_n));
+
+ // we will actually sign SHA(4^s) to prevent a malleability attack!
+ 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(hashbuf))
+ sz = sizeof(hashbuf);
+ CHECK(d0_longhash_bignum(ctx->schnorr_g_to_s, hashbuf, sz));
+ CHECK(d0_bignum_import_unsigned(temp2, hashbuf, sz));
+
+ // + 7 / 8 is too large, so let's mod it
+ CHECK(d0_bignum_divmod(NULL, temp1, temp2, ctx->rsa_n));
+
+ // hash complete
+ CHECK(d0_bignum_cmp(temp0, temp1) == 0);
+
+ *status = 1;
+ }
+ else
+ *status = 0;
+
+ UNLOCKTEMPS();
+ return 1;
+
+fail:
+ UNLOCKTEMPS();
+ return 0;
+}
+
+D0_WARN_UNUSED_RESULT D0_BOOL d0_blind_id_verify_private_id(const d0_blind_id_t *ctx)
+{
+ USINGTEMPS(); // temps: temp0 = g^s
+ USING(schnorr_G); USING(schnorr_s); USING(schnorr_g_to_s);
+
+ LOCKTEMPS();
+ CHECK(d0_bignum_mod_pow(temp0, four, ctx->schnorr_s, ctx->schnorr_G));
+ CHECK(!d0_bignum_cmp(temp0, ctx->schnorr_g_to_s));
+ UNLOCKTEMPS();
+ return 1;
+
+fail:
+ UNLOCKTEMPS();
+ return 0;
+}
+
d0_blind_id_t *d0_blind_id_new(void)
{
d0_blind_id_t *b = d0_malloc(sizeof(d0_blind_id_t));