+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;
+ int gcdfail = 0;
+ 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));
+ if(d0_bignum_isprime(temp0, 10) == 0)
+ continue;
+ CHECK(d0_bignum_sub(temp2, temp0, one));
+ CHECK(d0_bignum_gcd(temp4, NULL, NULL, temp2, ctx->rsa_e));
+ if(!d0_bignum_cmp(temp4, one))
+ break;
+ if(++gcdfail == 3)
+ return 0;
+ ++gcdfail;
+ }
+ gcdfail = 0;
+ for (;;)
+ {
+ CHECK(d0_bignum_rand_bit_exact(temp1, qb));
+ if(!d0_bignum_cmp(temp1, temp0))
+ {
+ if(++fail == 3)
+ return 0;
+ }
+ fail = 0;
+
+ // n = temp0*temp1
+ CHECK(d0_bignum_mul(ctx->rsa_n, temp0, temp1));
+ if(reject(ctx, pass))
+ continue;
+
+ if(d0_bignum_isprime(temp1, 10) == 0)
+ continue;
+ CHECK(d0_bignum_sub(temp3, temp1, one));
+ CHECK(d0_bignum_gcd(temp4, NULL, NULL, temp3, ctx->rsa_e));
+ if(!d0_bignum_cmp(temp4, one))
+ break;
+ if(++gcdfail == 3)
+ return 0;
+ ++gcdfail;
+ }
+
+ // ctx->rsa_d = ctx->rsa_e^-1 mod (temp0-1)(temp1-1)
+ CHECK(d0_bignum_mul(temp0, temp2, temp3));
+ CHECK(d0_bignum_mod_inv(ctx->rsa_d, ctx->rsa_e, temp0));
+ return 1;
+fail:
+ return 0;
+}
+