//
// PKCS5_pbe2_set_scrypt from 0x8c7494 to 0x8c7880 (1004 bytes)
//
// 1 xrefs:
// > ??> @ 0x6b92c
//
// 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_pbe2_set_scrypt(
int *a1,
char *a2,
int a3,
int *a4,
unsigned __int64 a5,
unsigned __int64 a6,
unsigned __int64 a7)
{
unsigned int v11; // r0
unsigned int v12; // r10
char **v13; // r11
char **v14; // r0
char **v15; // r4
char ***v16; // r9
char **v17; // r0
size_t v18; // r0
int *v19; // r0
_DWORD *v20; // r11
signed int **v21; // r0
int v22; // r5
signed int *v24; // r0
int v25; // r0
_BYTE v26[20]; // [sp+28h] [bp-14h] BYREF
if ( !a1 )
{
v15 = nullptr;
ERR_put_error(13, 231, 67, (int)"crypto/asn1/p5_scrypt.c", 62);
a4 = nullptr;
v20 = nullptr;
goto LABEL_34;
}
if ( !EVP_PBE_scrypt(0, 0, 0, 0, a5, HIDWORD(a5), a6, HIDWORD(a6), a7, HIDWORD(a7), 0, 0, 0, 0) )
{
v15 = nullptr;
ERR_put_error(13, 231, 227, (int)"crypto/asn1/p5_scrypt.c", 68);
a4 = nullptr;
v20 = nullptr;
goto LABEL_34;
}
v11 = EVP_CIPHER_type((int)a1);
v12 = v11;
if ( !v11 )
{
v15 = nullptr;
ERR_put_error(13, 231, 108, (int)"crypto/asn1/p5_scrypt.c", 75);
a4 = nullptr;
v20 = nullptr;
goto LABEL_34;
}
v13 = OBJ_nid2obj(v11);
v14 = (char **)PBE2PARAM_new();
v15 = v14;
if ( !v14 )
goto LABEL_38;
v16 = (char ***)v14[1];
*v16 = v13;
v17 = (char **)ASN1_TYPE_new();
v16[1] = v17;
if ( !v17 )
goto LABEL_38;
if ( EVP_CIPHER_iv_length((int)a1) )
{
if ( a4 )
{
v18 = EVP_CIPHER_iv_length((int)a1);
memcpy(v26, a4, v18);
}
else
{
v25 = EVP_CIPHER_iv_length((int)a1);
if ( RAND_bytes((int)v26, v25) < 0 )
{
v20 = nullptr;
goto LABEL_34;
}
}
}
v19 = (int *)EVP_CIPHER_CTX_new();
a4 = v19;
if ( !v19 )
{
LABEL_38:
v20 = nullptr;
goto LABEL_33;
}
v20 = nullptr;
if ( !EVP_CipherInit_ex(v19, a1, nullptr, 0, v26, 0) )
{
v20 = nullptr;
goto LABEL_34;
}
if ( EVP_CIPHER_param_to_asn1((int)a4, (int)v16[1]) < 0 )
{
ERR_put_error(13, 231, 114, (int)"crypto/asn1/p5_scrypt.c", 108);
goto LABEL_34;
}
EVP_CIPHER_CTX_free(a4);
if ( v12 == 37 )
v20 = (_DWORD *)EVP_CIPHER_key_length((int)a1);
X509_ALGOR_free(*v15);
v21 = (signed int **)SCRYPT_PARAMS_new();
v22 = (int)v21;
if ( !v21 )
goto LABEL_30;
if ( !a3 )
a3 = 8;
if ( !ASN1_STRING_set(*v21, a2, a3) )
goto LABEL_30;
if ( !a2 && RAND_bytes(*(_DWORD *)(*(_DWORD *)v22 + 8), a3) <= 0 )
goto LABEL_32;
if ( ASN1_INTEGER_set_uint64(*(signed int **)(v22 + 4), a5)
&& ASN1_INTEGER_set_uint64(*(signed int **)(v22 + 8), a6)
&& ASN1_INTEGER_set_uint64(*(signed int **)(v22 + 12), a7)
&& (!v20
|| (v24 = (signed int *)ASN1_INTEGER_new(), (*(_DWORD *)(v22 + 16) = v24) != 0)
&& ASN1_INTEGER_set_int64(v24, (unsigned int)v20))
&& (a2 = (char *)X509_ALGOR_new()) != nullptr )
{
*(_DWORD *)a2 = OBJ_nid2obj(0x3CDu);
if ( ASN1_TYPE_pack_sequence((int)byte_A3A58C, v22, (_DWORD **)a2 + 1) )
{
SCRYPT_PARAMS_free((_DWORD *)v22);
*v15 = a2;
v20 = X509_ALGOR_new();
if ( v20 )
{
*v20 = OBJ_nid2obj(0xA1u);
if ( ASN1_TYPE_pack_sequence((int)PBE2PARAM_it, (int)v15, (_DWORD **)v20 + 1) )
{
PBE2PARAM_free(v15);
return v20;
}
goto LABEL_33;
}
goto LABEL_38;
}
}
else
{
LABEL_30:
a2 = nullptr;
}
ERR_put_error(13, 232, 65, (int)"crypto/asn1/p5_scrypt.c", 218);
LABEL_32:
SCRYPT_PARAMS_free((_DWORD *)v22);
v20 = nullptr;
X509_ALGOR_free(a2);
*v15 = nullptr;
LABEL_33:
ERR_put_error(13, 231, 65, (int)"crypto/asn1/p5_scrypt.c", 148);
a4 = nullptr;
LABEL_34:
PBE2PARAM_free(v15);
X509_ALGOR_free(nullptr);
X509_ALGOR_free(v20);
EVP_CIPHER_CTX_free(a4);
return nullptr;
}