//
// sub_82C9FC from 0x82c9fc to 0x82d208 (2060 bytes)
//
// 1 xrefs:
// > ??> @ 0xa38d50
//
// 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_82C9FC(int a1, int a2, int a3, _DWORD *a4)
{
int sigid_algs; // r4
_DWORD **v7; // r4
char **v8; // r0
int v9; // r4
char *v10; // r0
char *v11; // r0
int v12; // r0
int **v13; // r7
int *v14; // r5
int *v15; // r3
char *v16; // r0
char *v17; // r0
char *v18; // r0
char *v19; // r0
int *v20; // r6
int v21; // r7
int v22; // r0
int v23; // r1
int v24; // r7
_DWORD *v25; // r5
int v26; // r8
_DWORD **v27; // r0
void *v28; // r0
int v29; // r0
int v30; // r6
char **v31; // r0
int *v32; // r5
_DWORD *v33; // r3
_DWORD **v34; // r7
char **v35; // r0
int *v36; // r4
char **v37; // r0
_DWORD **v42; // [sp+14h] [bp-20h] BYREF
int v43; // [sp+18h] [bp-1Ch]
int v44; // [sp+1Ch] [bp-18h]
int v45; // [sp+20h] [bp-14h] BYREF
int *v46; // [sp+24h] [bp-10h] BYREF
int v47; // [sp+28h] [bp-Ch] BYREF
int *v48[2]; // [sp+2Ch] [bp-8h] BYREF
v42 = nullptr;
switch ( a2 )
{
case 1:
if ( a3 )
return 1;
PKCS7_SIGNER_INFO_get0_algs(a4, nullptr, nullptr, &v42);
goto LABEL_8;
case 2:
if ( !a3 )
{
PKCS7_RECIP_INFO_get0_alg((int)a4, &v42);
LABEL_8:
v7 = v42;
if ( v42 )
{
v8 = OBJ_nid2obj(6u);
X509_ALGOR_set0(v7, v8, 5, 0);
}
}
return 1;
case 3:
*a4 = 672;
return 1;
case 5:
if ( !a3 )
{
v47 = 1;
v30 = CMS_SignerInfo_get0_pkey_ctx(a4);
CMS_SignerInfo_get0_algs(a4, a3, a3, a3, v48);
if ( !v30 || EVP_PKEY_CTX_ctrl(v30, 6, -1) > 0 )
{
sigid_algs = v47;
v32 = v48[0];
goto LABEL_67;
}
return 0;
}
if ( a3 == 1 )
{
v9 = CMS_SignerInfo_get0_pkey_ctx(a4);
CMS_SignerInfo_get0_algs(a4, 0, 0, 0, v48);
v10 = OBJ_obj2nid(*v48[0]);
if ( v10 != &byte_6 )
{
if ( v10 == (char *)&stru_38C.st_value )
return sub_82C58C(nullptr, v9, v48[0], 0);
sigid_algs = OBJ_find_sigid_algs((int)v10, nullptr, &v47);
if ( !sigid_algs )
return sigid_algs;
if ( v47 != 6 )
return 0;
}
}
return 1;
case 7:
if ( !a3 )
{
v45 = 0;
v47 = 1;
v21 = CMS_RecipientInfo_get0_pkey_ctx(a4);
CMS_RecipientInfo_ktri_get0_algs(a4, a3, a3, &v46);
if ( v21 && EVP_PKEY_CTX_ctrl(v21, 6, -1) <= 0 )
return 0;
sigid_algs = v47;
if ( v47 == 1 )
{
v32 = v46;
LABEL_67:
v31 = OBJ_nid2obj(6u);
X509_ALGOR_set0((_DWORD **)v32, v31, 5, 0);
return sigid_algs;
}
if ( v47 != 4 )
return 0;
if ( EVP_PKEY_CTX_ctrl(v21, 6, 768) <= 0
|| EVP_PKEY_CTX_ctrl(v21, 6, 1016) <= 0
|| (v22 = EVP_PKEY_CTX_ctrl(v21, 6, 768), v24 = v22, v22 < 0)
|| (v25 = (_DWORD *)RSA_OAEP_PARAMS_new(v22, v23)) == nullptr )
{
sigid_algs = 0;
v25 = nullptr;
goto LABEL_61;
}
v26 = v43;
if ( EVP_MD_type(v43) != 64 )
{
v27 = (_DWORD **)X509_ALGOR_new();
sigid_algs = (int)v27;
*v25 = v27;
if ( !v27 )
goto LABEL_61;
X509_ALGOR_set_md(v27, v26);
}
v28 = (void *)sub_82C0A8(v25 + 1, v44);
if ( !v28 )
goto LABEL_89;
if ( !v24 )
{
LABEL_91:
v28 = (void *)ASN1_item_pack(v25, &RSA_OAEP_PARAMS_it, &v45);
if ( v28 )
{
v36 = v46;
v37 = OBJ_nid2obj(0x397u);
X509_ALGOR_set0((_DWORD **)v36, v37, 16, v45);
v45 = 0;
sigid_algs = 1;
goto LABEL_61;
}
goto LABEL_89;
}
v28 = X509_ALGOR_new();
v25[2] = v28;
if ( !v28 )
{
LABEL_89:
sigid_algs = (int)v28;
goto LABEL_61;
}
v29 = ASN1_OCTET_STRING_new();
sigid_algs = v29;
if ( v29 )
{
if ( !ASN1_OCTET_STRING_set(v29, v48[0], v24) )
{
ASN1_OCTET_STRING_free(sigid_algs);
sigid_algs = 0;
goto LABEL_61;
}
v34 = (_DWORD **)v25[2];
v35 = OBJ_nid2obj(0x3A7u);
X509_ALGOR_set0(v34, v35, 4, sigid_algs);
goto LABEL_91;
}
LABEL_61:
RSA_OAEP_PARAMS_free(v25);
ASN1_STRING_free(v45);
return sigid_algs;
}
if ( a3 == 1 )
{
sigid_algs = CMS_RecipientInfo_get0_pkey_ctx(a4);
if ( sigid_algs )
{
if ( !CMS_RecipientInfo_ktri_get0_algs(a4, 0, 0, v48) )
return -1;
v11 = OBJ_obj2nid(*v48[0]);
if ( v11 == &byte_6 )
return a3;
if ( v11 != (_BYTE *)&stru_38C.st_size + 3 )
{
ERR_put_error(4, 159, 162, (int)"crypto/rsa/rsa_ameth.c", 715);
return -1;
}
v12 = ASN1_TYPE_unpack_sequence(&RSA_OAEP_PARAMS_it, v48[0][1]);
v13 = (int **)v12;
if ( !v12 )
{
ERR_put_error(4, 159, 161, (int)"crypto/rsa/rsa_ameth.c", 722);
v14 = nullptr;
sigid_algs = -1;
goto LABEL_41;
}
v14 = *(int **)(v12 + 4);
if ( v14
&& (OBJ_obj2nid(*v14) == (_BYTE *)&stru_38C.st_name + 3
? (v14 = (int *)ASN1_TYPE_unpack_sequence(X509_ALGOR_it, v14[1]))
: (v14 = nullptr),
(v15 = v13[1]) != nullptr) )
{
if ( OBJ_obj2nid(*v15) != (_BYTE *)&stru_38C.st_name + 3 )
{
ERR_put_error(4, 157, 153, (int)"crypto/rsa/rsa_ameth.c", 421);
goto LABEL_78;
}
if ( !v14 )
{
ERR_put_error(4, 157, 154, (int)"crypto/rsa/rsa_ameth.c", 425);
goto LABEL_78;
}
v16 = OBJ_obj2nid(*v14);
v17 = OBJ_nid2sn((unsigned int)v16);
if ( !EVP_get_digestbyname((int)v17) )
{
ERR_put_error(4, 157, 151, (int)"crypto/rsa/rsa_ameth.c", 430);
LABEL_78:
sigid_algs = -1;
goto LABEL_41;
}
}
else if ( !EVP_sha1() )
{
goto LABEL_78;
}
if ( *v13 )
{
v18 = OBJ_obj2nid(**v13);
v19 = OBJ_nid2sn((unsigned int)v18);
if ( !EVP_get_digestbyname((int)v19) )
{
ERR_put_error(4, 156, 166, (int)"crypto/rsa/rsa_ameth.c", 409);
sigid_algs = -1;
LABEL_41:
RSA_OAEP_PARAMS_free(v13);
X509_ALGOR_free(v14);
return sigid_algs;
}
}
else if ( !EVP_sha1() )
{
goto LABEL_78;
}
v20 = v13[2];
if ( v20 )
{
if ( OBJ_obj2nid(*v20) != (_BYTE *)&stru_39C.st_size + 3 )
{
ERR_put_error(4, 159, 163, (int)"crypto/rsa/rsa_ameth.c", 736);
sigid_algs = -1;
goto LABEL_41;
}
v33 = (_DWORD *)v20[1];
if ( *v33 != 4 )
{
ERR_put_error(4, 159, 160, (int)"crypto/rsa/rsa_ameth.c", 740);
sigid_algs = -1;
goto LABEL_41;
}
*(_DWORD *)(v33[1] + 8) = 0;
}
if ( EVP_PKEY_CTX_ctrl(sigid_algs, 6, -1) > 0
&& EVP_PKEY_CTX_ctrl(sigid_algs, 6, 768) > 0
&& EVP_PKEY_CTX_ctrl(sigid_algs, 6, 1016) > 0 )
{
if ( EVP_PKEY_CTX_ctrl(sigid_algs, 6, 768) > 0 )
sigid_algs = 1;
else
sigid_algs = -1;
goto LABEL_41;
}
goto LABEL_78;
}
return sigid_algs;
}
return 1;
case 8:
sigid_algs = 1;
*a4 = 0;
return sigid_algs;
default:
return -2;
}
}