//
// PKCS5_pbe2_set_iv from 0xadc1d4 to 0xadc440 (620 bytes)
//
// 3 xrefs:
// > PKCS8_encrypt @ 0xad0cb0
// > PKCS5_pbe2_set @ 0xadc468
// > ??> @ 0x84efc
//
// This function is hookable on this platform (idp: arm, 32 bit: True, 64 bit: False!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 12:09:31 +0000
//
_DWORD *__fastcall PKCS5_pbe2_set_iv(int *a1, int a2, const void *a3, int a4, void *a5, int a6)
{
unsigned int v9; // r0
unsigned int v10; // r9
char **v11; // r5
_DWORD *v12; // r0
_DWORD *v13; // r6
char ***v14; // r8
char **v15; // r0
size_t v16; // r0
int *v17; // r0
int *v18; // r5
_DWORD *v19; // r4
int v20; // r5
_DWORD *v21; // r0
int v23; // r0
_BYTE v25[20]; // [sp+10h] [bp-14h] BYREF
v9 = EVP_CIPHER_type((int)a1);
v10 = v9;
if ( !v9 )
{
v13 = nullptr;
ERR_put_error(13, 167, 108, (int)"crypto/asn1/p5_pbev2.c", 54);
v18 = nullptr;
v19 = nullptr;
goto LABEL_20;
}
v11 = OBJ_nid2obj(v9);
v12 = PBE2PARAM_new();
v13 = v12;
if ( !v12 )
goto LABEL_18;
v14 = (char ***)v12[1];
*v14 = v11;
v15 = (char **)ASN1_TYPE_new();
v14[1] = v15;
if ( !v15 )
goto LABEL_18;
if ( EVP_CIPHER_iv_length((int)a1) )
{
if ( a5 )
{
v16 = EVP_CIPHER_iv_length((int)a1);
memcpy(v25, a5, v16);
}
else
{
v23 = EVP_CIPHER_iv_length((int)a1);
if ( RAND_bytes((int)v25, v23) <= 0 )
{
v18 = nullptr;
v19 = nullptr;
goto LABEL_20;
}
}
}
v17 = (int *)EVP_CIPHER_CTX_new();
v18 = v17;
if ( !v17 )
goto LABEL_18;
v19 = nullptr;
if ( !EVP_CipherInit_ex(v17, a1, nullptr, 0, v25, 0) )
{
v19 = nullptr;
goto LABEL_20;
}
if ( EVP_CIPHER_param_to_asn1((int)v18, (int)v14[1]) < 0 )
{
ERR_put_error(13, 167, 114, (int)"crypto/asn1/p5_pbev2.c", 84);
goto LABEL_20;
}
if ( a6 == -1 && EVP_CIPHER_CTX_ctrl((int)v18) <= 0 )
{
ERR_clear_error();
a6 = 799;
}
EVP_CIPHER_CTX_free(v18);
v20 = v10 == 37 ? EVP_CIPHER_key_length((int)a1) : -1;
X509_ALGOR_free((_DWORD *)*v13);
v21 = PKCS5_pbkdf2_set(a2, a3, a4, a6, v20);
*v13 = v21;
if ( v21 && (v19 = X509_ALGOR_new()) != nullptr )
{
*v19 = OBJ_nid2obj(0xA1u);
if ( ASN1_TYPE_pack_sequence((int)PBE2PARAM_it, (int)v13, (_DWORD **)v19 + 1) )
{
PBE2PARAM_free(v13);
return v19;
}
}
else
{
LABEL_18:
v19 = nullptr;
}
ERR_put_error(13, 167, 65, (int)"crypto/asn1/p5_pbev2.c", 134);
v18 = nullptr;
LABEL_20:
EVP_CIPHER_CTX_free(v18);
PBE2PARAM_free(v13);
X509_ALGOR_free(nullptr);
X509_ALGOR_free(v19);
return nullptr;
}