//
// bn_expand2 from 0xff8fe0 to 0xff9290 (688 bytes)
//
// 5 xrefs:
// > BN_set_word @ 0xff92dc
// > bn_wexpand @ 0xff9330
// > BN_hex2bn @ 0xffc3a8
// > BN_dec2bn @ 0xffc57c
// > ??> @ 0x49300
//
// This function is hookable on this platform (idp: arm, 32 bit: False, 64 bit: True!
//
// 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 13:15:50 +0000
//
unsigned __int64 *__fastcall bn_expand2(unsigned __int64 *a1, int a2)
{
unsigned __int64 *v2; // x3
unsigned __int64 v6; // x22
_BYTE *v7; // x9
int v8; // w10
unsigned int v9; // w2
_OWORD *v10; // x6
__int64 v11; // x7
_OWORD *v12; // x2
_OWORD *v13; // x5
_OWORD *v14; // x4
__int128 v15; // q0
int v16; // w10
__int64 v17; // x2
_QWORD *v18; // x0
_QWORD *v19; // x2
int v20; // w10
_OWORD *v21; // x1
_OWORD *v22; // x0
_OWORD *v23; // x3
_OWORD *v24; // x2
__int128 v25; // q0
v2 = a1;
if ( *((_DWORD *)a1 + 3) >= a2 )
return v2;
if ( a2 > 0x7FFFFF )
{
ERR_put_error(3, 120, 114, "crypto/bn/bn_lib.c", 255);
return nullptr;
}
if ( (unsigned int)BN_get_flags((__int64)a1, 2u) )
{
ERR_put_error(3, 120, 105, "crypto/bn/bn_lib.c", 259);
return nullptr;
}
if ( (unsigned int)BN_get_flags((__int64)a1, 8u) )
v6 = CRYPTO_secure_zalloc(8LL * a2, "crypto/bn/bn_lib.c", 263);
else
v6 = CRYPTO_zalloc(8LL * a2, "crypto/bn/bn_lib.c", 265);
if ( !v6 )
{
ERR_put_error(3, 120, 65, "crypto/bn/bn_lib.c", 267);
return nullptr;
}
v7 = (_BYTE *)*a1;
if ( *a1 )
{
v8 = *((_DWORD *)a1 + 2);
v9 = v8 >> 2;
if ( v8 >> 2 <= 0 )
{
v20 = a1[1] & 3;
if ( v20 == 2 )
{
v18 = (_QWORD *)v6;
v19 = (_QWORD *)*a1;
LABEL_27:
v18[1] = v19[1];
goto LABEL_25;
}
if ( v20 != 3 )
{
if ( v20 != 1 )
goto LABEL_17;
v18 = (_QWORD *)v6;
v19 = (_QWORD *)*a1;
LABEL_25:
*v18 = *v19;
LABEL_17:
OPENSSL_cleanse(v7, 8LL * *((int *)a1 + 3));
if ( (unsigned int)BN_get_flags((__int64)a1, 8u) )
CRYPTO_secure_free(*a1, "crypto/bn/bn_lib.c", 174);
else
CRYPTO_free(*a1, "crypto/bn/bn_lib.c", 176);
goto LABEL_19;
}
v18 = (_QWORD *)v6;
v19 = (_QWORD *)*a1;
}
else
{
if ( ((unsigned __int64)v7 >= v6 + 64 || v6 >= (unsigned __int64)(v7 + 64)) && v9 > 6 )
{
v10 = (_OWORD *)v6;
v11 = v9 - 1;
v12 = (_OWORD *)*a1;
do
{
v13 = v12;
v14 = v10;
v12 += 2;
v10 += 2;
v15 = v13[1];
*v14 = *v13;
v14[1] = v15;
}
while ( v12 != (_OWORD *)&v7[32 * v11 + 32] );
}
else
{
v21 = (_OWORD *)v6;
v11 = v9 - 1;
v22 = (_OWORD *)*a1;
do
{
v23 = v22;
v24 = v21;
v21 += 2;
v22 += 2;
v25 = v23[1];
*v24 = *v23;
v24[1] = v25;
}
while ( v21 != (_OWORD *)(v6 + 32 * (v11 + 1)) );
}
v16 = v8 & 3;
v17 = 32 * ((int)v11 + 1LL);
v18 = (_QWORD *)(v6 + v17);
v19 = &v7[v17];
if ( v16 == 2 )
goto LABEL_27;
if ( v16 != 3 )
{
if ( v16 != 1 )
goto LABEL_17;
goto LABEL_25;
}
}
v18[2] = v19[2];
goto LABEL_27;
}
LABEL_19:
*a1 = v6;
*((_DWORD *)a1 + 3) = a2;
return a1;
}