__int64
__fastcall sub_1DC(
int
*a1, unsigned
int
a2,
int
a3, _QWORD *a4)
{
int
v7;
unsigned
__int16
v8;
int
v9;
int
v10;
unsigned
int
v11;
__int64
v12;
__int64
v14;
unsigned
int
v15;
unsigned
int
v16;
unsigned
int
v17;
unsigned
int
v18;
__int64
v19;
__int64
v20;
__int64
v21;
__int64
i;
char
v23[32];
switch
( a2 )
{
case
0u:
sub_930(
"alloc_resources"
, 124LL, 3LL, 1LL,
"Session %p:"
, a1);
if
( a3 != 273 )
return
(unsigned
int
)-65530;
v7 = *(_DWORD *)a4;
if
( *(_DWORD *)a4 == 1 )
{
v8 = 272;
}
else
if
( v7 == 2 )
{
v8 = 528;
}
else
{
if
( v7 )
{
sub_930(
"ta2tee_algo_id"
, 70LL, 1LL, 1LL,
"Invalid %u"
);
return
(unsigned
int
)-65530;
}
v8 = 16;
}
*a1 = v8 | 0x10000000;
v9 = *((_DWORD *)a4 + 4);
if
( v9 != 16 && v9 != 32 )
{
sub_930(
"ta2tee_key_size"
, 82LL, 1LL, 1LL,
"Invalid %u"
);
return
(unsigned
int
)-65530;
}
a1[2] = v9;
v10 = *((_DWORD *)a4 + 8);
if
( v10 )
{
if
( v10 != 1 )
{
sub_930(
"ta2tee_mode_id"
, 96LL, 1LL, 1LL,
"Invalid mode %u"
);
return
(unsigned
int
)-65530;
}
a1[1] = 0;
}
else
{
a1[1] = 1;
}
if
( *((_QWORD *)a1 + 2) )
sub_3018();
v11 = sub_305C(a1 + 4, (unsigned
int
)*a1, (unsigned
int
)a1[1], (unsigned
int
)(8 * a1[2]));
if
( v11 )
{
sub_930(
"alloc_resources"
, 160LL, 1LL, 1LL,
"Failed to allocate"
);
*((_QWORD *)a1 + 2) = 0LL;
}
else
{
if
( *((_QWORD *)a1 + 3) )
sub_2400();
v11 = sub_2380(2684354576LL, (unsigned
int
)(8 * a1[2]), a1 + 6);
if
( v11 )
{
sub_930(
"alloc_resources"
, 174LL, 1LL, 1LL,
"Failed to allocate"
);
*((_QWORD *)a1 + 3) = 0LL;
}
else
{
v14 = sub_1F70((unsigned
int
)a1[2], 0LL);
if
( v14 )
{
sub_2578(v23, 3221225472LL, v14, (unsigned
int
)a1[2]);
v11 = sub_24A8(*((_QWORD *)a1 + 3), v23, 1LL);
if
( v11 )
{
sub_930(
"alloc_resources"
, 198LL, 1LL, 1LL,
"TEE failed, %x"
, v11);
}
else
{
v11 = sub_3DC0(*((_QWORD *)a1 + 2), *((_QWORD *)a1 + 3));
if
( !v11 )
return
v11;
sub_930(
"alloc_resources"
, 204LL, 1LL, 1LL,
"TEE failed %x"
, v11);
}
}
else
{
v11 = -65524;
}
}
}
if
( *((_QWORD *)a1 + 2) )
sub_3018();
v12 = *((_QWORD *)a1 + 3);
*((_QWORD *)a1 + 2) = 0LL;
if
( v12 )
sub_2400();
*((_QWORD *)a1 + 3) = 0LL;
return
v11;
case
1u:
sub_930(
"set_bj888_key"
, 240LL, 3LL, 1LL,
"Session %p: load "
, a1);
if
( a3 != 5 )
return
(unsigned
int
)-65530;
v15 = *((_DWORD *)a4 + 2);
if
( v15 != a1[2] )
{
sub_930(
"set_bj888_key"
, 251LL, 1LL, 1LL,
"Wrong size %u, expect %u bytes"
, v15);
return
(unsigned
int
)-65530;
}
((
void
(*)(
void
))sub_2578)();
sub_2454(*((_QWORD *)a1 + 3));
v16 = sub_24A8(*((_QWORD *)a1 + 3), v23, 1LL);
v11 = v16;
if
( v16 )
{
sub_930(
"set_bj888_key"
, 280LL, 1LL, 1LL,
"TEE failed, %x"
, v16);
}
else
{
sub_3D48(*((_QWORD *)a1 + 2));
v17 = sub_3DC0(*((_QWORD *)a1 + 2), *((_QWORD *)a1 + 3));
v11 = v17;
if
( v17 )
sub_930(
"set_bj888_key"
, 287LL, 1LL, 1LL,
"TEE failed %x"
, v17);
}
return
v11;
case
2u:
sub_930(
"reset_bj888_iv"
, 310LL, 3LL, 1LL,
"Session %p: no hint"
, a1);
if
( a3 != 5 )
return
(unsigned
int
)-65530;
sub_42E4(*((_QWORD *)a1 + 2), *a4, *((unsigned
int
*)a4 + 2));
return
0;
case
3u:
sub_930(
"cipher_buffer"
, 344LL, 3LL, 1LL,
"Session %p: no hints"
, a1);
if
( a3 != 101 )
return
(unsigned
int
)-65530;
v18 = *((_DWORD *)a4 + 2);
if
( *((_DWORD *)a4 + 6) < v18 )
{
sub_930(
"cipher_buffer"
, 352LL, 1LL, 1LL,
"Bad sizes: in %d, out %d"
, v18);
return
(unsigned
int
)-65530;
}
v19 = *((_QWORD *)a1 + 2);
if
( !v19 )
return
(unsigned
int
)-65529;
sub_43C4(v19, *a4);
v20 = a4[2];
v21 = sub_20(v23, &unk_11AFA, 27LL);
for
( i = 0LL; i != 27; ++i )
{
if
( *(unsigned
__int8
*)(v21 + i) != *(unsigned
__int8
*)(v20 + i) )
{
sub_1E10(*a4,
"wrong"
, 6LL);
sub_1FD8(
"wrong"
);
return
(unsigned
int
)-65530;
}
}
sub_1E10(*a4,
"right"
, 6LL);
sub_1FD8(
"right"
);
return
0;
default
:
v11 = -65526;
sub_930(
"TA_InvokeCommandEntryPoint"
, 452LL, 1LL, 1LL,
" 0x%x is not supported"
, a2);
return
v11;
}
}