//
// ssl_derive from 0x78f160 to 0x78f2ac (332 bytes)
//
// 5 xrefs:
// > tls_construct_client_key_exchange @ 0x7a23ec
// > tls_construct_client_key_exchange @ 0x7a25e8
// > tls_process_client_key_exchange @ 0x7aba14
// > tls_process_client_key_exchange @ 0x7aba80
// > ??> @ 0x5ae9c
//
// 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
//
int __fastcall ssl_derive(_DWORD *a1, int a2, int a3)
{
bool v3; // zf
int v4; // r4
int v8; // r7
const void *v9; // r5
int v10; // r2
size_t v11; // r1
_BOOL4 master_secret; // r0
size_t v13; // [sp+4h] [bp-4h] BYREF
v3 = a3 == 0;
if ( a3 )
v3 = a2 == 0;
v4 = v3;
v13 = 0;
if ( v3 )
return 0;
v8 = EVP_PKEY_CTX_new(a2, v4, a3, 0);
if ( EVP_PKEY_derive_init() <= 0 )
{
v9 = (const void *)v4;
v11 = v13;
goto LABEL_16;
}
if ( EVP_PKEY_derive_set_peer(v8, a3) <= 0 || EVP_PKEY_derive(v8, v4, &v13) <= 0 )
{
v11 = v13;
v9 = (const void *)v4;
goto LABEL_16;
}
v9 = (const void *)CRYPTO_malloc(v13, "ssl/s3_lib.c", 4083);
if ( !v9 )
{
v11 = v13;
v4 = 0;
goto LABEL_16;
}
if ( EVP_PKEY_derive(v8, v9, &v13) <= 0 )
{
LABEL_20:
v11 = v13;
goto LABEL_16;
}
if ( a1[7] )
{
master_secret = ssl_generate_master_secret(a1, v9, v13, 1);
v9 = (const void *)v4;
v4 = master_secret;
goto LABEL_20;
}
v10 = a1[26];
v11 = v13;
*(_DWORD *)(v10 + 600) = v9;
v4 = 1;
v9 = nullptr;
*(_DWORD *)(v10 + 604) = v11;
LABEL_16:
CRYPTO_clear_free(v9, v11, "ssl/s3_lib.c", 4103);
EVP_PKEY_CTX_free(v8);
return v4;
}