//
// ec_GFp_simple_points_make_affine from 0x7f4cf4 to 0x7f51e8 (1268 bytes)
//
// 4 xrefs:
// > ??> @ 0x61f5c
// > ??> @ 0xab2718
// > ??> @ 0xab27dc
// > ??> @ 0xab28a0
//
// 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 ec_GFp_simple_points_make_affine(_DWORD *a1, int a2, _DWORD *a3, int a4)
{
bool v6; // zf
int v7; // r5
int v9; // r11
int v10; // r0
bool v11; // zf
int v12; // r6
int v13; // r0
int ***v14; // r9
int v15; // r8
int v16; // r0
int v17; // r8
int **v18; // r0
int ***v19; // r7
int v20; // r6
int **v21; // t1
int v22; // r0
int (__fastcall *v23)(_DWORD *, int **, int); // r3
_DWORD *v24; // r10
int *v25; // r6
int v26; // r8
int v27; // t1
int (__fastcall *v28)(_DWORD *, int, int, int); // r12
int v29; // r10
int ***v30; // r8
_DWORD *v31; // r6
int v32; // t1
int v33; // r8
_DWORD *v34; // r10
int v35; // r6
int v36; // t1
int (__fastcall *v37)(_DWORD *, _DWORD, int); // r3
int v38; // [sp+8h] [bp-14h]
int v40; // [sp+10h] [bp-Ch]
int v41; // [sp+14h] [bp-8h]
if ( !a2 )
return 1;
v6 = a4 == 0;
v7 = a4;
if ( a4 )
a4 = 0;
if ( v6 )
{
v22 = BN_CTX_new(a1);
v7 = v22;
if ( !v22 )
return 0;
v38 = v22;
}
else
{
v38 = a4;
}
BN_CTX_start(v7);
v9 = BN_CTX_get(v7);
v10 = BN_CTX_get(v7);
v11 = v9 == 0;
if ( v9 )
v11 = v10 == 0;
v40 = v10;
if ( v11
|| (v12 = 0, v41 = a2, v13 = CRYPTO_malloc(4 * a2, "crypto/ec/ecp_smpl.c", 1224), (v14 = (int ***)v13) == nullptr) )
{
BN_CTX_end(v7);
BN_CTX_free(v38);
return 0;
}
else
{
v15 = v13 - 4;
do
{
v16 = BN_new();
++v12;
*(_DWORD *)(v15 + 4) = v16;
v15 += 4;
if ( !v16 )
goto LABEL_17;
}
while ( v12 != a2 );
if ( BN_is_zero(*(_DWORD *)(*a3 + 12)) )
{
v23 = *(int (__fastcall **)(_DWORD *, int **, int))(*a1 + 156);
if ( v23 )
{
if ( !v23(a1, *v14, v7) )
goto LABEL_17;
}
else if ( !BN_set_word(*v14, 1) )
{
goto LABEL_17;
}
}
else if ( !BN_copy((int)*v14, *(_DWORD *)(*a3 + 12)) )
{
goto LABEL_17;
}
if ( a2 != 1 )
{
v24 = a3;
v25 = (int *)v14;
v26 = 1;
do
{
v27 = v24[1];
++v24;
++v26;
if ( BN_is_zero(*(_DWORD *)(v27 + 12)) )
{
if ( !BN_copy(v25[1], *v25) )
goto LABEL_17;
}
else if ( !(*(int (__fastcall **)(_DWORD *, int, int, _DWORD, int))(*a1 + 136))(
a1,
v25[1],
*v25,
*(_DWORD *)(*v24 + 12),
v7) )
{
goto LABEL_17;
}
++v25;
}
while ( v26 != a2 );
}
v17 = BN_mod_inverse(v9, v14[v41 - 1], a1[9], v7);
if ( v17 )
{
v28 = *(int (__fastcall **)(_DWORD *, int, int, int))(*a1 + 148);
if ( v28
&& (!v28(a1, v9, v9, v7) || !(*(int (__fastcall **)(_DWORD *, int, int, int))(*a1 + 148))(a1, v9, v9, v7)) )
{
goto LABEL_17;
}
v29 = a2 - 1;
if ( a2 != 1 )
{
v30 = &v14[v41 - 2];
v31 = &a3[a2];
do
{
v32 = *--v31;
if ( !BN_is_zero(*(_DWORD *)(v32 + 12))
&& (!(*(int (__fastcall **)(_DWORD *, int, int **, int, int))(*a1 + 136))(a1, v40, *v30, v9, v7)
|| !(*(int (__fastcall **)(_DWORD *, int, int, _DWORD, int))(*a1 + 136))(
a1,
v9,
v9,
*(_DWORD *)(*v31 + 12),
v7)
|| !BN_copy(*(_DWORD *)(*v31 + 12), v40)) )
{
goto LABEL_17;
}
--v29;
--v30;
}
while ( v29 );
}
if ( !BN_is_zero(*(_DWORD *)(*a3 + 12)) && !BN_copy(*(_DWORD *)(*a3 + 12), v9) )
{
LABEL_17:
v17 = 0;
goto LABEL_18;
}
v33 = 0;
v34 = a3 - 1;
do
{
v36 = v34[1];
++v34;
v35 = v36;
if ( !BN_is_zero(*(_DWORD *)(v36 + 12)) )
{
if ( !(*(int (__fastcall **)(_DWORD *, int, _DWORD, int))(*a1 + 140))(a1, v9, *(_DWORD *)(v35 + 12), v7)
|| !(*(int (__fastcall **)(_DWORD *, _DWORD, _DWORD, int, int))(*a1 + 136))(
a1,
*(_DWORD *)(v35 + 4),
*(_DWORD *)(v35 + 4),
v9,
v7)
|| !(*(int (__fastcall **)(_DWORD *, int, int, _DWORD, int))(*a1 + 136))(
a1,
v9,
v9,
*(_DWORD *)(v35 + 12),
v7)
|| !(*(int (__fastcall **)(_DWORD *, _DWORD, _DWORD, int, int))(*a1 + 136))(
a1,
*(_DWORD *)(v35 + 8),
*(_DWORD *)(v35 + 8),
v9,
v7) )
{
goto LABEL_17;
}
v37 = *(int (__fastcall **)(_DWORD *, _DWORD, int))(*a1 + 156);
if ( v37 )
{
if ( !v37(a1, *(_DWORD *)(v35 + 12), v7) )
goto LABEL_17;
}
else if ( !BN_set_word(*(int ***)(v35 + 12), 1) )
{
goto LABEL_17;
}
*(_DWORD *)(v35 + 16) = 1;
}
++v33;
}
while ( v33 != a2 );
v17 = 1;
}
else
{
ERR_put_error(16, 137, 3, "crypto/ec/ecp_smpl.c", 1269);
}
LABEL_18:
BN_CTX_end(v7);
BN_CTX_free(v38);
v18 = *v14;
if ( *v14 )
{
v19 = v14;
v20 = 0;
do
{
++v20;
BN_clear_free(v18);
if ( v20 == a2 )
break;
v21 = v19[1];
++v19;
v18 = v21;
}
while ( v21 );
}
CRYPTO_free(v14, "crypto/ec/ecp_smpl.c", 1354);
return v17;
}
}