//
// BN_rand_range from 0x10985c0 to 0x109877c (444 bytes)
//
// 11 xrefs:
// > sub_1005CF0 @ 0x1005d44
// > sub_1005CF0 @ 0x1005d60
// > sub_1008488 @ 0x1008654
// > sub_10088DC @ 0x1008948
// > ec_key_simple_generate_key @ 0x100e1e0
// > ossl_ecdsa_sign_setup @ 0x1012a28
// > ossl_ecdsa_sign_sig @ 0x1013138
// > BN_BLINDING_create_param @ 0x10935e8
// > bn_probable_prime_dh_coprime @ 0x10f53b0
// > DSA_generate_key @ 0x10fab08
// > ??> @ 0x9ad98
//
// This function is hookable on this platform (idp: arm, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 13:17:24 +0000
//
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;
}