//
// sub_830AA0 from 0x830aa0 to 0x830d2c (652 bytes)
//
// 1 xrefs:
// > ??> @ 0xa38e9c
//
// 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_830AA0(int a1, int a2, int *a3, const void *a4, int a5)
{
_DWORD *v5; // r4
int v6; // r12
int v8; // r0
int v12; // r6
size_t v13; // r8
int v14; // r0
int v15; // r3
void *v16; // r1
int v17; // r0
int result; // r0
void *v19; // r0
void *v20; // r0
int v21; // r5
int v22; // r0
int v23; // r0
void *v24; // r0
void *v25; // r0
_DWORD v26[2]; // [sp+14h] [bp-8h] BYREF
v5 = *(_DWORD **)(a1 + 20);
v6 = *(_DWORD *)(a1 + 8);
v8 = v5[5];
v12 = *(_DWORD *)(v6 + 20);
if ( !v8 )
{
result = RSA_private_encrypt(a5, (int)a4, a2, v12);
goto LABEL_10;
}
v13 = EVP_MD_size(v8);
if ( v13 != a5 )
{
ERR_put_error(4, 142, 143, (int)"crypto/rsa/rsa_pmeth.c", 118);
return -1;
}
v14 = EVP_MD_type(v5[5]);
v15 = v5[4];
if ( v14 == 95 )
{
if ( v15 != 1 )
return -1;
result = RSA_sign_ASN1_OCTET_STRING(0, a4, v13, a2, v26, v12);
if ( result <= 0 )
return result;
LABEL_25:
result = v26[0];
goto LABEL_10;
}
if ( v15 != 5 )
{
if ( v15 != 1 )
{
if ( v15 == 6 )
{
v16 = (void *)v5[8];
if ( !v16 )
{
v24 = (void *)EVP_PKEY_size(*(_DWORD *)(a1 + 8));
v25 = CRYPTO_malloc(v24, (int)"crypto/rsa/rsa_pmeth.c", 91);
v5[8] = v25;
if ( !v25 )
return -1;
v16 = v25;
}
if ( RSA_padding_add_PKCS1_PSS_mgf1(v12, v16, a4, v5[5], v5[6], v5[7]) )
{
v17 = RSA_size(v12);
result = RSA_private_encrypt(v17, v5[8], a2, v12);
goto LABEL_10;
}
}
return -1;
}
v23 = EVP_MD_type(v5[5]);
result = RSA_sign(v23, a4, v13, a2, v26, v12);
if ( result <= 0 )
return result;
goto LABEL_25;
}
if ( EVP_PKEY_size(*(_DWORD *)(a1 + 8)) < v13 + 1 )
{
ERR_put_error(4, 142, 120, (int)"crypto/rsa/rsa_pmeth.c", 134);
return -1;
}
v20 = (void *)v5[8];
if ( !v20 )
{
v19 = (void *)EVP_PKEY_size(*(_DWORD *)(a1 + 8));
v20 = CRYPTO_malloc(v19, (int)"crypto/rsa/rsa_pmeth.c", 91);
v5[8] = v20;
if ( !v20 )
{
ERR_put_error(4, 142, 65, (int)"crypto/rsa/rsa_pmeth.c", 138);
return -1;
}
}
memcpy(v20, a4, v13);
v21 = v5[8];
v22 = EVP_MD_type(v5[5]);
*(_BYTE *)(v21 + v13) = RSA_X931_hash_id(v22);
result = RSA_private_encrypt(v13 + 1, v5[8], a2, v12);
LABEL_10:
if ( result >= 0 )
{
*a3 = result;
return 1;
}
return result;
}