//
// ossl_ecdsa_sign_setup from 0x1012968 to 0x1012e20 (1208 bytes)
//
// 2 xrefs:
// > ??> @ 0x465d0
// > ??> @ 0x1539e60
//
// 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:03 +0000
//
__int64 __fastcall ossl_ecdsa_sign_setup(__int64 a1, __int64 a2, _BYTE **a3, _BYTE **a4)
{
__int64 *v8; // x21
_QWORD *v9; // x0
__int64 v10; // x1
__int64 v11; // x2
__int64 v12; // x23
_BYTE *v13; // x19
_BYTE *v14; // x24
_BYTE *v15; // x25
_QWORD *v16; // x26
__int64 v17; // x20
int v18; // w20
unsigned int v19; // w19
__int64 v21; // x0
__int64 mont_data; // x0
int v23; // [xsp+68h] [xbp+68h]
if ( a1 && (v8 = (__int64 *)EC_KEY_get0_group(a1)) != nullptr )
{
v9 = EC_KEY_can_sign(a1);
if ( (_DWORD)v9 )
{
v12 = a2;
if ( !a2 )
{
v12 = BN_CTX_new(v9, v10, v11);
if ( !v12 )
{
v19 = 0;
ERR_put_error(16, 248, 65, "crypto/ec/ecdsa_ossl.c", 57);
return v19;
}
}
v13 = (_BYTE *)BN_new();
v14 = (_BYTE *)BN_new();
v15 = (_BYTE *)BN_new();
if ( v14 == nullptr || v13 == nullptr || !v15 )
{
v16 = nullptr;
ERR_put_error(16, 248, 65, "crypto/ec/ecdsa_ossl.c", 67);
}
else
{
v16 = EC_POINT_new(v8);
if ( v16 )
{
v17 = EC_GROUP_get0_order((__int64)v8);
if ( v17 )
{
do
{
do
{
if ( !(unsigned int)BN_rand_range(v13) )
{
ERR_put_error(16, 248, 158, "crypto/ec/ecdsa_ossl.c", 94);
goto LABEL_14;
}
}
while ( BN_is_zero((__int64)v13) );
if ( !(unsigned int)BN_add(v13, v13, v17) )
goto LABEL_14;
v23 = BN_num_bits((__int64)v13);
if ( v23 <= (int)BN_num_bits(v17) && !(unsigned int)BN_add(v13, v13, v17) )
goto LABEL_14;
if ( !(unsigned int)EC_POINT_mul((__int64)v8) )
{
ERR_put_error(16, 248, 16, "crypto/ec/ecdsa_ossl.c", 113);
goto LABEL_14;
}
v21 = EC_GROUP_method_of((__int64)v8);
if ( (unsigned int)EC_METHOD_get_field_type(v21) == 406 )
{
if ( !(unsigned int)EC_POINT_get_affine_coordinates_GFp((__int64)v8, v16) )
{
ERR_put_error(16, 248, 16, "crypto/ec/ecdsa_ossl.c", 120);
goto LABEL_14;
}
}
else if ( !(unsigned int)EC_POINT_get_affine_coordinates_GF2m((__int64)v8, v16) )
{
ERR_put_error(16, 248, 16, "crypto/ec/ecdsa_ossl.c", 130);
goto LABEL_14;
}
if ( !(unsigned int)BN_nnmod(v14, v15, v17, v12) )
{
ERR_put_error(16, 248, 3, "crypto/ec/ecdsa_ossl.c", 136);
goto LABEL_14;
}
}
while ( BN_is_zero((__int64)v14) );
if ( EC_GROUP_get_mont_data((__int64)v8) )
{
if ( !(unsigned int)BN_set_word((__int64)v15, 2) )
{
ERR_put_error(16, 248, 3, "crypto/ec/ecdsa_ossl.c", 149);
goto LABEL_14;
}
if ( !(unsigned int)BN_mod_sub(v15, v17, v15, v17, v12) )
{
ERR_put_error(16, 248, 3, "crypto/ec/ecdsa_ossl.c", 153);
goto LABEL_14;
}
BN_set_flags((__int64)v15, 4);
mont_data = EC_GROUP_get_mont_data((__int64)v8);
if ( !(unsigned int)BN_mod_exp_mont_consttime(v13, v13, v15, v17, v12, mont_data) )
{
ERR_put_error(16, 248, 3, "crypto/ec/ecdsa_ossl.c", 159);
goto LABEL_14;
}
}
else if ( !BN_mod_inverse(v13, v13, v17, v12) )
{
ERR_put_error(16, 248, 3, "crypto/ec/ecdsa_ossl.c", 164);
goto LABEL_14;
}
v18 = 1;
BN_clear_free(*a4);
BN_clear_free(*a3);
*a4 = v14;
*a3 = v13;
goto LABEL_15;
}
ERR_put_error(16, 248, 16, "crypto/ec/ecdsa_ossl.c", 76);
}
else
{
ERR_put_error(16, 248, 16, "crypto/ec/ecdsa_ossl.c", 71);
}
}
LABEL_14:
v18 = 0;
BN_clear_free(v13);
BN_clear_free(v14);
LABEL_15:
if ( a2 != v12 )
BN_CTX_free(v12);
v19 = v18;
EC_POINT_free((__int64)v16);
BN_clear_free(v15);
return v19;
}
ERR_put_error(16, 248, 159, "crypto/ec/ecdsa_ossl.c", 51);
return 0;
}
else
{
ERR_put_error(16, 248, 67, "crypto/ec/ecdsa_ossl.c", 46);
return 0;
}
}