//
// BN_gcd from 0x109686c to 0x1096a2c (448 bytes)
//
// 3 xrefs:
// > RSA_generate_key_ex @ 0x10e8aac
// > RSA_generate_key_ex @ 0x10e8c18
// > ??> @ 0xb1538
//
// 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:23 +0000
//
bool __fastcall BN_gcd(unsigned __int64 *a1, __int64 a2, __int64 a3, int32x2_t *a4)
{
__int64 v7; // x20
__int64 v8; // x19
int v9; // w22
__int64 v10; // x0
__int64 v12; // x0
_BOOL4 v13; // w19
BN_CTX_start((unsigned __int64)a4);
v7 = BN_CTX_get(a4);
v8 = BN_CTX_get(a4);
if ( !v8 || !v7 || !BN_copy((unsigned __int64 *)v7, a2) || !BN_copy((unsigned __int64 *)v8, a3) )
{
LABEL_16:
BN_CTX_end((__int64)a4);
return 0;
}
*(_DWORD *)(v7 + 16) = 0;
*(_DWORD *)(v8 + 16) = 0;
if ( (BN_cmp((__int64 *)v7, (__int64 *)v8) & 0x80000000) != 0 )
{
v12 = v7;
v7 = v8;
v8 = v12;
}
v9 = 0;
while ( !BN_is_zero(v8) )
{
if ( (unsigned int)BN_is_odd(v7) )
{
if ( (unsigned int)BN_is_odd(v8) )
{
if ( !(unsigned int)BN_sub(v7, v7, v8) )
goto LABEL_16;
LABEL_12:
if ( !(unsigned int)BN_rshift1(v7, v7) )
goto LABEL_16;
goto LABEL_13;
}
if ( !(unsigned int)BN_rshift1(v8, v8) )
goto LABEL_16;
LABEL_13:
if ( (BN_cmp((__int64 *)v7, (__int64 *)v8) & 0x80000000) != 0 )
{
v10 = v7;
v7 = v8;
v8 = v10;
}
}
else
{
if ( (unsigned int)BN_is_odd(v8) )
goto LABEL_12;
if ( !(unsigned int)BN_rshift1(v7, v7) || !(unsigned int)BN_rshift1(v8, v8) )
goto LABEL_16;
++v9;
}
}
if ( v9 && !(unsigned int)BN_lshift(v7, (__int64 *)v7, v9) )
goto LABEL_16;
v13 = BN_copy(a1, v7) != nullptr;
BN_CTX_end((__int64)a4);
return v13;
}