//
// RSA_setup_blinding from 0x1051d0c to 0x1051fcc (704 bytes)
//
// 6 xrefs:
// > RSA_blinding_on @ 0x1051ff4
// > sub_1053210 @ 0x1053620
// > sub_1053210 @ 0x1053660
// > sub_10536BC @ 0x1053ae4
// > sub_10536BC @ 0x1053b24
// > ??> @ 0xf8368
//
// 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:39 +0000
//
__int64 __fastcall RSA_setup_blinding(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // x19
__int64 v6; // x21
__int64 v7; // x0
__int64 v8; // x24
__int64 param; // x22
__int64 result; // x0
__int64 v11; // x0
__int64 words; // x22
long double v13; // q0
int v14; // w0
__int64 v15; // x22
__int64 v16; // x25
__int64 v17; // x24
__int64 v18; // x28
_QWORD **v19; // x27
_QWORD **v20; // x26
_UNKNOWN **v21; // x0
_UNKNOWN **v22; // x0
__int64 v23; // x22
v5 = a2;
if ( !a2 )
{
result = BN_CTX_new(a1, 0, a3);
v5 = result;
if ( !result )
return result;
}
BN_CTX_start(v5);
v6 = BN_CTX_get(v5);
if ( !v6 )
{
param = 0;
ERR_put_error(4, 136, 65, (__int64)"crypto/rsa/rsa_crpt.c", 126);
goto LABEL_8;
}
v6 = *(_QWORD *)(a1 + 40);
if ( !v6 )
{
v15 = *(_QWORD *)(a1 + 56);
v16 = *(_QWORD *)(a1 + 48);
v17 = *(_QWORD *)(a1 + 64);
if ( v15 != 0 && v16 != 0 && v17 )
{
BN_CTX_start(v5);
v18 = BN_CTX_get(v5);
v19 = (_QWORD **)BN_CTX_get(v5);
v20 = (_QWORD **)BN_CTX_get(v5);
if ( v20
&& (v21 = BN_value_one(), (unsigned int)BN_sub(v19, v15, v21))
&& (v22 = BN_value_one(), (unsigned int)BN_sub(v20, v17, v22))
&& (unsigned int)BN_mul(v18, v19, v20, v5) )
{
v23 = BN_mod_inverse(0, v16, v18, v5);
BN_CTX_end(v5);
if ( v23 )
{
v6 = v23;
goto LABEL_4;
}
}
else
{
BN_CTX_end(v5);
}
}
param = 0;
ERR_put_error(4, 136, 140, (__int64)"crypto/rsa/rsa_crpt.c", 133);
goto LABEL_8;
}
LABEL_4:
if ( !(unsigned int)RAND_status() )
{
v11 = *(_QWORD *)(a1 + 48);
if ( v11 )
{
if ( bn_get_words(v11) )
{
words = bn_get_words(*(_QWORD *)(a1 + 48));
*((_QWORD *)&v13 + 1) = bn_get_dmax(*(_QWORD *)(a1 + 48)).n128_u64[1];
*(_QWORD *)&v13 = 0;
RAND_add(words, (unsigned int)(8 * v14), v13);
v7 = BN_new();
v8 = v7;
if ( !v7 )
goto LABEL_16;
LABEL_6:
BN_with_flags(v7, *(__int64 **)(a1 + 32), 4);
param = BN_BLINDING_create_param(0, v6, v8, v5, *(_QWORD *)(*(_QWORD *)(a1 + 16) + 48LL), *(_QWORD *)(a1 + 112));
BN_free(v8);
if ( param )
BN_BLINDING_set_current_thread(param);
else
ERR_put_error(4, 136, 3, (__int64)"crypto/rsa/rsa_crpt.c", 164);
goto LABEL_8;
}
}
}
v7 = BN_new();
v8 = v7;
if ( v7 )
goto LABEL_6;
LABEL_16:
param = v8;
ERR_put_error(4, 136, 65, (__int64)"crypto/rsa/rsa_crpt.c", 153);
LABEL_8:
BN_CTX_end(v5);
if ( v5 != a2 )
BN_CTX_free(v5);
if ( *(_QWORD *)(a1 + 40) != v6 )
BN_free(v6);
return param;
}