//
// ecdh_simple_compute_key from 0xa02228 to 0xa025a0 (888 bytes)
//
// 5 xrefs:
// > ??> @ 0x7b6bc
// > ??> @ 0xd16e3c
// > ??> @ 0xd16f00
// > ??> @ 0xd16fc4
// > ??> @ 0xd19708
//
// 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:38 +0000
//
int __fastcall ecdh_simple_compute_key(int ***a1, unsigned int *a2, int a3, int a4)
{
int v7; // r0
int v8; // r4
int **v9; // r8
int **v10; // r5
int *v11; // r7
_DWORD *v12; // r6
int v13; // r0
int degree; // r0
int v15; // r9
int v16; // r0
unsigned int v17; // r9
int v18; // r3
int v19; // r7
int v20; // r7
int **v22; // r0
v7 = BN_CTX_new();
v8 = v7;
if ( !v7 )
{
EC_POINT_free(0);
v10 = nullptr;
v20 = 0;
goto LABEL_17;
}
BN_CTX_start(v7);
v9 = (int **)BN_CTX_get(v8);
BN_CTX_get(v8);
v10 = (int **)EC_KEY_get0_private_key(a4);
if ( v10 )
{
v11 = (int *)EC_KEY_get0_group(a4);
if ( (EC_KEY_get_flags(a4) & 0x1000) == 0 || EC_GROUP_get_cofactor((int)v11, (int)v9) && BN_mul(v9, v9, v10, v8) )
{
v12 = EC_POINT_new(v11);
if ( v12 )
{
if ( EC_POINT_mul((int)v11) )
{
v13 = EC_GROUP_method_of((int)v11);
if ( EC_METHOD_get_field_type(v13) == 406 )
{
if ( EC_POINT_get_affine_coordinates_GFp((int)v11, v12) )
goto LABEL_8;
v10 = nullptr;
ERR_put_error(16, 257, 155, "crypto/ec/ecdh_ossl.c", 100);
v20 = 0;
}
else
{
if ( EC_POINT_get_affine_coordinates_GF2m((int)v11, v12) )
{
LABEL_8:
degree = EC_GROUP_get_degree((int)v11);
v15 = degree + 7;
if ( degree + 7 < 0 )
v15 = degree + 14;
v16 = BN_num_bits(v9);
v17 = v15 >> 3;
v18 = v16 + 7;
if ( v16 + 7 < 0 )
v18 = v16 + 14;
v19 = v18 >> 3;
if ( v17 >= v18 >> 3 )
{
v22 = (int **)CRYPTO_malloc(v17, "crypto/ec/ecdh_ossl.c", 119);
v10 = v22;
if ( v22 )
{
memset(v22, 0, v17 - v19);
if ( BN_bn2bin(v9, (_BYTE *)v10 + v17 - v19) == v19 )
{
*a1 = v10;
v20 = 1;
*a2 = v17;
v10 = nullptr;
}
else
{
ERR_put_error(16, 257, 3, "crypto/ec/ecdh_ossl.c", 126);
v20 = 0;
}
}
else
{
ERR_put_error(16, 257, 65, "crypto/ec/ecdh_ossl.c", 120);
v20 = 0;
}
}
else
{
v10 = nullptr;
ERR_put_error(16, 257, 68, "crypto/ec/ecdh_ossl.c", 116);
v20 = 0;
}
goto LABEL_16;
}
v10 = nullptr;
ERR_put_error(16, 257, 155, "crypto/ec/ecdh_ossl.c", 107);
v20 = 0;
}
}
else
{
v10 = nullptr;
ERR_put_error(16, 257, 155, "crypto/ec/ecdh_ossl.c", 93);
v20 = 0;
}
}
else
{
ERR_put_error(16, 257, 65, "crypto/ec/ecdh_ossl.c", 88);
v10 = nullptr;
v20 = 0;
}
}
else
{
ERR_put_error(16, 257, 65, "crypto/ec/ecdh_ossl.c", 81);
v10 = nullptr;
v20 = 0;
v12 = nullptr;
}
}
else
{
ERR_put_error(16, 257, 154, "crypto/ec/ecdh_ossl.c", 72);
v20 = 0;
v12 = nullptr;
}
LABEL_16:
EC_POINT_free((int)v12);
BN_CTX_end(v8);
LABEL_17:
BN_CTX_free(v8);
CRYPTO_free(v10, "crypto/ec/ecdh_ossl.c", 141);
return v20;
}