//
// DH_generate_parameters_ex from 0x8d08a0 to 0x8d0ae0 (576 bytes)
//
// 2 xrefs:
// > sub_87FC88 @ 0x87fd68
// > ??> @ 0x6a7bc
//
// 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
//
int __fastcall DH_generate_parameters_ex(int a1, int a2, int a3, _DWORD *a4)
{
int (*v4)(void); // r12
int ***v10; // r0
int ***v11; // r8
int **v12; // r9
int **v13; // r0
bool v14; // zf
int **v15; // r10
int v16; // r4
int v17; // r0
int v18; // r0
v4 = *(int (**)(void))(*(_DWORD *)(a1 + 64) + 32);
if ( v4 )
return v4();
v10 = (int ***)BN_CTX_new();
v11 = v10;
if ( !v10 )
{
ERR_put_error(5, 106, 3, (int)"crypto/dh/dh_gen.c", 121);
return 0;
}
BN_CTX_start((int)v10);
v12 = BN_CTX_get(v11);
v13 = BN_CTX_get(v11);
v14 = v12 == nullptr;
if ( v12 )
v14 = v13 == nullptr;
v15 = v13;
if ( v14 )
goto LABEL_21;
if ( !*(_DWORD *)(a1 + 8) )
{
v17 = BN_new();
*(_DWORD *)(a1 + 8) = v17;
if ( !v17 )
goto LABEL_21;
}
if ( !*(_DWORD *)(a1 + 12) )
{
v18 = BN_new();
*(_DWORD *)(a1 + 12) = v18;
if ( !v18 )
goto LABEL_21;
}
if ( a3 <= 1 )
{
ERR_put_error(5, 106, 101, (int)"crypto/dh/dh_gen.c", 81);
ERR_put_error(5, 106, 3, (int)"crypto/dh/dh_gen.c", 121);
v16 = 0;
goto LABEL_22;
}
if ( a3 == 2 )
{
if ( !BN_set_word(v12, 24) || !BN_set_word(v15, 11) )
goto LABEL_21;
}
else if ( a3 == 5 )
{
if ( !BN_set_word(v12, 10) || !BN_set_word(v15, 3) )
goto LABEL_21;
}
else if ( !BN_set_word(v12, 2) || !BN_set_word(v15, 1) )
{
goto LABEL_21;
}
if ( !BN_generate_prime_ex(*(int **)(a1 + 8), a2, 1, (int *)v12, (int *)v15, a4)
|| !BN_GENCB_call(a4, 3, 0)
|| !BN_set_word(*(int ***)(a1 + 12), a3) )
{
LABEL_21:
ERR_put_error(5, 106, 3, (int)"crypto/dh/dh_gen.c", 121);
v16 = 0;
goto LABEL_22;
}
v16 = 1;
LABEL_22:
BN_CTX_end(v11);
BN_CTX_free((void **)v11);
return v16;
}