//
// ec_GFp_simple_points_make_affine from 0xd9aef8 to 0xd9b370 (1144 bytes)
//
// 4 xrefs:
// > ??> @ 0x87c00
// > ??> @ 0x12221e0
// > ??> @ 0x1222360
// > ??> @ 0x12224e0
//
// 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 ec_GFp_simple_points_make_affine(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v7; // x22
__int64 result; // x0
__int64 v9; // x26
__int64 v10; // x27
__int64 v11; // x28
__int64 *v12; // x21
__int64 v13; // x19
__int64 v14; // x0
unsigned int v15; // w23
__int64 v16; // x19
_BYTE *v17; // x0
unsigned int (__fastcall *v18)(_QWORD *, __int64, __int64); // x3
unsigned __int64 **v19; // x23
__int64 i; // x19
__int64 v21; // x0
unsigned int (__fastcall *v22)(_QWORD *, __int64, __int64, __int64); // x4
__int64 v23; // x19
__int64 *v24; // x23
__int64 v25; // x19
__int64 v26; // x23
unsigned int (__fastcall *v27)(_QWORD *, _QWORD, __int64); // x3
v7 = a4;
result = 1;
if ( a2 )
{
v9 = 0;
if ( !a4 )
{
result = BN_CTX_new(1, a2, a3);
v7 = result;
if ( !result )
return result;
v9 = result;
}
BN_CTX_start(v7);
v10 = BN_CTX_get(v7);
v11 = BN_CTX_get(v7);
if ( v11 && v10 && (v12 = (__int64 *)CRYPTO_malloc(8 * a2, "crypto/ec/ecp_smpl.c", 1224)) != nullptr )
{
v13 = 0;
do
{
v14 = BN_new();
v12[v13++] = v14;
if ( !v14 )
goto LABEL_11;
}
while ( v13 != a2 );
if ( BN_is_zero(*(_QWORD *)(*(_QWORD *)a3 + 24LL)) )
{
v18 = *(unsigned int (__fastcall **)(_QWORD *, __int64, __int64))(*a1 + 304LL);
if ( v18 )
{
if ( !v18(a1, *v12, v7) )
goto LABEL_11;
}
else if ( !(unsigned int)BN_set_word(*v12, 1) )
{
goto LABEL_11;
}
}
else if ( !BN_copy((unsigned __int64 *)*v12, *(_QWORD *)(*(_QWORD *)a3 + 24LL)) )
{
goto LABEL_11;
}
v19 = (unsigned __int64 **)(v12 + 1);
for ( i = 1; i != a2; ++v19 )
{
if ( BN_is_zero(*(_QWORD *)(*(_QWORD *)(a3 + 8 * i) + 24LL)) )
{
if ( !BN_copy(*v19, (__int64)*(v19 - 1)) )
goto LABEL_11;
}
else if ( !(*(unsigned int (__fastcall **)(_QWORD *, unsigned __int64 *, _QWORD, _QWORD, __int64))(*a1 + 264LL))(
a1,
*v19,
*(v19 - 1),
*(_QWORD *)(*(_QWORD *)(a3 + 8 * i) + 24LL),
v7) )
{
goto LABEL_11;
}
++i;
}
v21 = BN_mod_inverse(v10, v12[a2 - 1], a1[8], v7);
v15 = v21;
if ( v21 )
{
v22 = *(unsigned int (__fastcall **)(_QWORD *, __int64, __int64, __int64))(*a1 + 288LL);
if ( v22
&& (!v22(a1, v10, v10, v7)
|| !(*(unsigned int (__fastcall **)(_QWORD *, __int64, __int64, __int64))(*a1 + 288LL))(a1, v10, v10, v7)) )
{
goto LABEL_11;
}
v23 = a2 - 1;
v24 = &v12[a2];
if ( a2 != 1 )
{
while ( BN_is_zero(*(_QWORD *)(*(_QWORD *)(a3 + 8 * v23) + 24LL))
|| (*(unsigned int (__fastcall **)(_QWORD *, __int64, _QWORD, __int64, __int64))(*a1 + 264LL))(
a1,
v11,
*(v24 - 2),
v10,
v7)
&& (*(unsigned int (__fastcall **)(_QWORD *, __int64, __int64, _QWORD, __int64))(*a1 + 264LL))(
a1,
v10,
v10,
*(_QWORD *)(*(_QWORD *)(a3 + 8 * v23) + 24LL),
v7)
&& BN_copy(*(unsigned __int64 **)(*(_QWORD *)(a3 + 8 * v23) + 24LL), v11) )
{
--v23;
--v24;
if ( !v23 )
goto LABEL_46;
}
goto LABEL_11;
}
LABEL_46:
if ( !BN_is_zero(*(_QWORD *)(*(_QWORD *)a3 + 24LL))
&& !BN_copy(*(unsigned __int64 **)(*(_QWORD *)a3 + 24LL), v10) )
{
LABEL_11:
v15 = 0;
goto LABEL_12;
}
v25 = 0;
do
{
v26 = *(_QWORD *)(a3 + 8 * v25);
if ( !BN_is_zero(*(_QWORD *)(v26 + 24)) )
{
if ( !(*(unsigned int (__fastcall **)(_QWORD *, __int64, _QWORD, __int64))(*a1 + 272LL))(
a1,
v10,
*(_QWORD *)(v26 + 24),
v7)
|| !(*(unsigned int (__fastcall **)(_QWORD *, _QWORD, _QWORD, __int64, __int64))(*a1 + 264LL))(
a1,
*(_QWORD *)(v26 + 8),
*(_QWORD *)(v26 + 8),
v10,
v7)
|| !(*(unsigned int (__fastcall **)(_QWORD *, __int64, __int64, _QWORD, __int64))(*a1 + 264LL))(
a1,
v10,
v10,
*(_QWORD *)(v26 + 24),
v7)
|| !(*(unsigned int (__fastcall **)(_QWORD *, _QWORD, _QWORD, __int64, __int64))(*a1 + 264LL))(
a1,
*(_QWORD *)(v26 + 16),
*(_QWORD *)(v26 + 16),
v10,
v7) )
{
goto LABEL_11;
}
v27 = *(unsigned int (__fastcall **)(_QWORD *, _QWORD, __int64))(*a1 + 304LL);
if ( v27 )
{
if ( !v27(a1, *(_QWORD *)(v26 + 24), v7) )
goto LABEL_11;
*(_DWORD *)(v26 + 32) = 1;
}
else
{
if ( !(unsigned int)BN_set_word(*(_QWORD *)(v26 + 24), 1) )
goto LABEL_11;
*(_DWORD *)(v26 + 32) = 1;
}
}
++v25;
}
while ( v25 != a2 );
v15 = 1;
}
else
{
ERR_put_error(16, 137, 3, "crypto/ec/ecp_smpl.c", 1269);
}
LABEL_12:
v16 = 0;
BN_CTX_end(v7);
BN_CTX_free(v9);
v17 = (_BYTE *)*v12;
if ( *v12 )
{
do
{
++v16;
BN_clear_free(v17);
if ( v16 == a2 )
break;
v17 = (_BYTE *)v12[v16];
}
while ( v17 );
}
CRYPTO_free(v12, "crypto/ec/ecp_smpl.c", 1354);
return v15;
}
else
{
BN_CTX_end(v7);
BN_CTX_free(v9);
return 0;
}
}
return result;
}