//
// sub_82FF1C from 0x82ff1c to 0x830378 (1116 bytes)
//
// 1 xrefs:
// > ??> @ 0xa38ed8
//
// 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_82FF1C(int a1, int a2, int a3, _DWORD *a4)
{
int v8; // r5
int result; // r0
bool v10; // cc
int v11; // r3
int v12; // r3
v8 = *(_DWORD *)(a1 + 20);
if ( a2 == 4098 )
goto LABEL_65;
if ( a2 <= 4098 )
{
if ( a2 == 7 )
return 1;
if ( a2 <= 7 )
{
if ( a2 == 2 )
{
ERR_put_error(4, 143, 148, (int)"crypto/rsa/rsa_pmeth.c", 509);
return -2;
}
if ( a2 > 2 )
{
if ( a2 <= 5 )
return 1;
return -2;
}
if ( a2 == 1 )
{
if ( sub_82FDE4((int)a4, *(_DWORD *)(v8 + 16)) )
{
*(_DWORD *)(v8 + 20) = a4;
return a2;
}
return 0;
}
return -2;
}
if ( a2 == 13 )
goto LABEL_51;
if ( a2 <= 13 )
{
if ( (unsigned int)(a2 - 9) <= 2 )
return 1;
return -2;
}
if ( a2 != 4097 )
return -2;
if ( (unsigned int)(a3 - 1) <= 5 )
{
if ( !sub_82FDE4(*(_DWORD *)(v8 + 20), a3) )
return 0;
if ( a3 == 6 )
{
if ( (*(_DWORD *)(a1 + 16) & 0x18) != 0 )
goto LABEL_31;
}
else
{
if ( a3 != 4 )
{
LABEL_33:
*(_DWORD *)(v8 + 16) = a3;
return 1;
}
if ( (*(_DWORD *)(a1 + 16) & 0x300) != 0 )
{
LABEL_31:
if ( !*(_DWORD *)(v8 + 20) )
*(_DWORD *)(v8 + 20) = EVP_sha1();
goto LABEL_33;
}
}
}
ERR_put_error(4, 143, 144, (int)"crypto/rsa/rsa_pmeth.c", 396);
return -2;
}
if ( a2 == 4103 )
{
LABEL_65:
if ( *(_DWORD *)(v8 + 16) != 6 )
{
ERR_put_error(4, 143, 146, (int)"crypto/rsa/rsa_pmeth.c", 406);
return -2;
}
if ( a2 == 4103 )
{
*a4 = *(_DWORD *)(v8 + 28);
return 1;
}
if ( a3 >= -2 )
{
*(_DWORD *)(v8 + 28) = a3;
return 1;
}
return -2;
}
if ( a2 <= 4103 )
{
if ( a2 == 4100 )
{
if ( a4 && BN_is_odd((int)a4) && !BN_is_one((int)a4) )
{
BN_free(*(_DWORD *)(v8 + 4));
*(_DWORD *)(v8 + 4) = a4;
return 1;
}
else
{
ERR_put_error(4, 143, 101, (int)"crypto/rsa/rsa_pmeth.c", 428);
return -2;
}
}
if ( a2 < 4100 )
{
if ( a3 < 512 )
{
ERR_put_error(4, 143, 120, (int)"crypto/rsa/rsa_pmeth.c", 420);
return -2;
}
else
{
*(_DWORD *)v8 = a3;
return 1;
}
}
if ( a2 != 4101 )
{
*a4 = *(_DWORD *)(v8 + 16);
return 1;
}
goto LABEL_54;
}
if ( a2 == 4106 )
{
if ( *(_DWORD *)(v8 + 16) == 4 )
{
CRYPTO_free(*(void **)(v8 + 36), (int)"crypto/rsa/rsa_pmeth.c", 478);
v10 = (int)a4 <= 0;
if ( a4 )
v10 = a3 <= 0;
if ( v10 )
{
v11 = 0;
}
else
{
v11 = 1;
*(_DWORD *)(v8 + 36) = a4;
*(_DWORD *)(v8 + 40) = a3;
}
result = 1;
if ( v10 )
{
*(_DWORD *)(v8 + 36) = v11;
*(_DWORD *)(v8 + 40) = v11;
}
}
else
{
ERR_put_error(4, 143, 141, (int)"crypto/rsa/rsa_pmeth.c", 475);
return -2;
}
return result;
}
if ( a2 > 4106 )
{
if ( a2 != 4107 )
{
if ( a2 == 4108 )
{
if ( *(_DWORD *)(v8 + 16) == 4 )
{
*a4 = *(_DWORD *)(v8 + 36);
return *(_DWORD *)(v8 + 40);
}
else
{
ERR_put_error(4, 143, 141, (int)"crypto/rsa/rsa_pmeth.c", 490);
return -2;
}
}
return -2;
}
goto LABEL_48;
}
if ( a2 != 4104 )
{
LABEL_48:
if ( *(_DWORD *)(v8 + 16) != 4 )
{
ERR_put_error(4, 143, 141, (int)"crypto/rsa/rsa_pmeth.c", 438);
return -2;
}
if ( a2 != 4107 )
{
*(_DWORD *)(v8 + 20) = a4;
return 1;
}
LABEL_51:
v12 = *(_DWORD *)(v8 + 20);
LABEL_52:
*a4 = v12;
return 1;
}
LABEL_54:
if ( (*(_DWORD *)(v8 + 16) & 0xFFFFFFFD) == 4 )
{
if ( a2 != 4104 )
{
*(_DWORD *)(v8 + 24) = a4;
return 1;
}
v12 = *(_DWORD *)(v8 + 24);
if ( v12 )
goto LABEL_52;
goto LABEL_51;
}
ERR_put_error(4, 143, 156, (int)"crypto/rsa/rsa_pmeth.c", 461);
return -2;
}