[vlc-devel] commit: Move the CSA Key parsing inside csa_SetCW function ( Kaloyan Kovachev )

git version control git at videolan.org
Sat Jun 7 10:30:54 CEST 2008


vlc | branch: master | Kaloyan Kovachev <kkovachev at varna.net> | Wed Jun  4 22:18:15 2008 +0300| [4619c0a56757e47963f5f4c65b414d14468f92b1]

Move the CSA Key parsing inside csa_SetCW function

Signed-off-by: Rémi Denis-Courmont <rdenis at simphalempin.com>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4619c0a56757e47963f5f4c65b414d14468f92b1
---

 modules/demux/ts.c     |   58 +++++++++++++++---------------------------------
 modules/mux/mpeg/csa.c |   50 +++++++++++++++++++++++++++++++++++++----
 modules/mux/mpeg/csa.h |    2 +-
 modules/mux/mpeg/ts.c  |   51 +++++++++++++-----------------------------
 4 files changed, 80 insertions(+), 81 deletions(-)

diff --git a/modules/demux/ts.c b/modules/demux/ts.c
index 52acfd2..b98666c 100644
--- a/modules/demux/ts.c
+++ b/modules/demux/ts.c
@@ -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 );
diff --git a/modules/mux/mpeg/csa.c b/modules/mux/mpeg/csa.c
index 5840f6e..ea7b589 100644
--- a/modules/mux/mpeg/csa.c
+++ b/modules/mux/mpeg/csa.c
@@ -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;
+    }
 }
 
 /*****************************************************************************
diff --git a/modules/mux/mpeg/csa.h b/modules/mux/mpeg/csa.h
index 40fc4da..18c1ecc 100644
--- a/modules/mux/mpeg/csa.h
+++ b/modules/mux/mpeg/csa.h
@@ -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 );
diff --git a/modules/mux/mpeg/ts.c b/modules/mux/mpeg/ts.c
index f06a0cb..c2007cf 100644
--- a/modules/mux/mpeg/ts.c
+++ b/modules/mux/mpeg/ts.c
@@ -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 );




More information about the vlc-devel mailing list