//
// ec_GFp_simple_group_check_discriminant from 0x7f318c to 0x7f33b8 (556 bytes)
//
// 4 xrefs:
// > ??> @ 0x61e4c
// > ??> @ 0xab26c8
// > ??> @ 0xab278c
// > ??> @ 0xab2850
//
// 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
//
bool __fastcall ec_GFp_simple_group_check_discriminant(_DWORD *a1, int a2)
{
int v2; // r4
int v4; // r9
int v5; // r7
int v6; // r6
int v7; // r8
_DWORD *v8; // r10
int *v9; // r11
int (__fastcall *v10)(_DWORD *, int, _DWORD, int); // r12
_BOOL4 v11; // r5
int v13; // r0
v2 = a2;
v4 = a1[9];
if ( a2 )
{
v5 = 0;
}
else
{
v13 = BN_CTX_new(a1);
v2 = v13;
if ( !v13 )
{
v5 = 0;
ERR_put_error(16, 165, 65, "crypto/ec/ecp_smpl.c", 253);
v11 = 0;
goto LABEL_9;
}
v5 = v13;
}
BN_CTX_start(v2);
v6 = BN_CTX_get(v2);
v7 = BN_CTX_get(v2);
v8 = (_DWORD *)BN_CTX_get(v2);
v9 = (int *)BN_CTX_get(v2);
if ( !BN_CTX_get(v2) )
goto LABEL_7;
v10 = *(int (__fastcall **)(_DWORD *, int, _DWORD, int))(*a1 + 152);
if ( v10 )
{
if ( !v10(a1, v6, a1[16], v2)
|| !(*(int (__fastcall **)(_DWORD *, int, _DWORD, int))(*a1 + 152))(a1, v7, a1[17], v2) )
{
goto LABEL_7;
}
}
else if ( !BN_copy(v6, a1[16]) || !BN_copy(v7, a1[17]) )
{
goto LABEL_7;
}
if ( BN_is_zero(v6) )
{
v11 = !BN_is_zero(v7);
goto LABEL_8;
}
if ( BN_is_zero(v7) )
{
v11 = 1;
goto LABEL_8;
}
if ( BN_mod_sqr(v8, v6, v4, v2)
&& BN_mod_mul(v9, v8, v6, v4, v2)
&& BN_lshift(v8, v9, 2)
&& BN_mod_sqr(v9, v7, v4, v2)
&& BN_mul_word((int **)v9, 27)
&& BN_mod_add(v6, v8, v9, v4, v2) )
{
v11 = !BN_is_zero(v6);
goto LABEL_8;
}
LABEL_7:
v11 = 0;
LABEL_8:
BN_CTX_end(v2);
LABEL_9:
BN_CTX_free(v5);
return v11;
}