//
// RSA_setup_blinding from 0xa42040 to 0xa42304 (708 bytes)
//
// 6 xrefs:
// > RSA_blinding_on @ 0xa42338
// > sub_A43568 @ 0xa43994
// > sub_A43568 @ 0xa439ec
// > sub_A43A80 @ 0xa43ee4
// > sub_A43A80 @ 0xa43f3c
// > ??> @ 0x7fd0c
//
// 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:08:14 +0000
//
int __fastcall RSA_setup_blinding(int a1, int a2)
{
int v4; // r4
int v5; // r6
_DWORD *v6; // r0
int v7; // r9
int param; // r8
int v10; // r0
int words; // r8
int dmax; // r0
int v13; // r0
int v14; // r10
int v15; // r8
int v16; // r9
bool v17; // zf
int v18; // r3
int **v19; // r11
_UNKNOWN **v20; // r0
_UNKNOWN **v21; // r0
int v22; // r8
int **v23; // [sp+8h] [bp-Ch]
int **v24; // [sp+Ch] [bp-8h]
if ( a2 )
{
v4 = a2;
}
else
{
v13 = BN_CTX_new(a1);
v4 = v13;
if ( !v13 )
return 0;
}
BN_CTX_start(v4);
v5 = BN_CTX_get(v4);
if ( !v5 )
{
ERR_put_error(4, 136, 65, (int)"crypto/rsa/rsa_crpt.c", 126);
param = 0;
goto LABEL_10;
}
v5 = *(_DWORD *)(a1 + 20);
if ( !v5 )
{
v14 = *(_DWORD *)(a1 + 24);
v15 = *(_DWORD *)(a1 + 28);
v16 = *(_DWORD *)(a1 + 32);
v17 = v14 == 0;
if ( v14 )
v17 = v15 == 0;
v18 = v17;
if ( !v16 )
v18 |= 1u;
if ( !v18 )
{
BN_CTX_start(v4);
v24 = (int **)BN_CTX_get(v4);
v19 = (int **)BN_CTX_get(v4);
v23 = (int **)BN_CTX_get(v4);
if ( v23
&& (v20 = BN_value_one(), BN_sub(v19, v15, v20))
&& (v21 = BN_value_one(), BN_sub(v23, v16, v21))
&& BN_mul(v24, v19, v23, v4) )
{
v22 = BN_mod_inverse(0, v14, v24, v4);
BN_CTX_end(v4);
if ( v22 )
{
v5 = v22;
goto LABEL_6;
}
}
else
{
BN_CTX_end(v4);
}
}
ERR_put_error(4, 136, 140, (int)"crypto/rsa/rsa_crpt.c", 133);
param = 0;
goto LABEL_10;
}
LABEL_6:
if ( !RAND_status() )
{
v10 = *(_DWORD *)(a1 + 24);
if ( v10 )
{
if ( bn_get_words(v10) )
{
words = bn_get_words(*(_DWORD *)(a1 + 24));
dmax = bn_get_dmax(*(_DWORD *)(a1 + 24));
RAND_add(words, 4 * dmax, 0, 0);
v6 = (_DWORD *)BN_new();
v7 = (int)v6;
if ( !v6 )
goto LABEL_18;
LABEL_8:
BN_with_flags(v6, *(int **)(a1 + 16), 4);
param = BN_BLINDING_create_param(0, v5, v7, v4, *(_DWORD *)(*(_DWORD *)(a1 + 8) + 24), *(_DWORD *)(a1 + 60));
BN_free(v7);
if ( param )
BN_BLINDING_set_current_thread(param);
else
ERR_put_error(4, 136, 3, (int)"crypto/rsa/rsa_crpt.c", 164);
goto LABEL_10;
}
}
}
v6 = (_DWORD *)BN_new();
v7 = (int)v6;
if ( v6 )
goto LABEL_8;
LABEL_18:
param = v7;
ERR_put_error(4, 136, 65, (int)"crypto/rsa/rsa_crpt.c", 153);
LABEL_10:
BN_CTX_end(v4);
if ( v4 != a2 )
BN_CTX_free(v4);
if ( *(_DWORD *)(a1 + 20) != v5 )
BN_free(v5);
return param;
}