//
// sub_1005CF0 from 0x1005cf0 to 0x1005f04 (532 bytes)
//
// 1 xrefs:
// > ??> @ 0x1551c78
//
// 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:15:56 +0000
//
__int64 __fastcall sub_1005CF0(__int64 a1)
{
__int64 v2; // x22
__int64 *v3; // x19
int v4; // w23
__int64 v5; // x21
__int64 v6; // x24
__int64 v8; // x0
__int64 v9; // x23
__int64 v10; // x1
v2 = BN_CTX_new();
if ( !v2 )
goto LABEL_27;
v3 = *(__int64 **)(a1 + 40);
v4 = 0;
if ( v3 )
goto LABEL_3;
v3 = (__int64 *)BN_secure_new();
if ( !v3 )
{
LABEL_27:
v3 = nullptr;
v5 = 0;
goto LABEL_10;
}
v4 = 1;
LABEL_3:
v5 = *(_QWORD *)(a1 + 32);
if ( !v5 )
{
v5 = BN_new();
if ( !v5 )
goto LABEL_10;
}
v6 = 0;
if ( (*(_DWORD *)(a1 + 48) & 1) != 0 )
{
v6 = BN_MONT_CTX_set_locked((__int64 *)(a1 + 56), *(_QWORD *)(a1 + 136), *(_QWORD ***)(a1 + 8), v2);
if ( !v6 )
goto LABEL_10;
}
if ( v4 )
{
if ( *(_QWORD *)(a1 + 64) )
{
if ( !(unsigned int)BN_rand_range(v3) )
goto LABEL_10;
while ( BN_is_zero((__int64)v3) || (unsigned int)BN_is_one((__int64)v3) )
{
if ( !(unsigned int)BN_rand_range(v3) )
goto LABEL_10;
}
}
else
{
v10 = *(_QWORD *)(a1 + 24);
if ( !v10 )
v10 = (unsigned int)BN_num_bits(*(_QWORD *)(a1 + 8)) - 1;
if ( !(unsigned int)BN_rand(v3, v10, 0, 0) )
goto LABEL_10;
}
}
v8 = BN_new();
v9 = v8;
if ( v8 )
{
BN_with_flags(v8, v3, 4);
if ( (*(unsigned int (__fastcall **)(__int64, __int64, _QWORD, __int64, _QWORD, __int64, __int64))(*(_QWORD *)(a1 + 120) + 24LL))(
a1,
v5,
*(_QWORD *)(a1 + 16),
v9,
*(_QWORD *)(a1 + 8),
v2,
v6) )
{
BN_free(v9);
*(_QWORD *)(a1 + 32) = v5;
*(_QWORD *)(a1 + 40) = v3;
BN_CTX_free(v2);
return 1;
}
BN_free(v9);
}
LABEL_10:
ERR_put_error(5, 103, 3, "crypto/dh/dh_key.c", 134);
if ( *(_QWORD *)(a1 + 32) != v5 )
BN_free(v5);
if ( *(__int64 **)(a1 + 40) != v3 )
BN_free((__int64)v3);
BN_CTX_free(v2);
return 0;
}