//
// ssl_derive from 0x9a3d64 to 0x9a3eb0 (332 bytes)
//
// 5 xrefs:
// > tls_construct_client_key_exchange @ 0x9b6ff0
// > tls_construct_client_key_exchange @ 0x9b71ec
// > tls_process_client_key_exchange @ 0x9c0618
// > tls_process_client_key_exchange @ 0x9c0684
// > ??> @ 0x7491c
//
// 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:06:49 +0000
//
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;
}