int bn_probable_prime_dh_coprime(BIGNUM *rnd, int bits, BN_CTX *ctx)
	{
	int i;
	BIGNUM *offset_index;
	BIGNUM *offset_count;
	int ret = 0;
	
	BN_CTX_start(ctx);
	if ((offset_index = BN_CTX_get(ctx)) == NULL) goto err;
	if ((offset_count = BN_CTX_get(ctx)) == NULL) goto err;
	
	BN_add_word(offset_count, prime_offset_count);

loop:
	if (!BN_rand(rnd, bits, 0, 1)) goto err;
	if (!BN_rand_range(offset_index, offset_count)) goto err;

	BN_mul_word(rnd, prime_multiplier);
	BN_add_word(rnd, prime_offsets[BN_get_word(offset_index)]);

	/* we now have a random number 'rand' to test. */

	/* skip coprimes */
	for (i = first_prime_index; i < NUMPRIMES; i++)
		{
		/* check that rnd is a prime */
		if (BN_mod_word(rnd, (BN_ULONG)primes[i]) <= 1)
			{
			goto loop;
			}
		}
	ret = 1;

err:
	BN_CTX_end(ctx);
	bn_check_top(rnd);
	return ret;
	}