//
// sub_7FD8A8 from 0x7fd8a8 to 0x7fda80 (472 bytes)
//
// 6 xrefs:
// > ??> @ 0xa31608
// > ??> @ 0xa3163c
// > ??> @ 0xa31670
// > ??> @ 0xa316a4
// > ??> @ 0xa316d8
// > ??> @ 0xa3170c
//
// 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_7FD8A8(int a1, void *a2, void *a3, size_t a4)
{
int cipher_data; // r10
_BOOL4 v9; // r9
int result; // r0
cipher_data = EVP_CIPHER_CTX_get_cipher_data(a1);
v9 = EVP_CIPHER_CTX_iv_length(a1) == 4;
if ( !a3 )
return 0;
if ( !a4 )
return -1;
if ( EVP_CIPHER_CTX_encrypting(a1) )
{
if ( v9 )
{
if ( a2 )
goto LABEL_8;
if ( EVP_CIPHER_CTX_encrypting(a1) )
goto LABEL_27;
}
else
{
if ( (a4 & 7) != 0 )
return -1;
if ( a2 )
goto LABEL_15;
if ( EVP_CIPHER_CTX_encrypting(a1) )
return a4 + 8;
}
return a4 - 8;
}
if ( a4 <= 0xF || (a4 & 7) != 0 )
return -1;
if ( !a2 )
{
if ( EVP_CIPHER_CTX_encrypting(a1) )
{
if ( v9 )
LABEL_27:
a4 = (a4 + 7) & 0xFFFFFFF8;
return a4 + 8;
}
return a4 - 8;
}
if ( !v9 )
{
LABEL_15:
if ( EVP_CIPHER_CTX_encrypting(a1) )
result = CRYPTO_128_wrap(cipher_data, *(_DWORD *)(cipher_data + 248), (int)a2, a3, a4, (int)AES_encrypt);
else
result = CRYPTO_128_unwrap(cipher_data, *(_DWORD *)(cipher_data + 248), a2, a3, a4, AES_decrypt);
goto LABEL_17;
}
LABEL_8:
if ( EVP_CIPHER_CTX_encrypting(a1) )
{
result = CRYPTO_128_wrap_pad(cipher_data, *(_DWORD *)(cipher_data + 248), a2, a3, a4, AES_encrypt);
if ( result )
return result;
return -1;
}
result = CRYPTO_128_unwrap_pad(cipher_data, *(_DWORD *)(cipher_data + 248), a2, a3, a4, (int)AES_decrypt);
LABEL_17:
if ( !result )
return -1;
return result;
}