//
// DH_generate_parameters_ex from 0xe7c4d8 to 0xe7c6f8 (544 bytes)
//
// 2 xrefs:
// > sub_E29F44 @ 0xe2a044
// > ??> @ 0x62a18
//
// 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
//
__int64 __fastcall DH_generate_parameters_ex(_QWORD *a1, int a2, int a3, __int64 a4)
{
__int64 (*v4)(void); // x4
int32x2_t *v10; // x0
int32x2_t *v11; // x21
__int64 v12; // x24
__int64 v13; // x25
unsigned int v14; // w19
__int64 v15; // x0
__int64 v16; // x0
v4 = *(__int64 (**)(void))(a1[15] + 64LL);
if ( v4 )
return v4();
v10 = (int32x2_t *)BN_CTX_new();
v11 = v10;
if ( !v10 )
{
ERR_put_error(5, 106, 3, (__int64)"crypto/dh/dh_gen.c", 121);
return 0;
}
BN_CTX_start((unsigned __int64)v10);
v12 = BN_CTX_get(v11);
v13 = BN_CTX_get(v11);
if ( !v13 )
goto LABEL_20;
if ( !v12 )
goto LABEL_20;
if ( !a1[1] )
{
v15 = BN_new();
a1[1] = v15;
if ( !v15 )
goto LABEL_20;
}
if ( !a1[2] )
{
v16 = BN_new();
a1[2] = v16;
if ( !v16 )
goto LABEL_20;
}
if ( a3 <= 1 )
{
v14 = 0;
ERR_put_error(5, 106, 101, (__int64)"crypto/dh/dh_gen.c", 81);
ERR_put_error(5, 106, 3, (__int64)"crypto/dh/dh_gen.c", 121);
goto LABEL_21;
}
if ( a3 == 2 )
{
if ( !(unsigned int)BN_set_word(v12, 24) || !(unsigned int)BN_set_word(v13, 11) )
goto LABEL_20;
}
else if ( a3 == 5 )
{
if ( !(unsigned int)BN_set_word(v12, 10) || !(unsigned int)BN_set_word(v13, 3) )
goto LABEL_20;
}
else if ( !(unsigned int)BN_set_word(v12, 2) || !(unsigned int)BN_set_word(v13, 1) )
{
goto LABEL_20;
}
if ( !(unsigned int)BN_generate_prime_ex((_DWORD *)a1[1], a2, 1, v12, v13, a4)
|| !(unsigned int)BN_GENCB_call(a4, 3u, 0)
|| !(unsigned int)BN_set_word(a1[2], a3) )
{
LABEL_20:
v14 = 0;
ERR_put_error(5, 106, 3, (__int64)"crypto/dh/dh_gen.c", 121);
goto LABEL_21;
}
v14 = 1;
LABEL_21:
BN_CTX_end((__int64)v11);
BN_CTX_free((void **)v11);
return v14;
}