//
// PKCS5_pbe2_set_iv from 0xe72b68 to 0xe72de8 (640 bytes)
//
// 3 xrefs:
// > PKCS8_encrypt @ 0xe66148
// > PKCS5_pbe2_set @ 0xe72df0
// > ??> @ 0x36738
//
// 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
//
_QWORD *__fastcall PKCS5_pbe2_set_iv(unsigned int *a1, int a2, const void *a3, int a4, void *a5, signed int a6)
{
unsigned int v11; // w0
unsigned int v12; // w23
char **v13; // x24
__int64 v14; // x0
__int64 *v15; // x20
char ***v16; // x22
__int64 v17; // x0
int v18; // w0
__int64 v19; // x0
__int64 *v20; // x0
int v21; // w19
_QWORD *v22; // x0
_QWORD *v23; // x21
unsigned int v25; // w0
_BYTE v27[16]; // [xsp+70h] [xbp+70h] BYREF
v11 = EVP_CIPHER_type(a1);
v12 = v11;
if ( !v11 )
{
v15 = nullptr;
ERR_put_error(13, 167, 108, (__int64)"crypto/asn1/p5_pbev2.c", 54);
a5 = nullptr;
v23 = nullptr;
goto LABEL_19;
}
v13 = OBJ_nid2obj(v11);
v14 = PBE2PARAM_new();
v15 = (__int64 *)v14;
if ( !v14 )
goto LABEL_17;
v16 = *(char ****)(v14 + 8);
*v16 = v13;
v17 = ASN1_TYPE_new();
v16[1] = (char **)v17;
if ( !v17 )
goto LABEL_17;
if ( (unsigned int)EVP_CIPHER_iv_length((__int64)a1) )
{
if ( a5 )
{
v18 = EVP_CIPHER_iv_length((__int64)a1);
memcpy(v27, a5, v18);
}
else
{
v25 = EVP_CIPHER_iv_length((__int64)a1);
if ( (int)RAND_bytes((__int64)v27, v25) <= 0 )
{
v23 = nullptr;
goto LABEL_19;
}
}
}
v19 = EVP_CIPHER_CTX_new();
a5 = (void *)v19;
if ( !v19 )
goto LABEL_17;
if ( !(unsigned int)EVP_CipherInit_ex(v19, a1, 0, 0, v27, 0) )
{
v23 = nullptr;
goto LABEL_19;
}
if ( (EVP_CIPHER_param_to_asn1((__int64)a5, (__int64)v16[1]) & 0x80000000) != 0 )
{
v23 = nullptr;
ERR_put_error(13, 167, 114, (__int64)"crypto/asn1/p5_pbev2.c", 84);
goto LABEL_19;
}
if ( a6 == -1 && (int)EVP_CIPHER_CTX_ctrl((__int64)a5) <= 0 )
{
ERR_clear_error();
a6 = 799;
}
v20 = (__int64 *)a5;
v21 = -1;
EVP_CIPHER_CTX_free(v20);
if ( v12 == 37 )
v21 = EVP_CIPHER_key_length((__int64)a1);
X509_ALGOR_free(*v15);
v22 = PKCS5_pbkdf2_set(a2, a3, a4, a6, v21);
*v15 = (__int64)v22;
if ( v22 && (v23 = (_QWORD *)X509_ALGOR_new()) != nullptr )
{
*v23 = OBJ_nid2obj(0xA1u);
if ( ASN1_TYPE_pack_sequence((__int64)PBE2PARAM_it, (__int64)v15, v23 + 1) )
{
PBE2PARAM_free((__int64)v15);
return v23;
}
}
else
{
LABEL_17:
v23 = nullptr;
}
a5 = nullptr;
ERR_put_error(13, 167, 65, (__int64)"crypto/asn1/p5_pbev2.c", 134);
LABEL_19:
EVP_CIPHER_CTX_free((__int64 *)a5);
PBE2PARAM_free((__int64)v15);
X509_ALGOR_free(0);
X509_ALGOR_free((__int64)v23);
return nullptr;
}