//
// BN_to_ASN1_INTEGER from 0x8625b0 to 0x8626e8 (312 bytes)
//
// 13 xrefs:
// > sub_7DE054 @ 0x7de0b8
// > sub_7DE40C @ 0x7de468
// > sub_7DF150 @ 0x7df4f8
// > sub_7E102C @ 0x7e1094
// > sub_7E13E0 @ 0x7e14a4
// > EC_GROUP_get_ecparameters @ 0x7e601c
// > EC_GROUP_get_ecparameters @ 0x7e6040
// > EC_GROUP_get_ecparameters @ 0x7e6338
// > sub_852030 @ 0x8520f0
// > sub_8522B4 @ 0x8523fc
// > s2i_ASN1_INTEGER @ 0x85d090
// > s2i_ASN1_INTEGER @ 0x85d0ec
// > ??> @ 0x608bc
//
// 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_to_ASN1_INTEGER(_DWORD *a1, int a2, int a3, int a4)
{
int v6; // r5
int v7; // r0
int v8; // r4
int v9; // r4
int v11; // r0
if ( a2 )
a4 = 2;
if ( a2 )
{
*(_DWORD *)(a2 + 4) = a4;
v6 = a2;
}
else
{
v11 = ASN1_STRING_type_new(2);
v6 = v11;
if ( !v11 )
{
ERR_put_error(13, 229, 58, (int)"crypto/asn1/a_int.c", 484);
return 0;
}
}
if ( BN_is_negative((int)a1) && !BN_is_zero((int)a1) )
*(_DWORD *)(v6 + 4) |= 0x102u;
v7 = BN_num_bits(a1);
v8 = v7 + 7;
if ( v7 + 7 < 0 )
v8 = v7 + 14;
v9 = v8 >> 3;
if ( !v9 )
v9 = 1;
if ( ASN1_STRING_set((signed int *)v6, nullptr, v9) )
{
if ( BN_is_zero((int)a1) )
**(_BYTE **)(v6 + 8) = 0;
else
v9 = BN_bn2bin(a1, *(_BYTE **)(v6 + 8));
*(_DWORD *)v6 = v9;
return v6;
}
else
{
ERR_put_error(13, 229, 65, (int)"crypto/asn1/a_int.c", 497);
if ( a2 != v6 )
ASN1_INTEGER_free(v6);
return 0;
}
}