//
// CMS_add0_recipient_password from 0x875f64 to 0x8762f4 (912 bytes)
//
// 1 xrefs:
// > ??> @ 0x6a53c
//
// 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
//
_DWORD *__fastcall CMS_add0_recipient_password(int *a1, int a2, int a3, int a4, char *a5, size_t a6, int *a7)
{
int *v9; // r5
int v10; // r0
int v11; // r9
size_t *v12; // r7
int *v13; // r6
int v14; // r1
void *v15; // r0
int v16; // r0
unsigned int v17; // r0
_DWORD *v18; // r4
_DWORD *v19; // r0
_DWORD *v20; // r6
_DWORD *v21; // r8
char **v22; // r0
int v23; // r11
void *v24; // r0
int v25; // r3
int v26; // r2
int *v27; // r0
int *v28; // r0
_BYTE v30[20]; // [sp+8h] [bp-14h] BYREF
v9 = a7;
v10 = cms_get0_enveloped(a1);
v11 = v10;
if ( v10 )
{
if ( a3 <= 0 )
{
if ( a7 )
goto LABEL_5;
a3 = 893;
}
else if ( a7 )
{
goto LABEL_4;
}
v9 = *(int **)(*(_DWORD *)(v10 + 12) + 12);
if ( !v9 )
{
ERR_put_error(46, 165, 126, (int)"crypto/cms/cms_pwri.c", 68);
return nullptr;
}
LABEL_4:
if ( a3 != 893 )
{
ERR_put_error(46, 165, 179, (int)"crypto/cms/cms_pwri.c", 73);
return nullptr;
}
LABEL_5:
v12 = (size_t *)X509_ALGOR_new();
if ( !v12 )
goto LABEL_32;
v13 = (int *)EVP_CIPHER_CTX_new();
if ( EVP_EncryptInit_ex(v13, v9, nullptr, 0, nullptr) <= 0 )
{
ERR_put_error(46, 165, 6, (int)"crypto/cms/cms_pwri.c", 85);
}
else
{
v14 = EVP_CIPHER_CTX_iv_length((int)v13);
if ( v14 <= 0 )
goto LABEL_12;
if ( RAND_bytes((int)v30, v14) > 0 )
{
if ( EVP_EncryptInit_ex(v13, nullptr, nullptr, 0, v30) <= 0 )
{
ERR_put_error(46, 165, 6, (int)"crypto/cms/cms_pwri.c", 95);
}
else
{
v15 = ASN1_TYPE_new();
v12[1] = (size_t)v15;
if ( v15 )
{
if ( EVP_CIPHER_param_to_asn1((int)v13, (int)v15) > 0 )
{
LABEL_12:
v16 = EVP_CIPHER_CTX_cipher((int)v13);
v17 = EVP_CIPHER_type(v16);
*v12 = (size_t)OBJ_nid2obj(v17);
EVP_CIPHER_CTX_free(v13);
v18 = ASN1_item_new((int)CMS_RecipientInfo_it);
if ( v18 )
{
v19 = ASN1_item_new((int)&CMS_PasswordRecipientInfo_it);
v20 = v19;
v18[1] = v19;
if ( v19 )
{
*v18 = 3;
X509_ALGOR_free((_DWORD *)v19[2]);
v21 = X509_ALGOR_new();
v20[2] = v21;
if ( v21 )
{
v22 = OBJ_nid2obj(0x37Du);
v23 = v20[2];
*v21 = v22;
v24 = ASN1_TYPE_new();
v25 = v20[2];
*(_DWORD *)(v23 + 4) = v24;
v26 = *(_DWORD *)(v25 + 4);
if ( v26 )
{
if ( ASN1_item_pack(v12, X509_ALGOR_it, (int *)(v26 + 4)) )
{
**(_DWORD **)(v20[2] + 4) = 16;
X509_ALGOR_free(v12);
v27 = (int *)PKCS5_pbkdf2_set(a2, 0, 0);
v12 = (size_t *)v27;
v20[1] = v27;
if ( !v27 )
{
LABEL_30:
EVP_CIPHER_CTX_free(v27);
ASN1_item_free(v18, CMS_RecipientInfo_it);
goto LABEL_27;
}
CMS_RecipientInfo_set0_password(v18, a5, a6);
v28 = *(int **)(v11 + 8);
*v20 = 0;
if ( OPENSSL_sk_push(v28, (int)v18) )
return v18;
v12 = nullptr;
}
}
}
}
ERR_put_error(46, 165, 65, (int)"crypto/cms/cms_pwri.c", 161);
v27 = nullptr;
goto LABEL_30;
}
LABEL_32:
ERR_put_error(46, 165, 65, (int)"crypto/cms/cms_pwri.c", 161);
EVP_CIPHER_CTX_free(nullptr);
goto LABEL_27;
}
ERR_put_error(46, 165, 102, (int)"crypto/cms/cms_pwri.c", 105);
}
else
{
ERR_put_error(46, 165, 65, (int)"crypto/cms/cms_pwri.c", 100);
}
}
}
}
EVP_CIPHER_CTX_free(v13);
LABEL_27:
X509_ALGOR_free(v12);
return nullptr;
}
return nullptr;
}