//
// BN_rand_range from 0xe1a2c0 to 0xe1a47c (444 bytes)
//
// 11 xrefs:
// > sub_D87990 @ 0xd879e4
// > sub_D87990 @ 0xd87a00
// > sub_D8A128 @ 0xd8a2f4
// > sub_D8A57C @ 0xd8a5e8
// > ec_key_simple_generate_key @ 0xd8fe80
// > ossl_ecdsa_sign_setup @ 0xd946c8
// > ossl_ecdsa_sign_sig @ 0xd94dd8
// > BN_BLINDING_create_param @ 0xe152e8
// > bn_probable_prime_dh_coprime @ 0xe773b0
// > DSA_generate_key @ 0xe7cb08
// > ??> @ 0x73518
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
bool __fastcall BN_rand_range(__int64 *a1, __int64 a2)
{
_BOOL4 is_zero; // w23
int v6; // w22
int v7; // w20
int v8; // w22
int v9; // w20
if ( *(_DWORD *)(a2 + 16) || (is_zero = BN_is_zero(a2)) )
{
is_zero = 0;
ERR_put_error(3, 122, 115, (__int64)"crypto/bn/bn_rand.c", 120);
}
else
{
v6 = BN_num_bits(a2);
if ( v6 == 1 )
{
is_zero = 1;
BN_set_word((__int64)a1, 0);
}
else if ( (unsigned int)BN_is_bit_set(a2, v6 - 2) || (unsigned int)BN_is_bit_set(a2, v6 - 3) )
{
v7 = 100;
while ( 1 )
{
--v7;
if ( !(unsigned int)BN_rand((__int64)a1, v6, -1, 0) )
break;
if ( !v7 )
{
ERR_put_error(3, 122, 113, (__int64)"crypto/bn/bn_rand.c", 166);
return is_zero;
}
if ( (BN_cmp(a1, (__int64 *)a2) & 0x80000000) != 0 )
return 1;
}
}
else
{
v8 = v6 + 1;
v9 = 100;
while ( (unsigned int)BN_rand((__int64)a1, v8, -1, 0)
&& ((BN_cmp(a1, (__int64 *)a2) & 0x80000000) != 0
|| (unsigned int)BN_sub((__int64)a1, (__int64)a1, a2)
&& ((BN_cmp(a1, (__int64 *)a2) & 0x80000000) != 0 || (unsigned int)BN_sub((__int64)a1, (__int64)a1, a2))) )
{
if ( !--v9 )
{
is_zero = 0;
ERR_put_error(3, 122, 113, (__int64)"crypto/bn/bn_rand.c", 153);
return is_zero;
}
if ( (BN_cmp(a1, (__int64 *)a2) & 0x80000000) != 0 )
return 1;
}
}
}
return is_zero;
}