//
// ssl3_ctrl from 0xd38a10 to 0xd390ec (1756 bytes)
//
// 14 xrefs:
// > dtls1_ctrl @ 0xd5d408
// > ??> @ 0xc70f8
// > ??> @ 0x121f230
// > ??> @ 0x121f310
// > ??> @ 0x121f3f0
// > ??> @ 0x121f4d0
// > ??> @ 0x121f5b0
// > ??> @ 0x121f690
// > ??> @ 0x121f770
// > ??> @ 0x121f850
// > ??> @ 0x121f930
// > ??> @ 0x121fa10
// > ??> @ 0x121faf0
// > ??> @ 0x121fbd0
//
// 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 ssl3_ctrl(__int64 a1, int a2, size_t a3, char *a4)
{
char *v6; // x19
__int64 v7; // x5
__int64 v9; // x19
unsigned int v10; // w0
__int64 v11; // x0
__int64 server_send_pkey; // x0
__int64 v13; // x0
__int64 v14; // x1
__int64 v15; // x0
__int64 v16; // x22
void *v17; // x0
__int64 v18; // x0
__int64 v19; // x1
__int64 v20; // x2
__int64 v21; // x0
unsigned __int8 *v22; // x22
__int64 v23; // x20
unsigned __int8 *v24; // x23
int v25; // w0
int v26; // w21
unsigned int v27; // w21
int v28; // w0
__int64 v29; // x0
__int64 v30; // x0
int curve_name; // [xsp+4Ch] [xbp+4Ch] BYREF
v6 = a4;
switch ( a2 )
{
case 3:
if ( a4 )
{
v9 = ssl_dh_to_pkey((__int64)a4);
if ( v9 )
{
v10 = EVP_PKEY_security_bits();
if ( (unsigned int)ssl_security(a1, 262151, v10, 0, v9) )
{
EVP_PKEY_free(*(_QWORD *)(*(_QWORD *)(a1 + 328) + 8LL));
v7 = 1;
*(_QWORD *)(*(_QWORD *)(a1 + 328) + 8LL) = v9;
}
else
{
ERR_put_error(20, 213, 394, "ssl/s3_lib.c", 2919);
EVP_PKEY_free(v9);
return 0;
}
}
else
{
ERR_put_error(20, 213, 65, "ssl/s3_lib.c", 2914);
return 0;
}
}
else
{
ERR_put_error(20, 213, 67, "ssl/s3_lib.c", 2909);
return (__int64)v6;
}
return v7;
case 4:
if ( a4 )
{
if ( EC_KEY_get0_group(a4) )
{
curve_name = EC_GROUP_get_curve_name();
v7 = 0;
if ( curve_name )
return (int)tls1_set_curves(a1 + 672, a1 + 664, &curve_name, 1);
}
else
{
ERR_put_error(20, 213, 124, "ssl/s3_lib.c", 2949);
return 0;
}
}
else
{
ERR_put_error(20, 213, 67, "ssl/s3_lib.c", 2944);
return (__int64)v6;
}
return v7;
case 6:
ERR_put_error(20, 213, 66, "ssl/s3_lib.c", 2930);
return 0;
case 10:
return *(int *)(*(_QWORD *)(a1 + 144) + 260LL);
case 11:
v29 = *(_QWORD *)(a1 + 144);
LODWORD(v7) = *(_DWORD *)(v29 + 260);
*(_DWORD *)(v29 + 260) = 0;
return (int)v7;
case 12:
return *(int *)(*(_QWORD *)(a1 + 144) + 256LL);
case 13:
return **(int **)(a1 + 144);
case 55:
if ( a3 )
{
ERR_put_error(20, 213, 320, "ssl/s3_lib.c", 2981);
return 0;
}
else
{
CRYPTO_free(*(_QWORD *)(a1 + 552), "ssl/s3_lib.c", 2965);
*(_QWORD *)(a1 + 552) = a3;
if ( !v6 )
return 1;
if ( strlen(v6) - 1 > 0xFE )
{
ERR_put_error(20, 213, 319, "ssl/s3_lib.c", 2973);
return a3;
}
else
{
v30 = CRYPTO_strdup(v6, "ssl/s3_lib.c", 2976);
*(_QWORD *)(a1 + 552) = v30;
if ( v30 )
return 1;
ERR_put_error(20, 213, 68, "ssl/s3_lib.c", 2977);
return a3;
}
}
case 57:
*(_QWORD *)(a1 + 544) = a4;
return 1;
case 65:
*(_DWORD *)(a1 + 564) = a3;
return 1;
case 66:
v7 = 1;
*(_QWORD *)a4 = *(_QWORD *)(a1 + 624);
return v7;
case 67:
*(_QWORD *)(a1 + 624) = a4;
return 1;
case 68:
v7 = 1;
*(_QWORD *)a4 = *(_QWORD *)(a1 + 616);
return v7;
case 69:
*(_QWORD *)(a1 + 616) = a4;
return 1;
case 70:
*(_QWORD *)a4 = *(_QWORD *)(a1 + 632);
return *(int *)(a1 + 640);
case 71:
CRYPTO_free(*(_QWORD *)(a1 + 632), "ssl/s3_lib.c", 3024);
*(_QWORD *)(a1 + 632) = v6;
*(_DWORD *)(a1 + 640) = a3;
return 1;
case 88:
if ( a3 )
return (int)ssl_cert_set1_chain(a1, 0, a4);
else
return (int)ssl_cert_set0_chain(a1, 0, a4);
case 89:
if ( a3 )
return (int)ssl_cert_add1_chain_cert(a1, 0, a4);
else
return (int)ssl_cert_add0_chain_cert(a1, 0, a4);
case 90:
v21 = *(_QWORD *)(a1 + 376);
if ( !v21 )
return 0;
v22 = *(unsigned __int8 **)(v21 + 296);
v23 = *(_QWORD *)(v21 + 288) >> 1;
if ( a4 && v23 )
{
v24 = &v22[2 * v23];
do
{
v25 = *v22;
v26 = v22[1];
v22 += 2;
v27 = v26 | (v25 << 8);
v28 = tls1_ec_curve_id2nid(v27, 0);
if ( v28 )
*(_DWORD *)v6 = v28;
else
*(_DWORD *)v6 = v27 | 0x1000000;
v6 += 4;
}
while ( v22 != v24 );
}
return (int)v23;
case 91:
return (int)tls1_set_curves(a1 + 672, a1 + 664, a4, a3);
case 92:
return (int)tls1_set_curves_list(a1 + 672, a1 + 664, a4);
case 93:
return (int)tls1_shared_curve(a1, (unsigned int)a3);
case 97:
return (int)tls1_set_sigalgs(*(_QWORD *)(a1 + 328), a4, a3, 0);
case 98:
return (int)tls1_set_sigalgs_list(*(_QWORD *)(a1 + 328), a4, 0);
case 101:
return (int)tls1_set_sigalgs(*(_QWORD *)(a1 + 328), a4, a3, 1);
case 102:
return (int)tls1_set_sigalgs_list(*(_QWORD *)(a1 + 328), a4, 1);
case 103:
if ( *(_DWORD *)(a1 + 56) )
return 0;
v18 = *(_QWORD *)(a1 + 144);
if ( !*(_DWORD *)(v18 + 568) )
return 0;
v19 = *(_QWORD *)(a1 + 328);
v20 = *(_QWORD *)(v19 + 312);
if ( v20 )
{
if ( a4 )
{
*(_QWORD *)a4 = v20;
v19 = *(_QWORD *)(a1 + 328);
}
return *(int *)(v19 + 320);
}
else
{
if ( a4 )
{
*(_QWORD *)a4 = v18 + 576;
v18 = *(_QWORD *)(a1 + 144);
}
return *(int *)(v18 + 572);
}
case 104:
if ( !*(_DWORD *)(a1 + 56) )
return 0;
v16 = *(_QWORD *)(a1 + 328);
CRYPTO_free(*(_QWORD *)(v16 + 312), "ssl/s3_lib.c", 3752);
*(_QWORD *)(v16 + 312) = 0;
if ( !v6 || !a3 )
return 1;
if ( a3 <= 0xFF )
{
v17 = (void *)CRYPTO_malloc(a3, "ssl/s3_lib.c", 3758);
*(_QWORD *)(v16 + 312) = v17;
if ( v17 )
{
memcpy(v17, v6, a3);
*(_QWORD *)(v16 + 320) = a3;
return 1;
}
}
return 0;
case 105:
return (int)ssl_build_cert_chain(a1, 0);
case 106:
return (int)ssl_cert_set_cert_store(*(_QWORD *)(a1 + 328), a4, 0, (unsigned int)a3);
case 107:
return (int)ssl_cert_set_cert_store(*(_QWORD *)(a1 + 328), a4, 1, (unsigned int)a3);
case 108:
if ( (*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 192LL) + 104LL) & 2) == 0 )
return 0;
if ( !*(_QWORD *)(a1 + 376) )
return 0;
v15 = *(_QWORD *)(*(_QWORD *)(a1 + 144) + 720LL);
if ( !v15 )
return 0;
*(_DWORD *)a4 = EVP_MD_type(v15);
return 1;
case 109:
if ( *(_DWORD *)(a1 + 56) || !*(_QWORD *)(a1 + 376) || !*(_QWORD *)(*(_QWORD *)(a1 + 144) + 1016LL) )
return 0;
EVP_PKEY_up_ref();
v7 = 1;
*(_QWORD *)v6 = *(_QWORD *)(*(_QWORD *)(a1 + 144) + 1016LL);
return v7;
case 111:
v13 = *(_QWORD *)(a1 + 376);
if ( !v13 )
return 0;
v14 = *(_QWORD *)(v13 + 280);
if ( !v14 )
return 0;
*(_QWORD *)a4 = v14;
return *(int *)(v13 + 272);
case 115:
v7 = 0;
*(_QWORD *)a4 = *(_QWORD *)(**(_QWORD **)(a1 + 328) + 16LL);
return v7;
case 116:
return (int)ssl_cert_select_current(*(_QWORD *)(a1 + 328), a4);
case 117:
if ( a3 != 3 )
return (int)ssl_cert_set_current(*(_QWORD *)(a1 + 328), a3);
if ( !*(_DWORD *)(a1 + 56) )
return 0;
v11 = *(_QWORD *)(*(_QWORD *)(a1 + 144) + 552LL);
if ( !v11 )
return 0;
v7 = 2;
if ( (*(_DWORD *)(v11 + 24) & 0x44) == 0 )
{
server_send_pkey = ssl_get_server_send_pkey(a1);
if ( !server_send_pkey )
return 0;
v7 = 1;
**(_QWORD **)(a1 + 328) = server_send_pkey;
}
return v7;
case 118:
v7 = 1;
*(_DWORD *)(*(_QWORD *)(a1 + 328) + 24LL) = a3;
return v7;
case 127:
return *(int *)(a1 + 564);
default:
return 0;
}
}