//
// BN_pseudo_rand_range from 0x109877c to 0x1098938 (444 bytes)
//
// 2 xrefs:
// > BN_is_prime_fasttest_ex @ 0x10f5168
// > ??> @ 0xbf5a8
//
// 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_pseudo_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_pseudo_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_pseudo_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;
}