//
// ec_GFp_simple_point2oct from 0xa0728c to 0xa075c0 (820 bytes)
//
// 2 xrefs:
// > EC_POINT_point2oct @ 0xa01fb0
// > ??> @ 0x7b68c
//
// This function is hookable on this platform (idp: arm, 32 bit: True, 64 bit: False!
//
// 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 12:07:41 +0000
//
int __fastcall ec_GFp_simple_point2oct(int a1, _DWORD *a2, int a3, _BYTE *a4, unsigned int a5, int a6)
{
unsigned int v6; // r5
bool v7; // zf
int v9; // r11
int v14; // r0
int v15; // r8
unsigned int v16; // r8
unsigned int v17; // r10
char v18; // r3
int v19; // r0
int v20; // r5
size_t v21; // r5
int v22; // r5
unsigned int v23; // r7
int v24; // r0
int v25; // r0
int v26; // r4
size_t v27; // r4
_DWORD *v28; // [sp+8h] [bp-Ch]
_DWORD *v29; // [sp+Ch] [bp-8h]
v6 = a3 & 0xFFFFFFFB;
v7 = (a3 & 0xFFFFFFFB) == 2;
if ( (a3 & 0xFFFFFFFB) != 2 )
v7 = a3 == 4;
if ( !v7 )
{
ERR_put_error(16, 104, 104, "crypto/ec/ecp_oct.c", 172);
LABEL_6:
v9 = 0;
LABEL_7:
BN_CTX_free(v9);
return 0;
}
if ( !EC_POINT_is_at_infinity(a1, a2) )
{
v14 = BN_num_bits(*(_DWORD **)(a1 + 36));
v15 = v14 + 7;
if ( v14 + 7 < 0 )
v15 = v14 + 14;
v16 = v15 >> 3;
if ( a3 == 2 )
v17 = v16 + 1;
else
v17 = 2 * v16;
if ( a3 != 2 )
++v17;
if ( a4 )
{
if ( v17 > a5 )
{
ERR_put_error(16, 104, 100, "crypto/ec/ecp_oct.c", 197);
goto LABEL_6;
}
if ( a6 )
{
v9 = 0;
}
else
{
v24 = BN_CTX_new(v14);
a6 = v24;
if ( !v24 )
return 0;
v9 = v24;
}
BN_CTX_start(a6);
v28 = (_DWORD *)BN_CTX_get(a6);
v29 = (_DWORD *)BN_CTX_get(a6);
if ( !v29 || !EC_POINT_get_affine_coordinates_GFp(a1, a2) )
{
LABEL_37:
BN_CTX_end(a6);
goto LABEL_7;
}
if ( v6 == 2 && BN_is_odd((int)v29) )
v18 = a3 + 1;
else
v18 = a3;
*a4 = v18;
v19 = BN_num_bits(v28);
v20 = v19 + 7;
if ( v19 + 7 < 0 )
v20 = v19 + 14;
v21 = v16 - (v20 >> 3);
if ( v16 < v21 )
{
ERR_put_error(16, 104, 68, "crypto/ec/ecp_oct.c", 227);
goto LABEL_37;
}
if ( v21 )
{
memset(a4 + 1, 0, v21);
v22 = v21 + 1;
}
else
{
v22 = 1;
}
v23 = v16 + 1;
if ( v16 + 1 != BN_bn2bin(v28, &a4[v22]) + v22 )
{
ERR_put_error(16, 104, 68, "crypto/ec/ecp_oct.c", 237);
goto LABEL_37;
}
if ( (a3 & 0xFFFFFFFD) == 4 )
{
v25 = BN_num_bits(v29);
v26 = v25 + 7;
if ( v25 + 7 < 0 )
v26 = v25 + 14;
v27 = v16 - (v26 >> 3);
if ( v16 < v27 )
{
ERR_put_error(16, 104, 68, "crypto/ec/ecp_oct.c", 245);
goto LABEL_37;
}
if ( v27 )
{
memset(&a4[v23], 0, v27);
v23 += v27;
}
v23 += BN_bn2bin(v29, &a4[v23]);
}
if ( v23 != v17 )
{
ERR_put_error(16, 104, 68, "crypto/ec/ecp_oct.c", 257);
goto LABEL_37;
}
BN_CTX_end(a6);
}
else
{
v9 = 0;
}
BN_CTX_free(v9);
return v17;
}
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;
}
}