//
// sub_A12824 from 0xa12824 to 0xa12af4 (720 bytes)
//
// 3 xrefs:
// > ??> @ 0xc789c0
// > ??> @ 0xc789f4
// > ??> @ 0xc78a28
//
// 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:07:47 +0000
//
int __fastcall sub_A12824(int a1, int a2, char *a3, size_t a4)
{
size_t *v4; // r11
_DWORD *cipher_data; // r0
_DWORD *v10; // r4
_DWORD *v11; // r3
int v12; // r6
int v13; // r3
size_t v14; // r10
size_t v15; // r5
bool v16; // zf
_DWORD *v17; // r0
size_t v19; // r6
bool v20; // cf
char *v21; // r0
_DWORD *v22; // r0
int v23; // r5
int v24; // r0
_DWORD *v25; // r1
int v26; // r3
_DWORD *v27; // r0
void *v28; // [sp+0h] [bp-Ch]
int v29; // [sp+4h] [bp-8h]
cipher_data = (_DWORD *)EVP_CIPHER_CTX_get_cipher_data(a1);
v10 = cipher_data;
if ( !cipher_data[125] )
return -1;
v11 = (_DWORD *)cipher_data[124];
if ( !v11 )
return -1;
if ( a3 )
{
if ( a2 )
{
cipher_data = (_DWORD *)cipher_data[181];
}
else
{
v11 = cipher_data + 177;
v4 = cipher_data + 182;
}
if ( a2 )
v11 = v10 + 173;
else
cipher_data = (_DWORD *)cipher_data[182];
v28 = v11;
if ( a2 )
v4 = v10 + 181;
if ( cipher_data )
{
v19 = 16 - (_DWORD)cipher_data;
v20 = a4 >= 16 - (int)cipher_data;
v21 = (char *)cipher_data + (_DWORD)v11;
if ( !v20 )
{
memcpy(v21, a3, a4);
*v4 += a4;
return 0;
}
memcpy(v21, a3, v19);
a4 -= v19;
a3 += v19;
if ( a2 )
{
v16 = EVP_CIPHER_CTX_encrypting(a1) == 0;
v22 = v10 + 126;
if ( v16 )
{
if ( !CRYPTO_ocb128_decrypt(v22, v28, a2, 16) )
return -1;
}
else if ( !CRYPTO_ocb128_encrypt(v22, v28, a2, 16) )
{
return -1;
}
}
else if ( !CRYPTO_ocb128_aad(v10 + 126, v28) )
{
return -1;
}
v12 = 16;
*v4 = 0;
v13 = 16;
}
else
{
v12 = 0;
v13 = 0;
}
v14 = a4 & 0xF;
if ( a4 == v14 )
goto LABEL_20;
if ( !a2 )
{
v15 = a4 - v14;
if ( !CRYPTO_ocb128_aad(v10 + 126, a3) )
return -1;
goto LABEL_19;
}
v15 = a4 - v14;
v16 = EVP_CIPHER_CTX_encrypting(a1) == 0;
v17 = v10 + 126;
if ( !v16 )
{
if ( !CRYPTO_ocb128_encrypt(v17, a3, a2, v15) )
return -1;
goto LABEL_19;
}
if ( CRYPTO_ocb128_decrypt(v17, a3, a2, v15) )
{
LABEL_19:
v13 = v15 + v12;
a3 += v15;
LABEL_20:
if ( !v14 )
return v13;
v29 = v13;
memcpy(v28, a3, v14);
*v4 = v14;
return v29;
}
return -1;
}
if ( cipher_data[181] )
{
v24 = EVP_CIPHER_CTX_encrypting(a1);
v25 = v10 + 173;
v26 = v10[181];
v16 = v24 == 0;
v27 = v10 + 126;
if ( v16 )
{
if ( !CRYPTO_ocb128_decrypt(v27, v25, a2, v26) )
return -1;
}
else if ( !CRYPTO_ocb128_encrypt(v27, v25, a2, v26) )
{
return -1;
}
v23 = v10[181];
v10[181] = 0;
}
else
{
v23 = 0;
}
if ( v10[182] )
{
if ( !CRYPTO_ocb128_aad(v10 + 126, v10 + 177) )
return -1;
v10[182] = 0;
}
if ( EVP_CIPHER_CTX_encrypting(a1) )
{
if ( CRYPTO_ocb128_tag(v10 + 126, v10 + 169, 16) != 1 )
return -1;
v10[125] = 0;
return v23;
}
else
{
if ( (int)v10[184] < 0 || CRYPTO_ocb128_finish(v10 + 126, v10 + 169) )
return -1;
v10[125] = 0;
return v23;
}
}