//
// ec_GFp_simple_oct2point from 0xd98cf8 to 0xd99048 (848 bytes)
//
// 2 xrefs:
// > EC_POINT_oct2point @ 0xd94080
// > ??> @ 0xa57b0
//
// 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_oct2point(__int64 a1, _QWORD *a2, unsigned __int8 *a3, __int64 a4, __int64 a5)
{
int v10; // w5
unsigned int v11; // w25
unsigned int v12; // w19
__int64 result; // x0
int v14; // w0
__int64 v15; // x1
int v16; // w2
__int64 v17; // x0
int v18; // w20
__int64 v19; // x2
__int64 v20; // d8
__int64 *v21; // x28
__int64 *v22; // x21
_BOOL4 v23; // w19
if ( !a4 )
{
ERR_put_error(16, 103, 100, "crypto/ec/ecp_oct.c", 285);
return 0;
}
v10 = *a3;
v11 = v10 & 1;
v12 = v10 & 0xFFFFFFFE;
if ( (v10 & 0xF8) != 0 )
{
ERR_put_error(16, 103, 102, "crypto/ec/ecp_oct.c", 294);
return 0;
}
if ( (v10 & 0xFFFFFFFA) != 0 )
goto LABEL_5;
if ( (v10 & 1) != 0 )
{
ERR_put_error(16, 103, 102, "crypto/ec/ecp_oct.c", 298);
return 0;
}
if ( v12 )
{
LABEL_5:
v14 = BN_num_bits(*(_QWORD *)(a1 + 64));
v16 = v14 + 14;
v17 = (unsigned int)(v14 + 7);
if ( (int)v17 >= 0 )
v16 = v17;
v18 = v16 >> 3;
if ( v12 == 2 )
v19 = v18 + 1LL;
else
v19 = 2LL * v18 + 1;
if ( v19 != a4 )
{
ERR_put_error(16, 103, 102, "crypto/ec/ecp_oct.c", 317);
return 0;
}
v20 = 0;
if ( !a5 )
{
result = BN_CTX_new(v17, v15, v19);
a5 = result;
if ( !result )
return result;
v20 = result;
}
BN_CTX_start(a5);
v21 = (__int64 *)BN_CTX_get(a5);
v22 = (__int64 *)BN_CTX_get(a5);
if ( v22 && BN_bin2bn(a3 + 1, v18, (__int64)v21) )
{
if ( (BN_ucmp(v21, *(__int64 **)(a1 + 64)) & 0x80000000) == 0 )
{
v23 = 0;
ERR_put_error(16, 103, 102, "crypto/ec/ecp_oct.c", 336);
LABEL_24:
BN_CTX_end(a5);
BN_CTX_free(v20);
return v23;
}
if ( v12 == 2 )
{
v23 = EC_POINT_set_compressed_coordinates_GFp(a1, a2, (__int64)v21, v11, a5) != 0;
goto LABEL_24;
}
if ( BN_bin2bn(&a3[v18 + 1], v18, (__int64)v22) )
{
if ( (BN_ucmp(v22, *(__int64 **)(a1 + 64)) & 0x80000000) != 0 )
{
if ( v12 != 6 || (unsigned int)BN_is_odd((__int64)v22) == v11 )
{
v23 = EC_POINT_set_affine_coordinates_GFp(a1, a2) != 0;
}
else
{
v23 = 0;
ERR_put_error(16, 103, 102, "crypto/ec/ecp_oct.c", 353);
}
}
else
{
v23 = 0;
ERR_put_error(16, 103, 102, "crypto/ec/ecp_oct.c", 348);
}
goto LABEL_24;
}
}
v23 = 0;
goto LABEL_24;
}
if ( a4 == 1 )
return EC_POINT_set_to_infinity(a1, a2);
ERR_put_error(16, 103, 102, "crypto/ec/ecp_oct.c", 304);
return 0;
}