//
// bn_expand2 from 0x7d4b1c to 0x7d4d44 (552 bytes)
//
// 6 xrefs:
// > BN_set_word @ 0x7d4db0
// > bn_wexpand @ 0x7d4dfc
// > BN_MONT_CTX_set @ 0x7d599c
// > BN_hex2bn @ 0x7d791c
// > BN_dec2bn @ 0x7d7aa8
// > ??> @ 0x5fc3c
//
// 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 bn_expand2(int result, int a2)
{
int *v3; // r4
bool v4; // zf
int v5; // r0
_BYTE *v6; // r0
int v7; // r9
int v8; // r2
_BYTE *v9; // r3
int v10; // r12
int v11; // r1
int v12; // r5
int v13; // lr
int v14; // r9
int v15; // r3
_DWORD *v16; // r2
_DWORD *v17; // r9
_BYTE *v18; // r0
int v19; // r8
int v20; // r3
if ( *(_DWORD *)(result + 8) < a2 )
{
v3 = (int *)result;
if ( a2 >= 0x1000000 )
{
ERR_put_error(3, 120, 114, "crypto/bn/bn_lib.c", 255);
}
else if ( BN_get_flags(result, 2) )
{
ERR_put_error(3, 120, 105, "crypto/bn/bn_lib.c", 259);
}
else
{
v4 = BN_get_flags((int)v3, 8) == 0;
v5 = 4 * a2;
if ( v4 )
v19 = CRYPTO_zalloc(v5, "crypto/bn/bn_lib.c", 265);
else
v19 = CRYPTO_secure_zalloc(v5, "crypto/bn/bn_lib.c", 263);
if ( v19 )
{
v6 = (_BYTE *)*v3;
if ( !*v3 )
{
LABEL_18:
*v3 = v19;
v3[2] = a2;
return (int)v3;
}
v7 = v3[1] >> 2;
if ( v7 <= 0 )
{
v20 = v3[1] & 3;
if ( v20 == 2 )
{
v16 = (_DWORD *)v19;
v17 = (_DWORD *)*v3;
LABEL_25:
v16[1] = v17[1];
goto LABEL_23;
}
if ( v20 != 3 )
{
if ( v20 != 1 )
goto LABEL_15;
v16 = (_DWORD *)v19;
v17 = (_DWORD *)*v3;
LABEL_23:
*v16 = *v17;
LABEL_15:
OPENSSL_cleanse(v6, 4 * v3[2]);
v4 = BN_get_flags((int)v3, 8) == 0;
v18 = (_BYTE *)*v3;
if ( v4 )
CRYPTO_free(v18, "crypto/bn/bn_lib.c", 176);
else
CRYPTO_secure_free(v18, "crypto/bn/bn_lib.c", 174);
goto LABEL_18;
}
v16 = (_DWORD *)v19;
v17 = (_DWORD *)*v3;
}
else
{
v8 = v19 + 16;
v9 = v6 + 16;
v10 = v3[1] >> 2;
do
{
v11 = *((_DWORD *)v9 - 4);
v12 = *((_DWORD *)v9 - 3);
v13 = *((_DWORD *)v9 - 2);
--v10;
*(_DWORD *)(v8 - 4) = *((_DWORD *)v9 - 1);
*(_DWORD *)(v8 - 16) = v11;
*(_DWORD *)(v8 - 12) = v12;
*(_DWORD *)(v8 - 8) = v13;
v9 += 16;
v8 += 16;
}
while ( v10 );
v14 = 16 * v7;
v15 = v3[1] & 3;
v16 = (_DWORD *)(v19 + v14);
v17 = &v6[v14];
if ( v15 == 2 )
goto LABEL_25;
if ( v15 != 3 )
{
if ( v15 != 1 )
goto LABEL_15;
goto LABEL_23;
}
}
v16[2] = v17[2];
goto LABEL_25;
}
ERR_put_error(3, 120, 65, "crypto/bn/bn_lib.c", 267);
}
return 0;
}
return result;
}