//
// EVP_BytesToKey from 0xe61610 to 0xe618c8 (696 bytes)
//
// 3 xrefs:
// > PEM_do_header @ 0xdc71f4
// > PEM_ASN1_write_bio @ 0xdc7af4
// > ??> @ 0xbd450
//
// 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 EVP_BytesToKey(
__int64 a1,
__int64 a2,
__int64 a3,
__int64 a4,
__int64 a5,
unsigned int a6,
_BYTE *a7,
_BYTE *a8)
{
int v16; // w23
int v17; // w0
int v18; // w26
__int64 *v19; // x19
int i; // s10
int v21; // w20
unsigned int v22; // w23
int v24; // w5
int v25; // w1
__int64 v26; // x6
int v27; // w1
int v28; // [xsp+9Ch] [xbp+9Ch] BYREF
_BYTE v29[64]; // [xsp+A0h] [xbp+A0h] BYREF
v28 = 0;
v16 = EVP_CIPHER_key_length(a1);
v17 = EVP_CIPHER_iv_length(a1);
v18 = v17;
if ( v16 > 64 )
OPENSSL_die("assertion failed: nkey <= EVP_MAX_KEY_LENGTH", "crypto/evp/evp_key.c", 86);
if ( v17 > 16 )
OPENSSL_die("assertion failed: niv <= EVP_MAX_IV_LENGTH", "crypto/evp/evp_key.c", 87);
if ( !a4 )
return (unsigned int)v16;
v19 = (__int64 *)EVP_MD_CTX_new();
if ( v19 )
{
for ( i = 0; ; ++i )
{
while ( 1 )
{
if ( !(unsigned int)EVP_DigestInit_ex(v19, a2, 0)
|| i && !(unsigned int)EVP_DigestUpdate((__int64)v19)
|| !(unsigned int)EVP_DigestUpdate((__int64)v19)
|| a3 && !(unsigned int)EVP_DigestUpdate((__int64)v19)
|| !(unsigned int)EVP_DigestFinal_ex((int **)v19, (__int64)v29, &v28) )
{
goto LABEL_18;
}
if ( a6 > 1 )
{
v21 = 1;
while ( (unsigned int)EVP_DigestInit_ex(v19, a2, 0)
&& (unsigned int)EVP_DigestUpdate((__int64)v19)
&& (unsigned int)EVP_DigestFinal_ex((int **)v19, (__int64)v29, &v28) )
{
if ( ++v21 == a6 )
{
if ( v16 )
goto LABEL_24;
v24 = 0;
goto LABEL_39;
}
}
goto LABEL_18;
}
v24 = v16;
if ( v16 )
break;
LABEL_30:
if ( v18 )
{
v27 = v28;
if ( v24 != v28 )
goto LABEL_32;
}
LABEL_36:
++i;
if ( !(v16 | v18) )
goto LABEL_37;
}
LABEL_24:
v24 = v28;
if ( !v28 )
goto LABEL_30;
v25 = v16 - v28;
v26 = 0;
while ( 1 )
{
if ( a7 )
*a7++ = v29[v26];
--v16;
v24 = v26 + 1;
if ( !v16 )
break;
++v26;
if ( v16 == v25 )
goto LABEL_30;
}
LABEL_39:
if ( !v18 )
{
LABEL_37:
v22 = EVP_CIPHER_key_length(a1);
goto LABEL_19;
}
v27 = v28;
v16 = 0;
if ( v24 != v28 )
{
do
{
LABEL_32:
if ( a8 )
*a8++ = v29[v24];
--v18;
++v24;
}
while ( v18 && v27 != v24 );
goto LABEL_36;
}
}
}
LABEL_18:
v22 = 0;
LABEL_19:
EVP_MD_CTX_free(v19);
OPENSSL_cleanse(v29, 0x40u);
return v22;
}