//
// ossl_ecdsa_sign_sig from 0x1012e20 to 0x10136c0 (2208 bytes)
//
// 2 xrefs:
// > ??> @ 0xe9968
// > ??> @ 0x1539e68
//
// 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
//
unsigned __int64 **__fastcall ossl_ecdsa_sign_sig(_BYTE *a1, int a2, _BYTE *a3, __int64 a4, __int64 a5)
{
__int64 v10; // x19
__int64 v11; // d10
unsigned __int64 **v12; // x20
__int64 v13; // x0
__int64 v14; // x1
__int64 v15; // x2
__int64 v16; // x23
__int64 v17; // x22
_BYTE *v18; // x27
_BYTE *v19; // d9
__int64 v20; // x0
__int64 v21; // x28
int v22; // w0
int v23; // w19
_BYTE *v24; // d13
_BYTE *v25; // x19
__int64 v26; // x2
_BYTE *v27; // d8
__int64 v28; // x26
__int64 v29; // x0
unsigned __int64 **v30; // x0
int v32; // w0
int v33; // w1
__int64 v34; // x0
_BYTE *v35; // x0
__int64 mont_data; // x0
int v37; // [xsp+A0h] [xbp+A0h]
_QWORD *v38; // [xsp+A8h] [xbp+A8h]
unsigned __int64 *v39; // [xsp+B0h] [xbp+B0h]
__int64 *v40; // [xsp+B8h] [xbp+B8h]
v10 = EC_KEY_get0_group(a5);
v11 = EC_KEY_get0_private_key(a5);
if ( !v11 || !v10 )
{
ERR_put_error(16, 249, 67, "crypto/ec/ecdsa_ossl.c", 210);
return nullptr;
}
if ( !(unsigned int)EC_KEY_can_sign(a5) )
{
ERR_put_error(16, 249, 159, "crypto/ec/ecdsa_ossl.c", 215);
return nullptr;
}
v12 = (unsigned __int64 **)ECDSA_SIG_new();
if ( !v12 )
{
ERR_put_error(16, 249, 65, "crypto/ec/ecdsa_ossl.c", 221);
return nullptr;
}
*v12 = (unsigned __int64 *)BN_new();
v13 = BN_new();
v12[1] = (unsigned __int64 *)v13;
v16 = v13;
if ( !v13 || !*v12 )
{
v24 = nullptr;
v17 = 0;
v18 = nullptr;
ERR_put_error(16, 249, 65, "crypto/ec/ecdsa_ossl.c", 227);
v19 = nullptr;
goto LABEL_31;
}
v17 = BN_CTX_new(*v12, v14, v15);
if ( !v17 || (v18 = (_BYTE *)BN_new()) == nullptr )
{
v18 = nullptr;
goto LABEL_30;
}
v19 = (_BYTE *)BN_new();
if ( !v19 )
{
LABEL_30:
v24 = nullptr;
ERR_put_error(16, 249, 65, "crypto/ec/ecdsa_ossl.c", 234);
v19 = nullptr;
goto LABEL_31;
}
v20 = EC_GROUP_get0_order(v10);
v21 = v20;
if ( !v20 )
{
v24 = nullptr;
ERR_put_error(16, 249, 16, "crypto/ec/ecdsa_ossl.c", 240);
goto LABEL_31;
}
v22 = BN_num_bits(v20);
v23 = v22;
if ( v22 >= 8 * a2 )
{
if ( BN_bin2bn(a1, a2, (__int64)v19) )
goto LABEL_13;
goto LABEL_75;
}
v32 = v22 + 14;
v33 = v23 + 7;
if ( v23 + 7 < 0 )
v33 = v32;
a2 = v33 >> 3;
if ( !BN_bin2bn(a1, v33 >> 3, (__int64)v19) )
{
LABEL_75:
v24 = nullptr;
ERR_put_error(16, 249, 3, "crypto/ec/ecdsa_ossl.c", 250);
goto LABEL_31;
}
if ( v23 >= 8 * a2 || (unsigned int)BN_rshift((__int64)v19, (__int64)v19, 8 - (v23 & 7u)) )
{
LABEL_13:
v24 = nullptr;
while ( a3 != nullptr && a4 != 0 )
{
if ( !BN_copy(*v12, a4) )
{
ERR_put_error(16, 249, 65, "crypto/ec/ecdsa_ossl.c", 268);
goto LABEL_31;
}
v25 = a3;
LABEL_39:
if ( !(unsigned int)BN_mod_mul(v18, v11, *v12, v21, v17) )
{
ERR_put_error(16, 249, 3, "crypto/ec/ecdsa_ossl.c", 274);
goto LABEL_31;
}
if ( !(unsigned int)BN_mod_add_quick(v16, v18, v19, v21) )
{
ERR_put_error(16, 249, 3, "crypto/ec/ecdsa_ossl.c", 278);
goto LABEL_31;
}
if ( !(unsigned int)BN_mod_mul(v16, v16, v25, v21, v17) )
{
ERR_put_error(16, 249, 3, "crypto/ec/ecdsa_ossl.c", 282);
goto LABEL_31;
}
if ( !BN_is_zero(v16) )
goto LABEL_32;
if ( a3 != nullptr && a4 != 0 )
{
ERR_put_error(16, 249, 157, "crypto/ec/ecdsa_ossl.c", 291);
goto LABEL_31;
}
}
if ( a5 && (v40 = (__int64 *)EC_KEY_get0_group(a5)) != nullptr )
{
if ( (unsigned int)EC_KEY_can_sign(a5) )
{
v25 = (_BYTE *)BN_new();
v39 = (unsigned __int64 *)BN_new();
v26 = BN_new();
v27 = (_BYTE *)v26;
if ( v39 == nullptr || v25 == nullptr || !v26 )
{
v38 = nullptr;
ERR_put_error(16, 248, 65, "crypto/ec/ecdsa_ossl.c", 67);
goto LABEL_27;
}
v38 = EC_POINT_new(v40);
if ( !v38 )
{
ERR_put_error(16, 248, 16, "crypto/ec/ecdsa_ossl.c", 71);
goto LABEL_27;
}
v28 = EC_GROUP_get0_order((__int64)v40);
if ( !v28 )
{
ERR_put_error(16, 248, 16, "crypto/ec/ecdsa_ossl.c", 76);
goto LABEL_27;
}
do
{
if ( !a1 )
{
while ( (unsigned int)BN_rand_range(v25) )
{
if ( !BN_is_zero((__int64)v25) )
goto LABEL_53;
}
ERR_put_error(16, 248, 158, "crypto/ec/ecdsa_ossl.c", 94);
goto LABEL_27;
}
do
{
v29 = EC_KEY_get0_private_key(a5);
if ( !(unsigned int)BN_generate_dsa_nonce(v25, v28, v29, a1, a2, v17) )
{
ERR_put_error(16, 248, 158, "crypto/ec/ecdsa_ossl.c", 88);
goto LABEL_27;
}
}
while ( BN_is_zero((__int64)v25) );
LABEL_53:
if ( !(unsigned int)BN_add(v25, v25, v28) )
goto LABEL_27;
v37 = BN_num_bits((__int64)v25);
if ( v37 <= (int)BN_num_bits(v28) && !(unsigned int)BN_add(v25, v25, v28) )
goto LABEL_27;
if ( !(unsigned int)EC_POINT_mul((__int64)v40) )
{
ERR_put_error(16, 248, 16, "crypto/ec/ecdsa_ossl.c", 113);
goto LABEL_27;
}
v34 = EC_GROUP_method_of((__int64)v40);
if ( (unsigned int)EC_METHOD_get_field_type(v34) == 406 )
{
if ( !(unsigned int)EC_POINT_get_affine_coordinates_GFp((__int64)v40, v38) )
{
ERR_put_error(16, 248, 16, "crypto/ec/ecdsa_ossl.c", 120);
goto LABEL_27;
}
}
else if ( !(unsigned int)EC_POINT_get_affine_coordinates_GF2m((__int64)v40, v38) )
{
ERR_put_error(16, 248, 16, "crypto/ec/ecdsa_ossl.c", 130);
goto LABEL_27;
}
if ( !(unsigned int)BN_nnmod(v39, v27, v28, v17) )
{
ERR_put_error(16, 248, 3, "crypto/ec/ecdsa_ossl.c", 136);
goto LABEL_27;
}
}
while ( BN_is_zero((__int64)v39) );
if ( EC_GROUP_get_mont_data((__int64)v40) )
{
if ( !(unsigned int)BN_set_word((__int64)v27, 2) )
{
ERR_put_error(16, 248, 3, "crypto/ec/ecdsa_ossl.c", 149);
goto LABEL_27;
}
if ( !(unsigned int)BN_mod_sub(v27, v28, v27, v28, v17) )
{
ERR_put_error(16, 248, 3, "crypto/ec/ecdsa_ossl.c", 153);
goto LABEL_27;
}
BN_set_flags((__int64)v27, 4);
mont_data = EC_GROUP_get_mont_data((__int64)v40);
if ( !(unsigned int)BN_mod_exp_mont_consttime(v25, v25, v27, v28, v17, mont_data) )
{
ERR_put_error(16, 248, 3, "crypto/ec/ecdsa_ossl.c", 159);
goto LABEL_27;
}
LABEL_85:
BN_clear_free(*v12);
v35 = v24;
v24 = v25;
BN_clear_free(v35);
*v12 = v39;
EC_POINT_free((__int64)v38);
BN_clear_free(v27);
goto LABEL_39;
}
if ( BN_mod_inverse(v25, v25, v28, v17) )
goto LABEL_85;
ERR_put_error(16, 248, 3, "crypto/ec/ecdsa_ossl.c", 164);
LABEL_27:
BN_clear_free(v25);
BN_clear_free(v39);
EC_POINT_free((__int64)v38);
BN_clear_free(v27);
}
else
{
ERR_put_error(16, 248, 159, "crypto/ec/ecdsa_ossl.c", 51);
}
}
else
{
ERR_put_error(16, 248, 67, "crypto/ec/ecdsa_ossl.c", 46);
}
ERR_put_error(16, 249, 42, "crypto/ec/ecdsa_ossl.c", 261);
goto LABEL_31;
}
v24 = nullptr;
ERR_put_error(16, 249, 3, "crypto/ec/ecdsa_ossl.c", 255);
LABEL_31:
v30 = v12;
v12 = nullptr;
ECDSA_SIG_free((_BYTE **)v30);
LABEL_32:
BN_CTX_free(v17);
BN_clear_free(v19);
BN_clear_free(v18);
BN_clear_free(v24);
return v12;
}