//
// PKCS5_pbe2_set_scrypt from 0xe72e0c to 0xe731c8 (956 bytes)
//
// 1 xrefs:
// > ??> @ 0x9be98
//
// 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 PKCS5_pbe2_set_scrypt(
__int64 a1,
__int64 a2,
unsigned int a3,
void *a4,
unsigned __int64 a5,
unsigned __int64 a6,
unsigned __int64 a7)
{
__int64 v7; // x21
unsigned int v14; // w0
unsigned int v15; // w25
char **v16; // x26
__int64 v17; // x0
__int64 *v18; // x19
char ***v19; // x24
__int64 v20; // x0
int v21; // w0
__int64 v22; // x0
__int64 v23; // x24
__int64 *v24; // x0
__int64 *v25; // x20
__int64 v27; // x0
unsigned int v28; // w0
_BYTE v29[16]; // [xsp+80h] [xbp+70h] BYREF
v7 = a1;
if ( !a1 )
{
v18 = nullptr;
a4 = nullptr;
ERR_put_error(13, 231, 67, (__int64)"crypto/asn1/p5_scrypt.c", 62);
goto LABEL_34;
}
if ( !(unsigned int)EVP_PBE_scrypt(0, 0, 0, 0, a5, a6, a7, 0, 0, 0) )
{
v18 = nullptr;
ERR_put_error(13, 231, 227, (__int64)"crypto/asn1/p5_scrypt.c", 68);
a4 = nullptr;
v7 = 0;
goto LABEL_34;
}
v14 = EVP_CIPHER_type((unsigned int *)v7);
v15 = v14;
if ( !v14 )
{
v18 = nullptr;
ERR_put_error(13, 231, 108, (__int64)"crypto/asn1/p5_scrypt.c", 75);
a4 = nullptr;
v7 = 0;
goto LABEL_34;
}
v16 = OBJ_nid2obj(v14);
v17 = PBE2PARAM_new();
v18 = (__int64 *)v17;
if ( !v17 )
goto LABEL_38;
v19 = *(char ****)(v17 + 8);
*v19 = v16;
v20 = ASN1_TYPE_new();
v19[1] = (char **)v20;
if ( !v20 )
goto LABEL_38;
if ( (unsigned int)EVP_CIPHER_iv_length(v7) )
{
if ( a4 )
{
v21 = EVP_CIPHER_iv_length(v7);
memcpy(v29, a4, v21);
}
else
{
v28 = EVP_CIPHER_iv_length(v7);
if ( (RAND_bytes((__int64)v29, v28) & 0x80000000) != 0 )
{
v7 = 0;
goto LABEL_34;
}
}
}
v22 = EVP_CIPHER_CTX_new();
a4 = (void *)v22;
if ( !v22 )
{
LABEL_38:
v7 = 0;
goto LABEL_33;
}
if ( !(unsigned int)EVP_CipherInit_ex(v22, (unsigned int *)v7, 0, 0, v29, 0) )
{
v7 = 0;
goto LABEL_34;
}
if ( (EVP_CIPHER_param_to_asn1((__int64)a4, (__int64)v19[1]) & 0x80000000) != 0 )
{
v7 = 0;
ERR_put_error(13, 231, 114, (__int64)"crypto/asn1/p5_scrypt.c", 108);
goto LABEL_34;
}
v23 = 0;
EVP_CIPHER_CTX_free((__int64 *)a4);
if ( v15 == 37 )
v23 = (int)EVP_CIPHER_key_length(v7);
X509_ALGOR_free(*v18);
v24 = (__int64 *)SCRYPT_PARAMS_new();
v25 = v24;
if ( !v24 )
goto LABEL_30;
if ( !a3 )
a3 = 8;
if ( !(unsigned int)ASN1_STRING_set(*v24, (char *)a2, a3) )
goto LABEL_30;
if ( !a2 && (int)RAND_bytes(*(_QWORD *)(*v25 + 8), a3) <= 0 )
goto LABEL_32;
if ( (unsigned int)ASN1_INTEGER_set_uint64(v25[1], a5)
&& (unsigned int)ASN1_INTEGER_set_uint64(v25[2], a6)
&& (unsigned int)ASN1_INTEGER_set_uint64(v25[3], a7)
&& (!v23 || (v27 = ASN1_INTEGER_new(), (v25[4] = v27) != 0) && (unsigned int)ASN1_INTEGER_set_int64(v27, v23))
&& (a2 = X509_ALGOR_new()) != 0 )
{
*(_QWORD *)a2 = OBJ_nid2obj(0x3CDu);
if ( ASN1_TYPE_pack_sequence((__int64)byte_11333F0, (__int64)v25, (__int64 *)(a2 + 8)) )
{
SCRYPT_PARAMS_free((__int64)v25);
*v18 = a2;
v7 = X509_ALGOR_new();
if ( v7 )
{
*(_QWORD *)v7 = OBJ_nid2obj(0xA1u);
if ( ASN1_TYPE_pack_sequence((__int64)PBE2PARAM_it, (__int64)v18, (__int64 *)(v7 + 8)) )
{
PBE2PARAM_free((__int64)v18);
return v7;
}
goto LABEL_33;
}
goto LABEL_38;
}
}
else
{
LABEL_30:
a2 = 0;
}
ERR_put_error(13, 232, 65, (__int64)"crypto/asn1/p5_scrypt.c", 218);
LABEL_32:
v7 = 0;
SCRYPT_PARAMS_free((__int64)v25);
X509_ALGOR_free(a2);
*v18 = 0;
LABEL_33:
a4 = nullptr;
ERR_put_error(13, 231, 65, (__int64)"crypto/asn1/p5_scrypt.c", 148);
LABEL_34:
PBE2PARAM_free((__int64)v18);
X509_ALGOR_free(0);
X509_ALGOR_free(v7);
EVP_CIPHER_CTX_free((__int64 *)a4);
return 0;
}