//
// ec_GFp_simple_point2oct from 0x1016cf8 to 0x1017058 (864 bytes)
//
// 2 xrefs:
// > EC_POINT_point2oct @ 0x10122ec
// > ??> @ 0x907f0
//
// This function is hookable on this platform (idp: arm, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 13:16:05 +0000
//
__int64 __fastcall ec_GFp_simple_point2oct(__int64 a1, _QWORD *a2, int a3, _BYTE *a4, unsigned __int64 a5, __int64 a6)
{
unsigned int v6; // w22
__int64 v13; // x19
__int64 result; // x0
__int64 v15; // x2
bool v16; // nf
unsigned int v17; // w1
__int64 v18; // x0
__int64 v19; // x1
size_t v20; // x27
unsigned __int64 v21; // x26
_QWORD *v22; // x28
char v23; // w0
int v24; // w0
int v25; // w1
int v26; // w0
size_t v27; // x2
__int64 v28; // x22
size_t v29; // x23
int v30; // w0
int v31; // w1
int v32; // w0
size_t v33; // x2
_BYTE *v34; // x0
_QWORD *v35; // [xsp+68h] [xbp+68h]
v6 = a3 & 0xFFFFFFFB;
if ( (a3 & 0xFFFFFFFB) != 2 && a3 != 4 )
{
ERR_put_error(16, 104, 104, "crypto/ec/ecp_oct.c", 172);
LABEL_4:
v13 = 0;
LABEL_5:
BN_CTX_free(v13);
return 0;
}
if ( !(unsigned int)EC_POINT_is_at_infinity(a1, a2) )
{
LODWORD(v18) = BN_num_bits(*(_QWORD *)(a1 + 64));
v17 = v18 + 7;
v16 = (int)v18 + 7 < 0;
LODWORD(v18) = v18 + 14;
if ( v16 )
v18 = (unsigned int)v18;
else
v18 = v17;
v19 = (unsigned int)((int)v18 >> 3);
v20 = (int)v19;
if ( a3 == 2 )
{
v21 = (int)v19 + 1LL;
}
else
{
v18 = 1;
v21 = 2LL * (int)v19 + 1;
}
if ( a4 )
{
if ( v21 > a5 )
{
ERR_put_error(16, 104, 100, "crypto/ec/ecp_oct.c", 197);
goto LABEL_4;
}
v13 = 0;
if ( !a6 )
{
result = BN_CTX_new(v18, v19, v15);
a6 = result;
if ( !result )
return result;
v13 = result;
}
BN_CTX_start(a6);
v35 = (_QWORD *)BN_CTX_get(a6);
v22 = (_QWORD *)BN_CTX_get(a6);
if ( !v22 || !(unsigned int)EC_POINT_get_affine_coordinates_GFp(a1, a2) )
{
LABEL_20:
BN_CTX_end(a6);
goto LABEL_5;
}
if ( v6 == 2 && (unsigned int)BN_is_odd((__int64)v22) )
v23 = a3 + 1;
else
v23 = a3;
*a4 = v23;
v24 = BN_num_bits((__int64)v35);
v25 = v24 + 14;
v26 = v24 + 7;
if ( v26 >= 0 )
v25 = v26;
v27 = v20 - (v25 >> 3);
if ( v20 < v27 )
{
ERR_put_error(16, 104, 68, "crypto/ec/ecp_oct.c", 227);
goto LABEL_20;
}
v28 = 1;
if ( v27 )
{
v28 = v27 + 1;
memset(a4 + 1, 0, v27);
}
v29 = v20 + 1;
if ( v20 + 1 != v28 + (int)BN_bn2bin(v35, &a4[v28]) )
{
ERR_put_error(16, 104, 68, "crypto/ec/ecp_oct.c", 237);
goto LABEL_20;
}
if ( (a3 & 0xFFFFFFFD) == 4 )
{
v30 = BN_num_bits((__int64)v22);
v31 = v30 + 7;
v16 = v30 + 7 < 0;
v32 = v30 + 14;
if ( !v16 )
v32 = v31;
v33 = v20 - (v32 >> 3);
if ( v20 < v33 )
{
ERR_put_error(16, 104, 68, "crypto/ec/ecp_oct.c", 245);
goto LABEL_20;
}
if ( v33 )
{
v34 = &a4[v29];
v29 += v33;
memset(v34, 0, v33);
}
v29 += (int)BN_bn2bin(v22, &a4[v29]);
}
if ( v29 != v21 )
{
ERR_put_error(16, 104, 68, "crypto/ec/ecp_oct.c", 257);
goto LABEL_20;
}
BN_CTX_end(a6);
}
else
{
v13 = 0;
}
BN_CTX_free(v13);
return v21;
}
if ( !a4 )
return 1;
if ( a5 )
{
*a4 = 0;
return 1;
}
else
{
ERR_put_error(16, 104, 100, "crypto/ec/ecp_oct.c", 180);
return 0;
}
}