//
// sub_7D52C4 from 0x7d52c4 to 0x7d5524 (608 bytes)
//
// 2 xrefs:
// > BN_mod_mul_montgomery @ 0x7d55c0
// > BN_from_montgomery @ 0x7d5680
//
// 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_7D52C4(int *a1, _DWORD *a2, _DWORD *a3)
{
int v3; // r6
int v6; // r7
int v8; // r0
int v9; // r10
_DWORD *v10; // r5
int v11; // r9
int v12; // r7
unsigned int *v13; // r11
int v14; // r4
int v15; // r0
unsigned int v16; // r0
int v17; // r9
int v18; // r7
int v19; // r0
int v20; // lr
int *v21; // r12
int v22; // r5
int v23; // r4
int v24; // r11
int v25; // r0
int v26; // r2
int v27; // r1
signed int v28; // r3
int v29; // r1
int v30; // r0
int v31; // r1
int v32; // r3
int v34; // [sp+4h] [bp-8h]
v3 = a3[7];
if ( v3 )
{
v6 = 2 * v3;
if ( !bn_wexpand((int)a2, 2 * v3) )
return 0;
v8 = a2[1];
a2[3] ^= a3[9];
v9 = a3[6];
v10 = (_DWORD *)*a2;
if ( v6 != v8 )
memset(&v10[v8], 0, 4 * (v6 - v8));
a2[1] = v6;
v11 = a3[16];
if ( v3 <= 0 )
{
v14 = 0;
}
else
{
v12 = 0;
v13 = &v10[v3];
v14 = 0;
do
{
v15 = bn_mul_add_words(v10, v9, v3, v11 * *v10);
++v12;
++v10;
v16 = v15 + v14 + *v13;
if ( *v13 != v16 )
LOBYTE(v14) = v14 | 1;
if ( *v13 < v16 )
v14 = 0;
else
v14 &= 1u;
*v13++ = v16;
}
while ( v12 != v3 );
}
if ( bn_wexpand((int)a1, v3) )
{
v17 = *a1;
v18 = *a2 + 4 * v3;
a1[3] = a2[3];
a1[1] = v3;
v19 = bn_sub_words(v17, v18, v9, v3);
v34 = v17 & ~(v14 - v19) | (v14 - v19) & v18;
if ( v3 - 4 <= 0 )
{
v28 = 0;
}
else
{
v20 = 0;
v21 = (int *)((v17 & ~(v14 - v19) | (v14 - v19) & v18) + 4);
v22 = v17;
v23 = v18;
do
{
v24 = *(v21 - 1);
v25 = *v21;
v26 = v21[1];
*(_DWORD *)(v18 + 4 * v20) = 0;
v27 = v21[2];
*(_DWORD *)(v23 + 4) = 0;
*(_DWORD *)(v17 + 4 * v20) = v24;
v20 += 4;
*(_DWORD *)(v23 + 8) = 0;
v21 += 4;
*(_DWORD *)(v22 + 4) = v25;
v23 += 16;
*(_DWORD *)(v23 - 4) = 0;
v22 += 16;
*(_DWORD *)(v22 - 4) = v27;
*(_DWORD *)(v22 - 8) = v26;
}
while ( v3 - 4 > v20 );
v28 = ((v3 - 5) & 0xFFFFFFFC) + 4;
}
if ( v3 > v28 )
{
v29 = v28 + 1;
*(_DWORD *)(v17 + 4 * v28) = *(_DWORD *)(v34 + 4 * v28);
*(_DWORD *)(v18 + 4 * v28) = 0;
if ( v3 > v28 + 1 )
{
v30 = v28 + 2;
*(_DWORD *)(v17 + 4 * v29) = *(_DWORD *)(v34 + 4 * v29);
*(_DWORD *)(v18 + 4 * v29) = 0;
if ( v28 + 2 < v3 )
{
v31 = v28 + 3;
*(_DWORD *)(v17 + 4 * v30) = *(_DWORD *)(v34 + 4 * v30);
*(_DWORD *)(v18 + 4 * v30) = 0;
if ( v3 > v28 + 3 )
{
v32 = v28 + 4;
*(_DWORD *)(v17 + 4 * v31) = *(_DWORD *)(v34 + 4 * v31);
*(_DWORD *)(v18 + 4 * v31) = 0;
if ( v3 > v32 )
{
*(_DWORD *)(v17 + 4 * v32) = *(_DWORD *)(v34 + 4 * v32);
*(_DWORD *)(v18 + 4 * v32) = 0;
}
}
}
}
}
bn_correct_top(a2);
bn_correct_top(a1);
return 1;
}
else
{
return 0;
}
}
else
{
a1[1] = 0;
return 1;
}
}