Commit 4619c0a5 authored by Kaloyan Kovachev's avatar Kaloyan Kovachev Committed by Rémi Denis-Courmont

Move the CSA Key parsing inside csa_SetCW function

Signed-off-by: default avatarRémi Denis-Courmont <rdenis@simphalempin.com>
parent d9810ce0
......@@ -777,52 +777,30 @@ static int Open( vlc_object_t *p_this )
var_Get( p_demux, "ts-csa-ck", &val );
if( val.psz_string && *val.psz_string )
{
char *psz = val.psz_string;
if( psz[0] == '0' && ( psz[1] == 'x' || psz[1] == 'X' ) )
{
psz += 2;
}
if( strlen( psz ) != 16 )
int i_res;
p_sys->csa = csa_New();
i_res = csa_SetCW( (vlc_object_t*)p_demux, p_sys->csa, val.psz_string, 1 );
if( i_res != VLC_SUCCESS || csa_SetCW( (vlc_object_t*)p_demux, p_sys->csa, val.psz_string, 0 ) != VLC_SUCCESS )
{
msg_Warn( p_demux, "invalid csa ck (it must be 16 chars long)" );
csa_Delete( p_sys->csa );
}
else
if( p_sys->csa )
{
#ifndef UNDER_CE
uint64_t i_ck = strtoull( psz, NULL, 16 );
#else
uint64_t i_ck = strtoll( psz, NULL, 16 );
#endif
uint8_t ck[8];
int i;
for( i = 0; i < 8; i++ )
{
ck[i] = ( i_ck >> ( 56 - 8*i) )&0xff;
}
#ifndef TS_NO_CSA_CK_MSG
msg_Dbg( p_demux, "using CSA scrambling with "
"ck=%x:%x:%x:%x:%x:%x:%x:%x",
ck[0], ck[1], ck[2], ck[3], ck[4], ck[5], ck[6], ck[7] );
#endif
p_sys->csa = csa_New();
vlc_value_t pkt_val;
if( p_sys->csa )
var_Create( p_demux, "ts-csa-pkt", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Get( p_demux, "ts-csa-pkt", &pkt_val );
if( pkt_val.i_int < 4 || pkt_val.i_int > 188 )
{
vlc_value_t pkt_val;
csa_SetCW( p_sys->csa, ck, ck );
var_Create( p_demux, "ts-csa-pkt", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Get( p_demux, "ts-csa-pkt", &pkt_val );
if( pkt_val.i_int < 4 || pkt_val.i_int > 188 )
{
msg_Err( p_demux, "wrong packet size %d specified.", pkt_val.i_int );
msg_Warn( p_demux, "using default packet size of 188 bytes" );
p_sys->i_csa_pkt_size = 188;
}
else p_sys->i_csa_pkt_size = pkt_val.i_int;
msg_Dbg( p_demux, "decrypting %d bytes of packet", p_sys->i_csa_pkt_size );
msg_Err( p_demux, "wrong packet size %d specified.", pkt_val.i_int );
msg_Warn( p_demux, "using default packet size of 188 bytes" );
p_sys->i_csa_pkt_size = 188;
}
else p_sys->i_csa_pkt_size = pkt_val.i_int;
msg_Dbg( p_demux, "decrypting %d bytes of packet", p_sys->i_csa_pkt_size );
}
}
free( val.psz_string );
......
......@@ -81,13 +81,53 @@ void csa_Delete( csa_t *c )
/*****************************************************************************
* csa_SetCW:
*****************************************************************************/
void csa_SetCW( csa_t *c, uint8_t o_ck[8], uint8_t e_ck[8] )
int csa_SetCW( vlc_object_t *p_caller, csa_t *c, char *psz_ck, int set_odd )
{
memcpy( c->o_ck, o_ck, 8 );
csa_ComputeKey( c->o_kk, o_ck );
if ( !c )
{
msg_Dbg( p_caller, "no CSA found" );
return VLC_EGENERIC;
}
/* skip 0x */
if( psz_ck[0] == '0' && ( psz_ck[1] == 'x' || psz_ck[1] == 'X' ) )
{
psz_ck += 2;
}
if( strlen( psz_ck ) != 16 )
{
msg_Warn( p_caller, "invalid csa ck (it must be 16 chars long)" );
return VLC_EGENERIC;
}
else
{
#ifndef UNDER_CE
uint64_t i_ck = strtoull( psz_ck, NULL, 16 );
#else
uint64_t i_ck = strtoll( psz_ck, NULL, 16 );
#endif
uint8_t ck[8];
int i;
memcpy( c->e_ck, e_ck, 8 );
csa_ComputeKey( c->e_kk, e_ck );
for( i = 0; i < 8; i++ )
{
ck[i] = ( i_ck >> ( 56 - 8*i) )&0xff;
}
#ifndef TS_NO_CSA_CK_MSG
msg_Dbg( p_caller, "using CSA (de)scrambling with %s key=%x:%x:%x:%x:%x:%x:%x:%x", ((set_odd == 1) ? "odd" : "even" ),
ck[0], ck[1], ck[2], ck[3], ck[4], ck[5], ck[6], ck[7] );
#endif
if ( set_odd == 1 )
{
memcpy( c->o_ck, ck, 8 );
csa_ComputeKey( c->o_kk, ck );
}
else
{
memcpy( c->e_ck , ck, 8 );
csa_ComputeKey( c->e_kk , ck );
}
return VLC_SUCCESS;
}
}
/*****************************************************************************
......
......@@ -34,7 +34,7 @@ typedef struct csa_t csa_t;
csa_t *csa_New( void );
void csa_Delete( csa_t * );
void csa_SetCW( csa_t *, uint8_t o_ck[8], uint8_t e_ck[8] );
int csa_SetCW( vlc_object_t *p_caller, csa_t *c, char *psz_ck, int set_odd );
void csa_Decrypt( csa_t *, uint8_t *pkt, int i_pkt_size );
void csa_Encrypt( csa_t *, uint8_t *pkt, int i_pkt_size, int b_odd );
......
......@@ -771,48 +771,29 @@ static int Open( vlc_object_t *p_this )
var_Get( p_mux, SOUT_CFG_PREFIX "csa-ck", &val );
if( val.psz_string && *val.psz_string )
{
char *psz = val.psz_string;
int i_res;
/* skip 0x */
if( psz[0] == '0' && ( psz[1] == 'x' || psz[1] == 'X' ) )
{
psz += 2;
}
if( strlen( psz ) != 16 )
p_sys->csa = csa_New();
i_res = csa_SetCW( (vlc_object_t*)p_mux, p_sys->csa, val.psz_string, 1 );
if( i_res != VLC_SUCCESS || csa_SetCW( (vlc_object_t*)p_mux, p_sys->csa, val.psz_string, 0 ) != VLC_SUCCESS )
{
msg_Dbg( p_mux, "invalid csa ck (it must be 16 chars long)" );
csa_Delete( p_sys->csa );
}
else
if( p_sys->csa )
{
uint64_t i_ck = strtoull( psz, NULL, 16 );
uint8_t ck[8];
int i;
vlc_value_t pkt_val;
for( i = 0; i < 8; i++ )
var_Get( p_mux, SOUT_CFG_PREFIX "csa-pkt", &pkt_val );
if( pkt_val.i_int < 12 || pkt_val.i_int > 188 )
{
ck[i] = ( i_ck >> ( 56 - 8*i) )&0xff;
}
#ifndef TS_NO_CSA_CK_MSG
msg_Dbg( p_mux, "using CSA scrambling with ck=%x:%x:%x:%x:%x:%x:%x:%x",
ck[0], ck[1], ck[2], ck[3], ck[4], ck[5], ck[6], ck[7] );
#endif
p_sys->csa = csa_New();
if( p_sys->csa )
{
vlc_value_t pkt_val;
csa_SetCW( p_sys->csa, ck, ck );
var_Get( p_mux, SOUT_CFG_PREFIX "csa-pkt", &pkt_val );
if( pkt_val.i_int < 12 || pkt_val.i_int > 188 )
{
msg_Err( p_mux, "wrong packet size %d specified.", pkt_val.i_int );
msg_Warn( p_mux, "using default packet size of 188 bytes" );
p_sys->i_csa_pkt_size = 188;
}
else p_sys->i_csa_pkt_size = pkt_val.i_int;
msg_Dbg( p_mux, "encrypting %d bytes of packet", p_sys->i_csa_pkt_size );
msg_Err( p_mux, "wrong packet size %d specified.", pkt_val.i_int );
msg_Warn( p_mux, "using default packet size of 188 bytes" );
p_sys->i_csa_pkt_size = 188;
}
else p_sys->i_csa_pkt_size = pkt_val.i_int;
msg_Dbg( p_mux, "encrypting %d bytes of packet", p_sys->i_csa_pkt_size );
}
}
free( val.psz_string );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment