//
// cms_SignedData_init_bio from 0xe21f60 to 0xe22240 (736 bytes)
//
// 2 xrefs:
// > CMS_dataInit @ 0xe1fa74
// > ??> @ 0x67cc8
//
// 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
//
__int64 __fastcall cms_SignedData_init_bio(__int64 *a1)
{
__int64 v2; // x19
__int64 result; // x0
__int64 v4; // x21
int v5; // w20
int v6; // w0
int v7; // w1
_QWORD *v8; // x0
_QWORD *inited; // x22
int v10; // w0
int v11; // w21
int v12; // w0
int v13; // w20
bool v14; // cc
int v15; // w1
unsigned int *v16; // x0
int v17; // w20
int v18; // w0
int v19; // w1
__int64 v20; // x0
__int64 v21; // x1
int v22; // w0
if ( (unsigned int)OBJ_obj2nid(*a1) != 22 )
{
ERR_put_error(46, 133, 108, (__int64)"crypto/cms/cms_sd.c", 26);
return 0;
}
v2 = a1[1];
result = 0;
if ( v2 )
{
if ( !*(_DWORD *)(*(_QWORD *)(v2 + 16) + 16LL) )
goto LABEL_4;
v11 = 0;
while ( v11 < (int)OPENSSL_sk_num(*(unsigned int **)(v2 + 24)) )
{
v12 = *(_DWORD *)OPENSSL_sk_value(*(_QWORD *)(v2 + 24), v11);
if ( v12 == 4 )
{
if ( *(__int64 *)v2 <= 4 )
{
*(_QWORD *)v2 = 5;
++v11;
continue;
}
}
else if ( v12 == 3 )
{
if ( *(__int64 *)v2 <= 3 )
{
*(_QWORD *)v2 = 4;
++v11;
continue;
}
}
else if ( v12 == 2 && *(__int64 *)v2 <= 2 )
{
*(_QWORD *)v2 = 3;
++v11;
continue;
}
++v11;
}
v13 = 0;
while ( 1 )
{
v14 = v13 < (int)OPENSSL_sk_num(*(unsigned int **)(v2 + 32));
v15 = v13++;
if ( !v14 )
break;
while ( *(_DWORD *)OPENSSL_sk_value(*(_QWORD *)(v2 + 32), v15) == 1 && *(__int64 *)v2 <= 4 )
{
v16 = *(unsigned int **)(v2 + 32);
*(_QWORD *)v2 = 5;
v14 = v13 < (int)OPENSSL_sk_num(v16);
v15 = v13++;
if ( !v14 )
goto LABEL_25;
}
}
LABEL_25:
if ( (unsigned int)OBJ_obj2nid(**(_QWORD **)(v2 + 16)) != 21 && *(__int64 *)v2 <= 2 )
*(_QWORD *)v2 = 3;
v17 = 0;
v18 = OPENSSL_sk_num(*(unsigned int **)(v2 + 40));
v19 = 0;
if ( v18 <= 0 )
{
LABEL_33:
if ( *(__int64 *)v2 <= 0 )
*(_QWORD *)v2 = 1;
LABEL_4:
v4 = 0;
v5 = 0;
v6 = OPENSSL_sk_num(*(unsigned int **)(v2 + 8));
v7 = 0;
if ( v6 <= 0 )
return v4;
while ( 1 )
{
v8 = (_QWORD *)OPENSSL_sk_value(*(_QWORD *)(v2 + 8), v7);
inited = cms_DigestAlgorithm_init_bio(v8);
if ( !inited )
break;
if ( v4 )
{
++v5;
BIO_push(v4, (__int64)inited);
}
else
{
v4 = (__int64)inited;
++v5;
}
v10 = OPENSSL_sk_num(*(unsigned int **)(v2 + 8));
v7 = v5;
if ( v5 >= v10 )
return v4;
}
BIO_free_all(v4);
return 0;
}
while ( 1 )
{
v20 = OPENSSL_sk_value(*(_QWORD *)(v2 + 40), v19);
v21 = *(_QWORD *)v20;
if ( **(_DWORD **)(v20 + 8) == 1 )
{
if ( v21 <= 2 )
*(_QWORD *)v20 = 3;
if ( *(__int64 *)v2 <= 2 )
{
*(_QWORD *)v2 = 3;
++v17;
goto LABEL_32;
}
}
else if ( v21 <= 0 )
{
*(_QWORD *)v20 = 1;
++v17;
goto LABEL_32;
}
++v17;
LABEL_32:
v22 = OPENSSL_sk_num(*(unsigned int **)(v2 + 40));
v19 = v17;
if ( v17 >= v22 )
goto LABEL_33;
}
}
return result;
}