//
// EVP_PKEY_derive_set_peer from 0x806630 to 0x806820 (496 bytes)
//
// 6 xrefs:
// > ssl_derive @ 0x78f1bc
// > tls_process_client_key_exchange @ 0x7ab094
// > sub_7DF150 @ 0x7df860
// > sub_7E3D80 @ 0x7e4544
// > cms_RecipientInfo_kari_encrypt @ 0x874d1c
// > ??> @ 0x5aebc
//
// 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 EVP_PKEY_derive_set_peer(_DWORD *a1, _DWORD *a2)
{
_DWORD *v3; // r3
int (__fastcall *v5)(_DWORD *, int, _DWORD, _DWORD *); // r12
int v6; // r3
int result; // r0
_DWORD *v9; // r3
_DWORD *v10; // r3
if ( a1
&& (v3 = (_DWORD *)*a1) != nullptr
&& (v3[24] || v3[20] || v3[22])
&& (v5 = (int (__fastcall *)(_DWORD *, int, _DWORD, _DWORD *))v3[25]) != nullptr )
{
v6 = a1[4];
if ( v6 != 1024 && ((v6 - 256) & 0xFFFFFEFF) != 0 )
{
ERR_put_error(6, 155, 151, (int)"crypto/evp/pmeth_fn.c", 233);
return -1;
}
else
{
result = v5(a1, 2, 0, a2);
if ( result > 0 )
{
if ( result == 2 )
{
return 1;
}
else
{
v9 = (_DWORD *)a1[2];
if ( v9 )
{
if ( *v9 == *a2 )
{
if ( EVP_PKEY_missing_parameters((int)a2) || EVP_PKEY_cmp_parameters((_DWORD *)a1[2], a2) )
{
EVP_PKEY_free(a1[3]);
v10 = (_DWORD *)*a1;
a1[3] = a2;
result = ((int (__fastcall *)(_DWORD *, int, int, _DWORD *))v10[25])(a1, 2, 1, a2);
if ( result > 0 )
{
EVP_PKEY_up_ref((int)a2);
return 1;
}
else
{
a1[3] = 0;
}
}
else
{
ERR_put_error(6, 155, 153, (int)"crypto/evp/pmeth_fn.c", 264);
return -1;
}
}
else
{
ERR_put_error(6, 155, 101, (int)"crypto/evp/pmeth_fn.c", 251);
return -1;
}
}
else
{
ERR_put_error(6, 155, 154, (int)"crypto/evp/pmeth_fn.c", 246);
return -1;
}
}
}
}
}
else
{
ERR_put_error(6, 155, 150, (int)"crypto/evp/pmeth_fn.c", 226);
return -2;
}
return result;
}