CVS Commit: libdvdcss (gbazin)

H}kan Hjort d95hjort at dtek.chalmers.se
Thu Nov 14 18:17:12 CET 2002


Thu Nov 14 2002, Gildas Bazin wrote:
> On Thursday 14 November 2002 14:45, H}kan Hjort wrote:
> > > 
> > Sure if you either have a region free DVD drive or just DVD disc from 
> > the same region as the drive.
> > 
> 
> I just tried on a RPC-2 drive, set to region 2 and using a region 1 disc... 
> and this appears to be working fine.
> 
Ah sorry my misstake.. I though of the title key.  Though there are some
drives that act wierd reading the disc key on region missmatch.
(Not saying we should do anything about this though, there might even be
other drives that have problmes if the disc key is not read at all).

I have yet another patch in this area though.. i.e. if we discover an
encrypted block when reading and either don't have a key (it's all zero)
or the b_scrambled flag is false.  What should we do?

I have a patch that for the last case sets the flag to true, and tries
to get the disc key followed by the title key at this possition.
Do you think it's any idea to do this?
(It's untested code I'm sorry to say, no DVD drive here)

What of the case when we fail to get the key, or when the key was zero? 

-- 
Håkan Hjort
-------------- next part --------------
Index: src/libdvdcss.c
===================================================================
RCS file: /var/cvs/videolan/libdvdcss/src/libdvdcss.c,v
retrieving revision 1.19
diff -p -u -d -r1.19 libdvdcss.c
--- src/libdvdcss.c	18 Oct 2002 18:48:59 -0000	1.19
+++ src/libdvdcss.c	14 Nov 2002 17:13:39 -0000
@@ -353,37 +353,53 @@ extern int dvdcss_read ( dvdcss_t dvdcss
     i_ret = dvdcss->pf_read( dvdcss, p_buffer, i_blocks );
 
     if( i_ret <= 0
-         || !dvdcss->b_scrambled
          || !(i_flags & DVDCSS_READ_DECRYPT) )
     {
         return i_ret;
     }
-
-    if( ! memcmp( dvdcss->css.p_title_key, "\0\0\0\0\0", 5 ) )
+    
+    /* Loop over all the blocks and check if they need to be descambled */ 
+    for( i_index = i_ret; i_index; i_index-- )
     {
-        /* For what we believe is an unencrypted title, 
-	 * check that there are no encrypted blocks */
-        for( i_index = i_ret; i_index; i_index-- )
+        /* For what we believe is an unencrypted title .. */  
+        if( !dvdcss->b_scrambled 
+	    || !memcmp( dvdcss->css.p_title_key, "\0\0\0\0\0", 5 ) )
         {
+            /* .. if the block is encrypted we need to revise our belief. */
             if( ((u8*)p_buffer)[0x14] & 0x30 )
             {
-                _dvdcss_error( dvdcss, "no key but found encrypted block" );
+                _dvdcss_error( dvdcss, "found encrypted block" 
+                               ", need a valid key to decrypt" );
+
+                /* For a scambled title without a key */
                 /* Only return the initial range of unscrambled blocks? */
-                /* or fail completely? return 0; */
-		break;
+                /* or fail completely? or return all the blocks? */
+		if( dvdcss->b_scrambled )
+		    break;
+
+		/* If we thought that this DVD was unscrambled, 
+		 * then we know that it is now. */ 
+                dvdcss->b_scrambled = 1;
+		
+                /* If disc is CSS protected and the ioctls work, 
+		 * authenticate the drive. */
+                if( dvdcss->b_scrambled && dvdcss->b_ioctls )
+                {
+                    if( _dvdcss_disckey( dvdcss ) < 0 )
+			return -1;
+                }
+                /* try to get the title key */
+                if( _dvdcss_title( dvdcss, i_blocks ) ) 
+                    return -1;
+		/* FALLTROUGH to the unscramble call */ 
             }
-            p_buffer = (void *) ((u8 *)p_buffer + DVDCSS_BLOCK_SIZE);
         }
-    }
-    else 
-    {
-        /* Decrypt the blocks we managed to read */
-        for( i_index = i_ret; i_index; i_index-- )
-	{
+        if( dvdcss->b_scrambled ) {
 	    _dvdcss_unscramble( dvdcss->css.p_title_key, p_buffer );
 	    ((u8*)p_buffer)[0x14] &= 0x8f;
-            p_buffer = (void *) ((u8 *)p_buffer + DVDCSS_BLOCK_SIZE);
 	}
+        
+        p_buffer = (void *) ((u8 *)p_buffer + DVDCSS_BLOCK_SIZE);
     }
     
     return i_ret;


More information about the libdvdcss-devel mailing list