//
// CMS_add0_recipient_password from 0xe20928 to 0xe20cb8 (912 bytes)
//
// 1 xrefs:
// > ??> @ 0x621c0
//
// 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
//
__int64 __fastcall CMS_add0_recipient_password(
__int64 *a1,
unsigned int a2,
int a3,
__int64 a4,
char *a5,
size_t a6,
unsigned int *a7)
{
__int64 result; // x0
__int64 v13; // x24
_QWORD *v14; // x21
__int64 *v15; // x22
int v16; // w0
__int64 v17; // x0
unsigned int *v18; // x0
unsigned int v19; // w0
__int64 v20; // x19
__int64 v21; // x0
_QWORD *v22; // x22
__int64 v23; // x0
__int64 v24; // x0
_QWORD *v25; // x23
char **v26; // x0
__int64 v27; // x28
__int64 v28; // x0
__int64 v29; // x1
__int64 v30; // x2
__int64 *v31; // x0
_BYTE v32[16]; // [xsp+60h] [xbp+60h] BYREF
result = cms_get0_enveloped(a1);
v13 = result;
if ( result )
{
if ( a3 <= 0 )
{
if ( a7 )
goto LABEL_5;
a3 = 893;
}
else if ( a7 )
{
goto LABEL_4;
}
a7 = *(unsigned int **)(*(_QWORD *)(result + 24) + 24LL);
if ( !a7 )
{
ERR_put_error(46, 165, 126, (__int64)"crypto/cms/cms_pwri.c", 68);
return 0;
}
LABEL_4:
if ( a3 != 893 )
{
ERR_put_error(46, 165, 179, (__int64)"crypto/cms/cms_pwri.c", 73);
return 0;
}
LABEL_5:
v14 = (_QWORD *)X509_ALGOR_new();
if ( !v14 )
goto LABEL_32;
v15 = (__int64 *)EVP_CIPHER_CTX_new();
if ( (int)EVP_EncryptInit_ex((__int64)v15, a7, 0, 0, nullptr) <= 0 )
{
ERR_put_error(46, 165, 6, (__int64)"crypto/cms/cms_pwri.c", 85);
}
else
{
v16 = EVP_CIPHER_CTX_iv_length((__int64)v15);
if ( v16 <= 0 )
goto LABEL_12;
if ( (int)RAND_bytes((__int64)v32, (unsigned int)v16) > 0 )
{
if ( (int)EVP_EncryptInit_ex((__int64)v15, nullptr, 0, 0, v32) <= 0 )
{
ERR_put_error(46, 165, 6, (__int64)"crypto/cms/cms_pwri.c", 95);
}
else
{
v17 = ASN1_TYPE_new();
v14[1] = v17;
if ( v17 )
{
if ( (int)EVP_CIPHER_param_to_asn1((__int64)v15, v17) > 0 )
{
LABEL_12:
v18 = (unsigned int *)EVP_CIPHER_CTX_cipher((__int64)v15);
v19 = EVP_CIPHER_type(v18);
*v14 = OBJ_nid2obj(v19);
EVP_CIPHER_CTX_free(v15);
v20 = ASN1_item_new((__int64)CMS_RecipientInfo_it);
if ( v20 )
{
v21 = ASN1_item_new((__int64)&CMS_PasswordRecipientInfo_it);
*(_QWORD *)(v20 + 8) = v21;
v22 = (_QWORD *)v21;
if ( v21 )
{
v23 = *(_QWORD *)(v21 + 16);
*(_DWORD *)v20 = 3;
X509_ALGOR_free(v23);
v24 = X509_ALGOR_new();
v22[2] = v24;
v25 = (_QWORD *)v24;
if ( v24 )
{
v26 = OBJ_nid2obj(0x37Du);
v27 = v22[2];
*v25 = v26;
v28 = ASN1_TYPE_new();
v29 = v22[2];
*(_QWORD *)(v27 + 8) = v28;
v30 = *(_QWORD *)(v29 + 8);
if ( v30 )
{
if ( ASN1_item_pack((__int64)v14, (__int64)X509_ALGOR_it, (__int64 *)(v30 + 8)) )
{
**(_DWORD **)(v22[2] + 8LL) = 16;
X509_ALGOR_free((__int64)v14);
v31 = (__int64 *)PKCS5_pbkdf2_set(a2, 0, 0, 0xFFFFFFFFLL, 0xFFFFFFFFLL);
v22[1] = v31;
v14 = v31;
if ( !v31 )
{
LABEL_30:
EVP_CIPHER_CTX_free(v31);
ASN1_item_free(v20, CMS_RecipientInfo_it);
goto LABEL_27;
}
CMS_RecipientInfo_set0_password(v20, a5, a6);
*v22 = 0;
if ( (unsigned int)OPENSSL_sk_push(*(int **)(v13 + 16), v20) )
return v20;
v14 = nullptr;
}
}
}
}
ERR_put_error(46, 165, 65, (__int64)"crypto/cms/cms_pwri.c", 161);
v31 = nullptr;
goto LABEL_30;
}
LABEL_32:
ERR_put_error(46, 165, 65, (__int64)"crypto/cms/cms_pwri.c", 161);
EVP_CIPHER_CTX_free(nullptr);
goto LABEL_27;
}
ERR_put_error(46, 165, 102, (__int64)"crypto/cms/cms_pwri.c", 105);
}
else
{
ERR_put_error(46, 165, 65, (__int64)"crypto/cms/cms_pwri.c", 100);
}
}
}
}
EVP_CIPHER_CTX_free(v15);
LABEL_27:
X509_ALGOR_free((__int64)v14);
return 0;
}
return result;
}