//
// PKCS5_pbkdf2_set from 0x8c7024 to 0x8c71c8 (420 bytes)
//
// 3 xrefs:
// > CMS_add0_recipient_password @ 0x876120
// > PKCS5_pbe2_set_iv @ 0x8c72d8
// > ??> @ 0x6a54c
//
// 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 PKCS5_pbkdf2_set(int a1, const void *a2, int a3, signed int a4, int a5)
{
signed int **v9; // r4
int v10; // r0
int *v11; // r6
signed int *v12; // r3
void *v13; // r7
void *v14; // r0
int v15; // r1
signed int *v16; // r0
bool v17; // cc
_DWORD *v18; // r5
_DWORD **v20; // r0
_DWORD **v21; // r5
char **v22; // r0
v9 = (signed int **)PBKDF2PARAM_new();
if ( !v9 )
goto LABEL_28;
v10 = ASN1_OCTET_STRING_new();
v11 = (int *)v10;
if ( !v10 )
goto LABEL_28;
v12 = *v9;
if ( a3 )
v13 = (void *)a3;
else
v13 = byte_8;
*v12 = 4;
v12[1] = v10;
if ( !a3 )
a3 = (int)v13;
v14 = CRYPTO_malloc(v13, (int)"crypto/asn1/p5_pbev2.c", 170);
v11[2] = (int)v14;
if ( !v14 )
goto LABEL_28;
*v11 = a3;
if ( a2 )
{
memcpy(v14, a2, (size_t)v13);
}
else if ( RAND_bytes((int)v14, a3) <= 0 )
{
goto LABEL_28;
}
if ( a1 <= 0 )
v15 = 2048;
else
v15 = a1;
if ( !ASN1_INTEGER_set(v9[1], v15) )
goto LABEL_28;
if ( a5 > 0 )
{
v16 = (signed int *)ASN1_INTEGER_new();
v9[2] = v16;
if ( !v16 || !ASN1_INTEGER_set(v16, a5) )
goto LABEL_28;
}
v17 = a4 <= 163;
if ( a4 != 163 )
v17 = a4 <= 0;
if ( !v17 )
{
v20 = (_DWORD **)X509_ALGOR_new();
v21 = v20;
v9[3] = (signed int *)v20;
if ( !v20 )
goto LABEL_28;
v22 = OBJ_nid2obj(a4);
X509_ALGOR_set0(v21, v22, 5, 0);
}
v18 = X509_ALGOR_new();
if ( !v18 )
{
LABEL_28:
v18 = nullptr;
goto LABEL_29;
}
*v18 = OBJ_nid2obj(0x45u);
if ( ASN1_TYPE_pack_sequence((int)PBKDF2PARAM_it, (int)v9, (_DWORD **)v18 + 1) )
{
PBKDF2PARAM_free(v9);
return v18;
}
LABEL_29:
ERR_put_error(13, 219, 65, (int)"crypto/asn1/p5_pbev2.c", 221);
PBKDF2PARAM_free(v9);
X509_ALGOR_free(v18);
return nullptr;
}