//
// sub_7FD12C from 0x7fd12c to 0x7fd39c (624 bytes)
//
// 3 xrefs:
// > ??> @ 0xa31580
// > ??> @ 0xa315b4
// > ??> @ 0xa315e8
//
// 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 sub_7FD12C(int a1, int a2, size_t a3, void *a4)
{
_DWORD *cipher_data; // r0
_DWORD *v9; // r5
void *v11; // r0
void *v12; // r0
__int16 v13; // r4
__int16 v14; // r4
int v15; // r0
_DWORD *v16; // r3
void *v17; // r0
cipher_data = (_DWORD *)EVP_CIPHER_CTX_get_cipher_data(a1);
v9 = cipher_data;
switch ( a2 )
{
case 0:
cipher_data[66] = 8;
cipher_data[62] = 0;
cipher_data[63] = 0;
cipher_data[64] = 0;
cipher_data[65] = 0;
cipher_data[67] = 12;
cipher_data[68] = -1;
return 1;
case 8:
v15 = EVP_CIPHER_CTX_get_cipher_data(a4);
v16 = (_DWORD *)v9[81];
if ( !v16 )
return 1;
if ( v16 != v9 )
return 0;
*(_DWORD *)(v15 + 324) = v15;
return 1;
case 9:
a3 = 15 - a3;
goto LABEL_3;
case 16:
if ( !EVP_CIPHER_CTX_encrypting(a1) || !v9[64] || !CRYPTO_ccm128_tag((int)(v9 + 70), a4) )
return 0;
v9[64] = 0;
v9[63] = 0;
v9[65] = 0;
return 1;
case 17:
if ( (a3 & 1) != 0 || a3 - 4 > 0xC )
return 0;
if ( EVP_CIPHER_CTX_encrypting(a1) )
{
if ( a4 )
return 0;
}
else if ( a4 )
{
v9[64] = 1;
v17 = (void *)EVP_CIPHER_CTX_buf_noconst(a1);
memcpy(v17, a4, a3);
}
v9[67] = a3;
return 1;
case 18:
if ( a3 != 4 )
return 0;
v11 = (void *)EVP_CIPHER_CTX_iv_noconst(a1);
memcpy(v11, a4, 4u);
return 1;
case 20:
LABEL_3:
if ( a3 - 2 > 6 )
return 0;
cipher_data[66] = a3;
return 1;
case 22:
if ( a3 != 13 )
return 0;
v12 = (void *)EVP_CIPHER_CTX_buf_noconst(a1);
memcpy(v12, a4, 0xDu);
v9[68] = 13;
v13 = *(unsigned __int8 *)(EVP_CIPHER_CTX_buf_noconst(a1) + 11);
v14 = (*(unsigned __int8 *)(EVP_CIPHER_CTX_buf_noconst(a1) + 12) | (unsigned __int16)(v13 << 8)) - 8;
if ( !EVP_CIPHER_CTX_encrypting(a1) )
v14 -= v9[67];
*(_BYTE *)(EVP_CIPHER_CTX_buf_noconst(a1) + 11) = HIBYTE(v14);
*(_BYTE *)(EVP_CIPHER_CTX_buf_noconst(a1) + 12) = v14;
return v9[67];
default:
return -1;
}
}