[libdvdcss-devel] [PATCH 4/5] Replace duplicate KEY_SIZE define by DVD_KEY_SIZE.

Diego Biurrun diego at biurrun.de
Fri Nov 7 21:57:45 CET 2014


---
 src/css.c       | 60 ++++++++++++++++++++++++++++-----------------------------
 src/css.h       |  4 ++--
 src/ioctl.c     |  1 +
 src/ioctl.h     |  1 -
 src/libdvdcss.c |  6 +++---
 5 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/src/css.c b/src/css.c
index ccd4989..db438e7 100644
--- a/src/css.c
+++ b/src/css.c
@@ -61,7 +61,7 @@
 #include "ioctl.h"
 #include "device.h"
 
-#define PSZ_KEY_SIZE (KEY_SIZE * 3)
+#define PSZ_KEY_SIZE (DVD_KEY_SIZE * 3)
 
 /*****************************************************************************
  * Local prototypes
@@ -303,7 +303,7 @@ int dvdcss_title ( struct dvdcss *dvdcss, int i_block )
         return -1;
     }
     p_newtitle->i_startlb = i_block;
-    memcpy( p_newtitle->p_key, p_title_key, KEY_SIZE );
+    memcpy( p_newtitle->p_key, p_title_key, DVD_KEY_SIZE );
 
     /* Link it at the head of the (possibly empty) list */
     if( p_title == NULL )
@@ -318,7 +318,7 @@ int dvdcss_title ( struct dvdcss *dvdcss, int i_block )
         p_title->p_next = p_newtitle;
     }
 
-    memcpy( dvdcss->css.p_title_key, p_title_key, KEY_SIZE );
+    memcpy( dvdcss->css.p_title_key, p_title_key, DVD_KEY_SIZE );
     return 0;
 }
 
@@ -363,7 +363,7 @@ int dvdcss_disckey( struct dvdcss *dvdcss )
     /* Shuffle disc key using bus key */
     for( i = 0 ; i < DVD_DISCKEY_SIZE ; i++ )
     {
-        p_buffer[ i ] ^= dvdcss->css.p_bus_key[ 4 - (i % KEY_SIZE) ];
+        p_buffer[i] ^= dvdcss->css.p_bus_key[4 - (i % DVD_KEY_SIZE)];
     }
 
     /* Decrypt disc key */
@@ -383,14 +383,14 @@ int dvdcss_disckey( struct dvdcss *dvdcss )
                                  "cracking title keys instead" );
 
             /* Fallback, but not to DISC as the disc key might be faulty */
-            memset( p_disc_key, 0, KEY_SIZE );
+            memset( p_disc_key, 0, DVD_KEY_SIZE );
             dvdcss->i_method = DVDCSS_METHOD_TITLE;
             break;
 
         case DVDCSS_METHOD_DISC:
 
             /* Crack Disc key to be able to use it */
-            memcpy( p_disc_key, p_buffer, KEY_SIZE );
+            memcpy( p_disc_key, p_buffer, DVD_KEY_SIZE );
             PrintKey( dvdcss, "cracking disc key ", p_disc_key );
             if( ! CrackDiscKey( dvdcss, p_disc_key ) )
             {
@@ -398,18 +398,18 @@ int dvdcss_disckey( struct dvdcss *dvdcss )
                 break;
             }
             print_debug( dvdcss, "failed to crack the disc key" );
-            memset( p_disc_key, 0, KEY_SIZE );
+            memset( p_disc_key, 0, DVD_KEY_SIZE );
             dvdcss->i_method = DVDCSS_METHOD_TITLE;
             break;
 
         default:
 
             print_debug( dvdcss, "disc key needs not be decrypted" );
-            memset( p_disc_key, 0, KEY_SIZE );
+            memset( p_disc_key, 0, DVD_KEY_SIZE );
             break;
     }
 
-    memcpy( dvdcss->css.p_disc_key, p_disc_key, KEY_SIZE );
+    memcpy( dvdcss->css.p_disc_key, p_disc_key, DVD_KEY_SIZE );
 
     return 0;
 }
@@ -421,7 +421,7 @@ int dvdcss_disckey( struct dvdcss *dvdcss )
 static int dvdcss_titlekey( struct dvdcss *dvdcss, int i_pos, dvd_key p_title_key )
 {
     static uint8_t p_garbage[ DVDCSS_BLOCK_SIZE ];  /* we never read it back */
-    uint8_t p_key[ KEY_SIZE ];
+    uint8_t p_key[DVD_KEY_SIZE];
     int i, i_ret = 0;
 
     if( dvdcss->b_ioctls && ( dvdcss->i_method == DVDCSS_METHOD_KEY ||
@@ -480,9 +480,9 @@ static int dvdcss_titlekey( struct dvdcss *dvdcss, int i_pos, dvd_key p_title_ke
         if( !( i_ret < 0 ) )
         {
             /* Decrypt title key using the bus key */
-            for( i = 0 ; i < KEY_SIZE ; i++ )
+            for( i = 0 ; i < DVD_KEY_SIZE ; i++ )
             {
-                p_key[ i ] ^= dvdcss->css.p_bus_key[ 4 - (i % KEY_SIZE) ];
+                p_key[i] ^= dvdcss->css.p_bus_key[4 - (i % DVD_KEY_SIZE)];
             }
 
             /* If p_key is all zero then there really wasn't any key present
@@ -500,7 +500,7 @@ static int dvdcss_titlekey( struct dvdcss *dvdcss, int i_pos, dvd_key p_title_ke
             }
 
             /* All went well either there wasn't a key or we have it now. */
-            memcpy( p_title_key, p_key, KEY_SIZE );
+            memcpy( p_title_key, p_key, DVD_KEY_SIZE );
             PrintKey( dvdcss, "title key is ", p_title_key );
 
             return i_ret;
@@ -524,7 +524,7 @@ static int dvdcss_titlekey( struct dvdcss *dvdcss, int i_pos, dvd_key p_title_ke
     /* For now, the read limit is 9GB / 2048 =  4718592 sectors. */
     i_ret = CrackTitleKey( dvdcss, i_pos, 4718592, p_key );
 
-    memcpy( p_title_key, p_key, KEY_SIZE );
+    memcpy( p_title_key, p_key, DVD_KEY_SIZE );
     PrintKey( dvdcss, "title key is ", p_title_key );
 
     return i_ret;
@@ -591,7 +591,7 @@ int dvdcss_unscramble( const dvd_key p_key, uint8_t *p_sec )
 static int GetBusKey( struct dvdcss *dvdcss )
 {
     uint8_t   p_buffer[10];
-    uint8_t   p_challenge[2*KEY_SIZE];
+    uint8_t   p_challenge[2 * DVD_KEY_SIZE];
     dvd_key   p_key1;
     dvd_key   p_key2;
     dvd_key   p_key_check;
@@ -657,7 +657,7 @@ static int GetBusKey( struct dvdcss *dvdcss )
     }
 
     /* Send key1 to host */
-    for( i = 0 ; i < KEY_SIZE ; i++ )
+    for( i = 0 ; i < DVD_KEY_SIZE ; i++ )
     {
         p_key1[i] = p_buffer[4-i];
     }
@@ -666,7 +666,7 @@ static int GetBusKey( struct dvdcss *dvdcss )
     {
         CryptKey( 0, i, p_challenge, p_key_check );
 
-        if( memcmp( p_key_check, p_key1, KEY_SIZE ) == 0 )
+        if( memcmp( p_key_check, p_key1, DVD_KEY_SIZE ) == 0 )
         {
             print_debug( dvdcss, "drive authenticated, using variant %d", i );
             i_variant = i;
@@ -699,7 +699,7 @@ static int GetBusKey( struct dvdcss *dvdcss )
     CryptKey( 1, i_variant, p_challenge, p_key2 );
 
     /* Get key2 from host */
-    for( i = 0 ; i < KEY_SIZE ; ++i )
+    for( i = 0 ; i < DVD_KEY_SIZE ; ++i )
     {
         p_buffer[4-i] = p_key2[i];
     }
@@ -715,8 +715,8 @@ static int GetBusKey( struct dvdcss *dvdcss )
     /* The drive has accepted us as authentic. */
     print_debug( dvdcss, "authentication established" );
 
-    memcpy( p_challenge, p_key1, KEY_SIZE );
-    memcpy( p_challenge + KEY_SIZE, p_key2, KEY_SIZE );
+    memcpy( p_challenge, p_key1, DVD_KEY_SIZE );
+    memcpy( p_challenge + DVD_KEY_SIZE, p_key2, DVD_KEY_SIZE );
 
     CryptKey( 2, i_variant, p_challenge, dvdcss->css.p_bus_key );
 
@@ -1000,7 +1000,7 @@ static void DecryptKey( uint8_t invert, const uint8_t *p_key,
                    p_css_tab4[( i_lfsr0 >> 24 ) & 0xff];
 
     i_combined = 0;
-    for( i = 0 ; i < KEY_SIZE ; ++i )
+    for( i = 0 ; i < DVD_KEY_SIZE ; ++i )
     {
         o_lfsr1     = p_css_tab2[i_lfsr1_hi] ^ p_css_tab3[i_lfsr1_lo];
         i_lfsr1_hi  = i_lfsr1_lo >> 1;
@@ -1085,7 +1085,7 @@ static int DecryptDiscKey( const struct dvdcss *dvdcss,
                            const uint8_t *p_struct_disckey,
                            dvd_key p_disc_key )
 {
-    uint8_t p_verify[KEY_SIZE];
+    uint8_t p_verify[DVD_KEY_SIZE];
     unsigned int i, n = 0;
 
     /* Decrypt disc key with the above player keys */
@@ -1105,7 +1105,7 @@ static int DecryptDiscKey( const struct dvdcss *dvdcss,
             DecryptKey( 0, p_disc_key, p_struct_disckey, p_verify );
 
             /* If the position / player key pair worked then return. */
-            if( memcmp( p_disc_key, p_verify, KEY_SIZE ) == 0 )
+            if( memcmp( p_disc_key, p_verify, DVD_KEY_SIZE ) == 0 )
             {
                 return 0;
             }
@@ -1114,7 +1114,7 @@ static int DecryptDiscKey( const struct dvdcss *dvdcss,
 
     /* Have tried all combinations of positions and keys,
      * and we still didn't succeed. */
-    memset( p_disc_key, 0, KEY_SIZE );
+    memset( p_disc_key, 0, DVD_KEY_SIZE );
     return -1;
 }
 
@@ -1144,11 +1144,11 @@ static void DecryptTitleKey( const dvd_key p_disc_key, dvd_key p_titlekey )
  */
 static int investigate( const unsigned char *hash, const unsigned char *ckey )
 {
-    unsigned char key[KEY_SIZE];
+    unsigned char key[DVD_KEY_SIZE];
 
     DecryptKey( 0, ckey, hash, key );
 
-    return memcmp( key, ckey, KEY_SIZE );
+    return memcmp( key, ckey, DVD_KEY_SIZE );
 }
 
 static int CrackDiscKey( const struct dvdcss *dvdcss, uint8_t *p_disc_key )
@@ -1329,7 +1329,7 @@ static int CrackDiscKey( const struct dvdcss *dvdcss, uint8_t *p_disc_key )
 
 end:
 
-    memcpy( p_disc_key, &C[0], KEY_SIZE );
+    memcpy( p_disc_key, &C[0], DVD_KEY_SIZE );
 
     free( K1table );
     free( BigTable );
@@ -1604,12 +1604,12 @@ static int CrackTitleKey( struct dvdcss *dvdcss, int i_pos, int i_len,
 
     if( i_encrypted == 0 && i_reads > 0 )
     {
-        memset( p_titlekey, 0, KEY_SIZE );
+        memset( p_titlekey, 0, DVD_KEY_SIZE );
         print_debug( dvdcss, "no scrambled sectors found" );
         return 0;
     }
 
-    memset( p_titlekey, 0, KEY_SIZE );
+    memset( p_titlekey, 0, DVD_KEY_SIZE );
     return -1;
 }
 
@@ -1653,7 +1653,7 @@ static int AttackPattern( const uint8_t p_sec[ DVDCSS_BLOCK_SIZE ],
         int res;
 
         i_tries++;
-        memset( p_key, 0, KEY_SIZE );
+        memset( p_key, 0, DVD_KEY_SIZE );
         res = RecoverTitleKey( 0,  &p_sec[0x80],
                       &p_sec[ 0x80 - (i_best_plen / i_best_p) * i_best_p ],
                       &p_sec[0x54] /* key_seed */, p_key );
diff --git a/src/css.h b/src/css.h
index 9804bdf..7178efd 100644
--- a/src/css.h
+++ b/src/css.h
@@ -35,9 +35,9 @@
 #define CACHE_FILENAME_LENGTH 10
 #define CACHE_FILENAME_LENGTH_STRING "10"
 
-#define KEY_SIZE 5
+#define DVD_KEY_SIZE 5
 
-typedef uint8_t dvd_key[KEY_SIZE];
+typedef uint8_t dvd_key[DVD_KEY_SIZE];
 
 typedef struct dvd_title
 {
diff --git a/src/ioctl.c b/src/ioctl.c
index 1c6f51a..d30df78 100644
--- a/src/ioctl.c
+++ b/src/ioctl.c
@@ -85,6 +85,7 @@
 
 #include "dvdcss/dvdcss.h"
 #include "common.h"
+#include "css.h"
 #include "ioctl.h"
 
 #define DVD_CHALLENGE_SIZE 10
diff --git a/src/ioctl.h b/src/ioctl.h
index ded1d3c..77e8be0 100644
--- a/src/ioctl.h
+++ b/src/ioctl.h
@@ -37,7 +37,6 @@ int ioctl_SendChallenge     ( int, const int *, const uint8_t * );
 int ioctl_SendKey2          ( int, const int *, const uint8_t * );
 int ioctl_ReportRPC         ( int, int *, int *, int * );
 
-#define DVD_KEY_SIZE 5
 #define DVD_DISCKEY_SIZE 2048
 
 /*****************************************************************************
diff --git a/src/libdvdcss.c b/src/libdvdcss.c
index d86b24a..5d59a86 100644
--- a/src/libdvdcss.c
+++ b/src/libdvdcss.c
@@ -137,7 +137,7 @@
 #endif
 
 
-#define STRING_KEY_SIZE (KEY_SIZE * 2)
+#define STRING_KEY_SIZE (DVD_KEY_SIZE * 2)
 #define INTERESTING_SECTOR 16
 #define DISC_TITLE_OFFSET  40
 #define DISC_TITLE_LENGTH  32
@@ -390,7 +390,7 @@ static void create_cache_subdir( struct dvdcss *dvdcss, const char *psz_cache )
      * date and serial number, but different keys. */
     if( dvdcss->b_scrambled )
     {
-        for( i = 0; i < KEY_SIZE; i++ )
+        for( i = 0; i < DVD_KEY_SIZE; i++ )
         {
             sprintf( &psz_key[i * 2], "%.2x", dvdcss->css.p_disc_key[i] );
         }
@@ -520,7 +520,7 @@ LIBDVDCSS_EXPORT struct dvdcss *dvdcss_open ( const char *psz_target )
         }
     }
 
-    memset( dvdcss->css.p_disc_key, 0, KEY_SIZE );
+    memset( dvdcss->css.p_disc_key, 0, DVD_KEY_SIZE );
     /* If disc is CSS protected and the ioctls work, authenticate the drive */
     if( dvdcss->b_scrambled && dvdcss->b_ioctls )
     {
-- 
2.1.0



More information about the libdvdcss-devel mailing list