//
// sub_82E5F4 from 0x82e5f4 to 0x82e94c (856 bytes)
//
// 1 xrefs:
// > ??> @ 0xac0e28
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
int __fastcall sub_82E5F4(size_t a1, void *a2, _BYTE *a3, int a4, int a5)
{
int v7; // r0
int v8; // r0
int v9; // r6
int *v10; // r9
_DWORD *v11; // r10
int v12; // r0
int v13; // r4
int v14; // r4
_BYTE *v15; // r0
bool v16; // zf
int v17; // r2
unsigned int v18; // r8
_BYTE *v19; // r7
int v21; // r0
int v22; // r0
int v23; // r1
signed int v24; // r2
if ( BN_num_bits(*(_DWORD **)(a4 + 16)) > 0x4000 )
{
ERR_put_error(4, 104, 105, (int)"crypto/rsa/rsa_ossl.c", 60);
return -1;
}
else if ( BN_ucmp(*(int **)(a4 + 16), *(int **)(a4 + 20)) <= 0 )
{
ERR_put_error(4, 104, 101, (int)"crypto/rsa/rsa_ossl.c", 65);
return -1;
}
else
{
v7 = BN_num_bits(*(_DWORD **)(a4 + 16));
if ( v7 <= 3072 || (v7 = BN_num_bits(*(_DWORD **)(a4 + 20)), v7 <= 64) )
{
v8 = BN_CTX_new(v7);
v9 = v8;
if ( v8 )
{
BN_CTX_start(v8);
v10 = (int *)BN_CTX_get(v9);
v11 = (_DWORD *)BN_CTX_get(v9);
v12 = BN_num_bits(*(_DWORD **)(a4 + 16));
v13 = v12 + 7;
if ( v12 + 7 < 0 )
v13 = v12 + 14;
v14 = v13 >> 3;
v15 = CRYPTO_malloc((void *)v14, (int)"crypto/rsa/rsa_ossl.c", 83);
v16 = v10 == nullptr;
if ( v10 )
v16 = v11 == nullptr;
v17 = v16;
v18 = v14;
if ( !v15 )
v17 |= 1u;
v19 = v15;
if ( v17 )
{
ERR_put_error(4, 104, 65, (int)"crypto/rsa/rsa_ossl.c", 85);
v14 = -1;
}
else
{
switch ( a5 )
{
case 1:
v21 = RSA_padding_add_PKCS1_type_2();
goto LABEL_23;
case 2:
v21 = RSA_padding_add_SSLv23();
goto LABEL_23;
case 3:
v21 = RSA_padding_add_none((int)v15, v14, a2, a1);
goto LABEL_23;
case 4:
v21 = RSA_padding_add_PKCS1_OAEP(v15, v14);
LABEL_23:
if ( v21 <= 0 || !BN_bin2bn(v19, v14, v10) )
goto LABEL_33;
if ( BN_ucmp(v10, *(int **)(a4 + 16)) < 0 )
{
if ( ((*(_DWORD *)(a4 + 56) & 2) == 0
|| BN_MONT_CTX_set_locked((_BYTE **)(a4 + 60), *(_DWORD *)(a4 + 84), *(int ***)(a4 + 16), v9))
&& (*(int (__fastcall **)(_DWORD *, int *, _DWORD, _DWORD, int, _DWORD))(*(_DWORD *)(a4 + 8) + 24))(
v11,
v10,
*(_DWORD *)(a4 + 20),
*(_DWORD *)(a4 + 16),
v9,
*(_DWORD *)(a4 + 60)) )
{
v22 = BN_num_bits(v11);
v23 = v22 + 7;
if ( v22 + 7 < 0 )
v23 = v22 + 14;
v24 = v14 - BN_bn2bin(v11, &a3[v14 - (v23 >> 3)]);
if ( v24 > 0 )
memset(a3, 0, v24);
}
else
{
LABEL_33:
v14 = -1;
}
}
else
{
ERR_put_error(4, 104, 132, (int)"crypto/rsa/rsa_ossl.c", 115);
v14 = -1;
}
break;
default:
ERR_put_error(4, 104, 118, (int)"crypto/rsa/rsa_ossl.c", 103);
v14 = -1;
break;
}
}
BN_CTX_end(v9);
}
else
{
v18 = 0;
v19 = nullptr;
v14 = -1;
}
BN_CTX_free(v9);
CRYPTO_clear_free(v19, v18, (int)"crypto/rsa/rsa_ossl.c", 142);
return v14;
}
else
{
ERR_put_error(4, 104, 101, (int)"crypto/rsa/rsa_ossl.c", 72);
return -1;
}
}
}