//
// cms_RecipientInfo_kari_init from 0xe1f2f0 to 0xe1f4c8 (472 bytes)
//
// 2 xrefs:
// > CMS_add1_recipient_cert @ 0xe1e9e0
// > ??> @ 0x3dab8
//
// 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_RecipientInfo_kari_init(__int64 a1, __int64 a2, __int64 a3, int a4)
{
_QWORD *v8; // x0
_QWORD *v9; // x19
_QWORD *v10; // x22
_DWORD *v11; // x20
__int64 v12; // x0
__int64 *v13; // x0
__int64 *v14; // x21
__int64 *v15; // x0
__int64 v16; // x0
_DWORD *v18; // x0
__int64 v19; // [xsp+58h] [xbp+58h] BYREF
v8 = (_QWORD *)ASN1_item_new((__int64)&CMS_KeyAgreeRecipientInfo_it);
*(_QWORD *)(a1 + 8) = v8;
v9 = v8;
if ( !v8 )
return 0;
*(_DWORD *)a1 = 1;
*v8 = 3;
v10 = (_QWORD *)ASN1_item_new((__int64)CMS_RecipientEncryptedKey_it);
if ( (unsigned int)OPENSSL_sk_push((int *)v9[4], (__int64)v10) )
{
if ( (a4 & 0x10000) != 0 )
{
v11 = (_DWORD *)*v10;
*(_DWORD *)*v10 = 1;
*((_QWORD *)v11 + 1) = ASN1_item_new((__int64)&CMS_RecipientKeyIdentifier_it);
v12 = *(_QWORD *)(*v10 + 8LL);
if ( v12 && (unsigned int)cms_set1_keyid(v12, a2) )
{
LABEL_6:
v19 = 0;
v13 = (__int64 *)EVP_PKEY_CTX_new(a3, 0);
v14 = v13;
if ( v13 )
{
if ( (int)EVP_PKEY_keygen_init(v13) <= 0 || (int)EVP_PKEY_keygen(v14, &v19) <= 0 )
goto LABEL_15;
EVP_PKEY_CTX_free((__int64)v14);
v15 = (__int64 *)EVP_PKEY_CTX_new(v19, 0);
v14 = v15;
if ( v15 )
{
if ( (int)EVP_PKEY_derive_init(v15) > 0 )
{
v16 = v19;
v9[5] = v14;
EVP_PKEY_free(v16);
EVP_PKEY_up_ref(a3);
v10[2] = a3;
return 1;
}
goto LABEL_15;
}
}
v14 = nullptr;
LABEL_15:
EVP_PKEY_CTX_free((__int64)v14);
EVP_PKEY_free(v19);
return 0;
}
}
else
{
v18 = (_DWORD *)*v10;
*v18 = 0;
if ( (unsigned int)cms_set1_ias(v18 + 2, a2) )
goto LABEL_6;
}
return 0;
}
ASN1_item_free((__int64)v10, CMS_RecipientEncryptedKey_it);
return 0;
}