//
// sub_817860 from 0x817860 to 0x817a10 (432 bytes)
//
// 5 xrefs:
// > CRYPTO_ocb128_aad @ 0x818238
// > CRYPTO_ocb128_encrypt @ 0x8184e0
// > CRYPTO_ocb128_encrypt @ 0x818aac
// > CRYPTO_ocb128_decrypt @ 0x818d68
// > CRYPTO_ocb128_decrypt @ 0x819338
//
// 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
//
_BYTE *__fastcall sub_817860(int a1, unsigned int a2)
{
unsigned int v2; // r4
unsigned int v3; // r3
_BYTE *result; // r0
int v7; // lr
unsigned int v8; // r9
int v9; // r10
_BYTE *v10; // r3
unsigned int v11; // r12
unsigned int v12; // r8
unsigned int v13; // r9
unsigned int v14; // r11
unsigned int v15; // r8
unsigned int v16; // r9
unsigned int v17; // r8
unsigned int v18; // r9
int v19; // r12
unsigned int v20; // r10
unsigned int v21; // r9
unsigned int v22; // r10
unsigned int v23; // r9
unsigned int v24; // r10
unsigned int v25; // r8
char v26; // r2
unsigned int v27; // r1
v2 = *(_DWORD *)(a1 + 20);
if ( v2 >= a2 )
return (_BYTE *)(*(_DWORD *)(a1 + 64) + 16 * a2);
v3 = *(_DWORD *)(a1 + 24);
if ( a2 < v3 )
{
result = *(_BYTE **)(a1 + 64);
goto LABEL_5;
}
v27 = ((4 - v3 + a2) & 0xFFFFFFFC) + v3;
*(_DWORD *)(a1 + 24) = v27;
result = CRYPTO_realloc(*(void **)(a1 + 64), (void *)(16 * v27), (int)"crypto/modes/ocb128.c", 122);
if ( result )
{
*(_DWORD *)(a1 + 64) = result;
LABEL_5:
v7 = 16 * v2;
do
{
v8 = (unsigned __int8)result[v7 + 14];
v9 = (unsigned __int8)result[v7 + 15];
v10 = &result[v7 + 16];
v11 = (unsigned __int8)result[v7];
v10[14] = (2 * v8) | (result[v7 + 15] >> 7);
v12 = (unsigned __int8)result[v7 + 13];
v10[13] = (2 * v12) | (v8 >> 7);
v13 = (unsigned __int8)result[v7 + 12];
++v2;
v10[12] = (2 * v13) | (v12 >> 7);
v14 = (unsigned __int8)result[v7 + 11];
v10[11] = (2 * v14) | (v13 >> 7);
v15 = (unsigned __int8)result[v7 + 10];
v10[10] = (2 * v15) | (v14 >> 7);
v16 = (unsigned __int8)result[v7 + 9];
v10[9] = (2 * v16) | (v15 >> 7);
v17 = (unsigned __int8)result[v7 + 8];
v10[8] = (2 * v17) | (v16 >> 7);
v18 = (unsigned __int8)result[v7 + 7];
v19 = (135 * (v11 >> 7)) ^ (2 * v9);
v10[7] = (2 * v18) | (v17 >> 7);
v20 = (unsigned __int8)result[v7 + 6];
v10[6] = (2 * v20) | (v18 >> 7);
v21 = (unsigned __int8)result[v7 + 5];
v10[5] = (2 * v21) | (v20 >> 7);
v22 = (unsigned __int8)result[v7 + 4];
v10[4] = (2 * v22) | (v21 >> 7);
v23 = (unsigned __int8)result[v7 + 3];
v10[3] = (2 * v23) | (v22 >> 7);
v24 = (unsigned __int8)result[v7 + 2];
v10[2] = (2 * v24) | (v23 >> 7);
v25 = (unsigned __int8)result[v7 + 1];
v10[1] = (2 * v25) | (v24 >> 7);
v26 = result[v7];
v7 += 16;
result[v7] = (2 * v26) | (v25 >> 7);
v10[15] = v19;
result = *(_BYTE **)(a1 + 64);
}
while ( v2 != a2 );
*(_DWORD *)(a1 + 20) = v2;
result += 16 * v2;
}
return result;
}