//
// BF_set_key from 0x8c8f38 to 0x8c903c (260 bytes)
//
// 2 xrefs:
// > sub_8B634C @ 0x8b6374
// > ??> @ 0x6af3c
//
// 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
//
unsigned int *__fastcall BF_set_key(_DWORD *a1, int a2, unsigned __int8 *a3)
{
unsigned int v6; // r2
int *v7; // r12
unsigned __int8 *v8; // r3
unsigned __int8 *v9; // r6
unsigned __int8 *v10; // r0
int v11; // r7
unsigned __int8 *v12; // r3
int v13; // r1
int v14; // r6
int v15; // r0
int v16; // r1
int v17; // r6
int v18; // t1
int v19; // r1
_DWORD *v20; // r4
int v21; // r3
unsigned int *result; // r0
int v23; // r3
unsigned int v24; // [sp+0h] [bp-Ch] BYREF
int v25; // [sp+4h] [bp-8h]
memcpy(a1, &unk_A220D0, 0x1048u);
if ( a2 > 72 )
v6 = (unsigned int)(a3 + 72);
else
v6 = (unsigned int)&a3[a2];
v7 = a1 - 1;
v8 = a3;
do
{
v9 = v8 + 1;
if ( v6 <= (unsigned int)(v8 + 1) )
v9 = a3;
v10 = v9 + 1;
if ( v6 <= (unsigned int)(v9 + 1) )
v10 = a3;
v11 = *v8;
v12 = v10 + 1;
v13 = *v9;
v14 = *v10;
if ( v6 <= (unsigned int)(v10 + 1) )
v12 = a3;
v15 = *v12;
v16 = v14 | ((v13 | (v11 << 8)) << 8);
v8 = v12 + 1;
v18 = v7[1];
++v7;
v17 = v18;
v19 = v15 | (v16 << 8);
if ( v6 <= (unsigned int)v8 )
v8 = a3;
*v7 = v19 ^ v17;
}
while ( v7 != a1 + 17 );
v20 = a1;
v24 = 0;
v25 = 0;
do
{
BF_encrypt(&v24, a1);
v21 = v25;
*v20 = v24;
v20[1] = v21;
v20 += 2;
}
while ( v20 != a1 + 18 );
do
{
result = BF_encrypt(&v24, a1);
v23 = v25;
*v20 = v24;
v20[1] = v23;
v20 += 2;
}
while ( v20 != a1 + 1042 );
return result;
}