1
mirror of https://code.videolan.org/videolan/vlc synced 2024-09-28 23:09:59 +02:00

New features for libdvdcss: we have three ways now to decode a title key.

1) Crack the title key (the method that was here before). The only change
here is that we search the key for the exact chapter we are seeking with
DVDSetArea (in case the key has changed within a title). It is maybe not a
good idea.

2) Crack the disc key, which allows us to decode instantly all title keys.
I've used an algorithm from Frank Stevenson ; it eats much memory (64MB),
and takes about 15 s at launch time.

3) Decode the disc key with player keys (libcss method). However, you need
licensed player keys at build time for that to work.

To choose between libdvdcss methods, a command line options is supplied:

        vlc --dvdcss <method> where method is one of title, disc, key.

Note that all these changes only work with linux now, since we have to add a
specific ioctl to read title key. I hope that I haven't broken too many things.
This commit is contained in:
Stéphane Borel 2001-10-13 15:34:21 +00:00
parent 563c5e1733
commit 88a154951c
17 changed files with 1014 additions and 542 deletions

567
configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -18,6 +18,9 @@ if test -r extras/libdvdcss/libdvdcss.c; then
HAVE_LIBDVDCSS=1
LIBDVDCSS_VERSION=0.0.3
AC_SUBST(LIBDVDCSS_VERSION)
if test -r extras/libdvdcss/csskeys.h; then
AC_DEFINE(HAVE_CSSKEYS,1,css decryption with player keys)
fi
fi
dnl Save CFLAGS and LDFLAGS

View File

@ -2,7 +2,7 @@
* css.c: Functions for DVD authentification and unscrambling
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
* $Id: css.c,v 1.9 2001/09/09 13:43:25 sam Exp $
* $Id: css.c,v 1.10 2001/10/13 15:34:21 stef Exp $
*
* Author: Stéphane Borel <stef@via.ecp.fr>
* Håkan Hjort <d95hjort@dtek.chalmers.se>
@ -40,6 +40,18 @@
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <netinet/in.h>
#include <linux/cdrom.h>
#include "config.h"
#include "common.h"
@ -49,13 +61,20 @@
#include "csstables.h"
#include "ioctl.h"
#ifdef HAVE_CSSKEYS
# include "csskeys.h"
#endif
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static int CSSGetASF ( dvdcss_handle dvdcss );
static void CSSCryptKey ( int i_key_type, int i_varient,
u8 const * p_challenge, u8* p_key );
static int CSSCracker ( int i_start, unsigned char * p_crypted,
static void CSSDecryptKey( u8* p_crypted, u8* p_key, u8 );
static int CSSDiscCrack ( u8 * p_disc_key );
static int CSSTitleCrack( int i_start, unsigned char * p_crypted,
unsigned char * p_decrypted,
dvd_key_t * p_sector_key, dvd_key_t * p_key );
@ -81,21 +100,22 @@ int CSSTest( dvdcss_handle dvdcss )
}
/*****************************************************************************
* CSSInit : CSS Structure initialisation and DVD authentication.
* CSSAuth : CSS Structure initialisation and DVD authentication.
*****************************************************************************
* It simulates the mutual authentication between logical unit and host.
* Since we don't need the disc key to find the title key, we just run the
* basic unavoidable commands to authenticate device and disc.
*****************************************************************************/
int CSSInit( dvdcss_handle dvdcss )
int CSSAuth( dvdcss_handle dvdcss )
{
/* structures defined in cdrom.h or dvdio.h */
unsigned char p_buffer[2048 + 4 + 1];
unsigned char p_buffer[10];
char psz_warning[32];
int i_agid = 0;
int i_ret = -1;
int i;
dvdcss->css.i_agid = 0;
/* Test authentication success */
switch( CSSGetASF( dvdcss ) )
{
@ -104,10 +124,11 @@ int CSSInit( dvdcss_handle dvdcss )
case 1:
_dvdcss_debug( dvdcss, "already authenticated" );
return 0;
break;
case 0:
_dvdcss_debug( dvdcss, "need to authenticate" );
break;
}
/* Init sequence, request AGID */
@ -116,7 +137,7 @@ int CSSInit( dvdcss_handle dvdcss )
sprintf( psz_warning, "requesting AGID %d", i );
_dvdcss_debug( dvdcss, psz_warning );
i_ret = ioctl_ReportAgid( dvdcss->i_fd, &i_agid );
i_ret = ioctl_ReportAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
if( i_ret != -1 )
{
@ -126,8 +147,8 @@ int CSSInit( dvdcss_handle dvdcss )
_dvdcss_error( dvdcss, "ioctl_ReportAgid failed, invalidating" );
i_agid = 0;
ioctl_InvalidateAgid( dvdcss->i_fd, &i_agid );
dvdcss->css.i_agid = 0;
ioctl_InvalidateAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
}
/* Unable to authenticate without AGID */
@ -149,14 +170,14 @@ int CSSInit( dvdcss_handle dvdcss )
}
/* Send challenge to LU */
if( ioctl_SendChallenge( dvdcss->i_fd, &i_agid, p_buffer ) < 0 )
if( ioctl_SendChallenge( dvdcss->i_fd, &dvdcss->css.i_agid, p_buffer ) < 0 )
{
_dvdcss_error( dvdcss, "ioctl_SendChallenge failed" );
return -1;
}
/* Get key1 from LU */
if( ioctl_ReportKey1( dvdcss->i_fd, &i_agid, p_buffer ) < 0)
if( ioctl_ReportKey1( dvdcss->i_fd, &dvdcss->css.i_agid, p_buffer ) < 0)
{
_dvdcss_error( dvdcss, "ioctl_ReportKey1 failed" );
return -1;
@ -190,7 +211,7 @@ int CSSInit( dvdcss_handle dvdcss )
}
/* Get challenge from LU */
if( ioctl_ReportChallenge( dvdcss->i_fd, &i_agid, p_buffer ) < 0 )
if( ioctl_ReportChallenge( dvdcss->i_fd, &dvdcss->css.i_agid, p_buffer ) < 0 )
{
_dvdcss_error( dvdcss, "ioctl_ReportKeyChallenge failed" );
return -1;
@ -213,7 +234,7 @@ int CSSInit( dvdcss_handle dvdcss )
}
/* Send key2 to LU */
if( ioctl_SendKey2( dvdcss->i_fd, &i_agid, p_buffer ) < 0 )
if( ioctl_SendKey2( dvdcss->i_fd, &dvdcss->css.i_agid, p_buffer ) < 0 )
{
_dvdcss_error( dvdcss, "ioctl_SendKey2 failed" );
return -1;
@ -232,7 +253,7 @@ int CSSInit( dvdcss_handle dvdcss )
_dvdcss_debug( dvdcss, "received session key" );
if( i_agid < 0 )
if( dvdcss->css.i_agid < 0 )
{
return -1;
}
@ -249,12 +270,38 @@ int CSSInit( dvdcss_handle dvdcss )
case 0:
_dvdcss_debug( dvdcss, "need to get disc key" );
return 0;
}
return -1;
}
/*****************************************************************************
* CSSGetDiscKey : get disc key and optionnaly decrypts it.
*****************************************************************************
* This function should only be called if DVD ioctls are present.
* Two decryption methods are then offered:
* -disc key hash crack,
* -decryption with player keys if they are available.
*****************************************************************************/
int CSSGetDiscKey( dvdcss_handle dvdcss )
{
unsigned char p_buffer[2048 + 4 + 1];
#ifdef HAVE_CSSKEYS
dvd_key_t disc_key;
dvd_key_t test_key;
#endif
int i;
if( CSSAuth( dvdcss ) )
{
return -1;
}
/* Get encrypted disc key */
if( ioctl_ReadKey( dvdcss->i_fd, &i_agid, p_buffer ) < 0 )
if( ioctl_ReadDiscKey( dvdcss->i_fd, &dvdcss->css.i_agid, p_buffer ) < 0 )
{
_dvdcss_error( dvdcss, "ioctl_ReadKey failed" );
_dvdcss_error( dvdcss, "ioctl_ReadDiscKey failed" );
return -1;
}
@ -263,134 +310,195 @@ int CSSInit( dvdcss_handle dvdcss )
{
p_buffer[ i ] ^= dvdcss->css.disc.p_key_check[ 4 - (i % KEY_SIZE) ];
}
memcpy( dvdcss->css.disc.p_key_check, p_buffer, 2048 );
memcpy( dvdcss->css.disc.p_disc_key, p_buffer, 2048 );
/* Test authentication success */
switch( CSSGetASF( dvdcss ) )
switch( dvdcss->i_method )
{
case -1:
return -1;
case DVDCSS_KEY:
#ifdef HAVE_CSSKEYS
/* Decrypt disc key with player keys from csskeys.h */
_dvdcss_debug( dvdcss, "decrypting disc key with player keys" );
i = 0;
do
{
/* Take encrypted disc key and decrypt it */
memcpy( disc_key,
dvdcss->css.disc.p_disc_key
+ playerkeys[i].i_offset,
KEY_SIZE );
CSSDecryptKey( disc_key, playerkeys[i].p_key, 0 );
case 1:
_dvdcss_debug( dvdcss, "successfully authenticated" );
return 0;
/* Encrypt disc key hash with disc key to
* check we have disc key */
memcpy( test_key, dvdcss->css.disc.p_disc_key, KEY_SIZE );
CSSDecryptKey( test_key, disc_key, 0);
case 0:
_dvdcss_error( dvdcss, "no way to authenticate" );
return -1;
i++;
} while( ( playerkeys[i].i_offset != -1 ) &&
( memcmp( test_key, disc_key, KEY_SIZE ) ) );
/* The decrypted disk key will replace the disk key hash */
memcpy( dvdcss->css.disc.p_disc_key, disc_key, KEY_SIZE );
break;
#else
dvdcss->i_method = DVDCSS_DISC;
#endif
case DVDCSS_DISC:
/* Crack Disc key to be able to use it */
_dvdcss_debug( dvdcss, "cracking disc key with key hash" );
CSSDiscCrack( dvdcss->css.disc.p_disc_key );
break;
default:
_dvdcss_debug( dvdcss, "disc key won't be decrypted" );
}
return -1;
return 0;
}
/*****************************************************************************
* CSSGetKey : get title key.
*****************************************************************************
* The DVD should have been opened and authenticated before.
* CSSGetTitleKey : get title key.
*****************************************************************************/
int CSSGetKey( dvdcss_handle dvdcss, int i_pos, dvd_key_t p_titlekey )
int CSSGetTitleKey( dvdcss_handle dvdcss, int i_pos )
{
/*
* Title key cracking method from Ethan Hawke,
* with Frank A. Stevenson algorithm.
* Does not use any player key table and ioctls.
*/
u8 p_buf[0x800];
u8 p_packstart[4] = { 0x00, 0x00, 0x01, 0xba };
dvd_key_t p_key;
boolean_t b_encrypted;
boolean_t b_stop_scanning;
int i_blocks_read;
int i_best_plen;
int i_best_p;
int i,j;
for( i = 0 ; i < KEY_SIZE ; i++ )
if( ( dvdcss->i_method == DVDCSS_TITLE ) || ( dvdcss->b_ioctls == 0 ) )
{
p_key[i] = 0;
}
/*
* Title key cracking method from Ethan Hawke,
* with Frank A. Stevenson algorithm.
* Does not use any player key table and ioctls.
*/
u8 p_buf[0x800];
u8 p_packstart[4] = { 0x00, 0x00, 0x01, 0xba };
boolean_t b_encrypted;
boolean_t b_stop_scanning;
int i_blocks_read;
int i_best_plen;
int i_best_p;
b_encrypted = 0;
b_stop_scanning = 0;
i_blocks_read = 0;
do
{
i_pos = dvdcss_seek( dvdcss, i_pos );
if( dvdcss_read( dvdcss, p_buf, 1, DVDCSS_NOFLAGS ) != 1 ) break;
/* Stop when we find a non MPEG stream block */
if( memcmp( p_buf, p_packstart, 4 ) )
for( i = 0 ; i < KEY_SIZE ; i++ )
{
/* The title is unencrypted */
if( !b_encrypted )
break;
/* dvdcss some times fail to find/crack the key,
hope that it's the same as the one in the next title
_dvdcss_debug( dvdcss, "no key found at end of title" );
*/
p_key[i] = 0;
}
/* PES_scrambling_control on and make sure that the packet type
is one that can be scrambled */
if( p_buf[0x14] & 0x30 && ! ( p_buf[0x11] == 0xbb
|| p_buf[0x11] == 0xbe
|| p_buf[0x11] == 0xbf ) )
{
b_encrypted = 1;
i_best_plen = 0;
i_best_p = 0;
b_encrypted = 0;
b_stop_scanning = 0;
i_blocks_read = 0;
for( i = 2 ; i < 0x30 ; i++ )
do
{
i_pos = dvdcss_seek( dvdcss, i_pos, DVDCSS_NOFLAGS );
if( dvdcss_read( dvdcss, p_buf, 1, DVDCSS_NOFLAGS ) != 1 ) break;
/* Stop when we find a non MPEG stream block */
if( memcmp( p_buf, p_packstart, 4 ) )
{
for( j = i+1 ;
j < 0x80 && ( p_buf[0x7F - (j%i)] == p_buf[0x7F-j] );
j++ );
/* The title is unencrypted */
if( !b_encrypted )
break;
/* dvdcss some times fail to find/crack the key,
hope that it's the same as the one in the next title
_dvdcss_debug( dvdcss, "no key found at end of title" );
*/
}
/* PES_scrambling_control on and make sure that the packet type
is one that can be scrambled */
if( p_buf[0x14] & 0x30 && ! ( p_buf[0x11] == 0xbb
|| p_buf[0x11] == 0xbe
|| p_buf[0x11] == 0xbf ) )
{
b_encrypted = 1;
i_best_plen = 0;
i_best_p = 0;
for( i = 2 ; i < 0x30 ; i++ )
{
if( j > i_best_plen )
for( j = i+1 ;
j < 0x80 && ( p_buf[0x7F - (j%i)] == p_buf[0x7F-j] );
j++ );
{
i_best_plen = j;
i_best_p = i;
if( j > i_best_plen )
{
i_best_plen = j;
i_best_p = i;
}
}
}
if( ( i_best_plen > 20 ) && ( i_best_plen / i_best_p >= 2) )
{
i = CSSTitleCrack( 0, &p_buf[0x80],
&p_buf[0x80 - ( i_best_plen / i_best_p) *i_best_p],
(dvd_key_t*)&p_buf[0x54],
&p_key );
b_stop_scanning = ( i >= 0 );
}
}
if( ( i_best_plen > 20 ) && ( i_best_plen / i_best_p >= 2) )
{
i = CSSCracker( 0, &p_buf[0x80],
&p_buf[0x80 - ( i_best_plen / i_best_p) *i_best_p],
(dvd_key_t*)&p_buf[0x54],
&p_key );
b_stop_scanning = ( i >= 0 );
}
i_pos += 1;
i_blocks_read += 1;
/* If we haven't seen any encrypted ones after 3000 blocks stop */
if( !b_encrypted && i_blocks_read >= 1000 ) break;
} while( !b_stop_scanning );
if( b_stop_scanning )
{
memcpy( dvdcss->css.p_title_key, &p_key, sizeof(dvd_key_t) );
_dvdcss_debug( dvdcss, "vts key initialized" );
return 0;
}
i_pos += 1;
i_blocks_read += 1;
if( !b_encrypted )
{
_dvdcss_debug( dvdcss, "file was unscrambled" );
return 0;
}
/* If we haven't seen any encrypted ones after 3000 blocks stop */
if( !b_encrypted && i_blocks_read >= 1000 ) break;
} while( !b_stop_scanning );
if( b_stop_scanning )
{
memcpy( p_titlekey, &p_key, sizeof(dvd_key_t) );
_dvdcss_debug( dvdcss, "vts key initialized" );
return 0;
return -1;
}
if( !b_encrypted )
else
{
_dvdcss_debug( dvdcss, "file was unscrambled" );
return 0;
}
/*
* if we are here we have a decrypted disc key and ioctls are available
* so we can read the title key and decrypt it.
*/
return -1;
/* We need to authenticate again for every key
* (to get a new session key ?) */
CSSAuth( dvdcss );
/* Get encrypted title key */
if( ioctl_ReadTitleKey( dvdcss->i_fd, &dvdcss->css.i_agid,
i_pos, p_key ) < 0 )
{
_dvdcss_error( dvdcss, "ioctl_ReadTitleKey failed" );
return -1;
}
/* Unencrypt title key using bus key */
for( i = 0 ; i < KEY_SIZE ; i++ )
{
p_key[ i ] ^= dvdcss->css.disc.p_key_check[ 4 - (i % KEY_SIZE) ];
}
/* Title key decryption needs one inversion 0xff */
CSSDecryptKey( p_key, dvdcss->css.disc.p_disc_key, 0xff );
memcpy( dvdcss->css.p_title_key, p_key, sizeof(dvd_key_t) );
return 0;
} // ( dvdcss->i_method == DVDCSS_TITLECRACK ) || ( dvdcss->b_ioctls == 0 )
}
/*****************************************************************************
* CSSDescrambleSector
* CSSDescrambleSector: does the actual descrambling of data
*****************************************************************************
* sec : sector to descramble
* key : title key for this sector
@ -420,7 +528,7 @@ int CSSDescrambleSector( dvd_key_t p_key, u8* p_sec )
i_t1 = ( ( i_t1 & 1 ) << 8 ) ^ i_t4;
i_t4 = p_css_tab5[i_t4];
i_t6 = ((((((( i_t3 >> 3 ) ^ i_t3 ) >> 1 ) ^
i_t3 ) >> 8 ) ^ i_t3 ) >> 5) & 0xff;
i_t3 ) >> 8 ) ^ i_t3 ) >> 5 ) & 0xff;
i_t3 = (i_t3 << 8 ) | i_t6;
i_t6 = p_css_tab4[i_t6];
i_t5 += i_t6 + i_t4;
@ -473,7 +581,7 @@ static int CSSGetASF( dvdcss_handle dvdcss )
/*****************************************************************************
* CSSCryptKey : shuffles bits and unencrypt keys.
*****************************************************************************
* Used during authentication and disc key negociation in CSSInit.
* Used during authentication and disc key negociation in CSSAuth.
* i_key_type : 0->key1, 1->key2, 2->buskey.
* i_varient : between 0 and 31.
*****************************************************************************/
@ -678,15 +786,296 @@ static void CSSCryptKey( int i_key_type, int i_varient,
}
/*****************************************************************************
* CSSCracker : title key decryption by cracking
* CSSDecryptKey: decrypt p_crypted with p_key.
*****************************************************************************
* This function is called by CSSGetKeys to find a key
* Decryption is slightly dependant on the type of key:
* -for disc key, invert is 0x00,
* -for title key, invert if 0xff.
*****************************************************************************/
static int CSSCracker( int i_start,
unsigned char * p_crypted,
unsigned char * p_decrypted,
dvd_key_t * p_sector_key,
dvd_key_t * p_key )
static void CSSDecryptKey( u8* p_crypted, u8* p_key, u8 invert )
{
unsigned int i_lfsr1_lo;
unsigned int i_lfsr1_hi;
unsigned int i_lfsr0;
unsigned int i_combined;
byte_t o_lfsr0;
byte_t o_lfsr1;
byte_t k[5];
int i;
i_lfsr1_lo = p_key[0] | 0x100;
i_lfsr1_hi = p_key[1];
i_lfsr0 = ( ( p_key[4] << 17 )
| ( p_key[3] << 9 )
| ( p_key[2] << 1 ) )
+ 8 - ( p_key[2] & 7 );
i_lfsr0 = ( p_css_tab4[i_lfsr0 & 0xff] << 24 ) |
( p_css_tab4[( i_lfsr0 >> 8 ) & 0xff] << 16 ) |
( p_css_tab4[( i_lfsr0 >> 16 ) & 0xff] << 8 ) |
p_css_tab4[( i_lfsr0 >> 24 ) & 0xff];
i_combined = 0;
for( i = 0 ; i < KEY_SIZE ; ++i )
{
o_lfsr1 = p_css_tab2[i_lfsr1_hi] ^ p_css_tab3[i_lfsr1_lo];
i_lfsr1_hi = i_lfsr1_lo >> 1;
i_lfsr1_lo = ( ( i_lfsr1_lo & 1 ) << 8 ) ^ o_lfsr1;
o_lfsr1 = p_css_tab4[o_lfsr1];
o_lfsr0 = ((((((( i_lfsr0 >> 8 ) ^ i_lfsr0 ) >> 1 )
^ i_lfsr0 ) >> 3 ) ^ i_lfsr0 ) >> 7 );
i_lfsr0 = ( i_lfsr0 >> 8 ) | ( o_lfsr0 << 24 );
i_combined += ( o_lfsr0 ^ invert ) + o_lfsr1;
k[i] = i_combined & 0xff;
i_combined >>= 8;
}
p_crypted[4] = k[4] ^ p_css_tab1[p_crypted[4]] ^ p_crypted[3];
p_crypted[3] = k[3] ^ p_css_tab1[p_crypted[3]] ^ p_crypted[2];
p_crypted[2] = k[2] ^ p_css_tab1[p_crypted[2]] ^ p_crypted[1];
p_crypted[1] = k[1] ^ p_css_tab1[p_crypted[1]] ^ p_crypted[0];
p_crypted[0] = k[0] ^ p_css_tab1[p_crypted[0]] ^ p_crypted[4];
p_crypted[4] = k[4] ^ p_css_tab1[p_crypted[4]] ^ p_crypted[3];
p_crypted[3] = k[3] ^ p_css_tab1[p_crypted[3]] ^ p_crypted[2];
p_crypted[2] = k[2] ^ p_css_tab1[p_crypted[2]] ^ p_crypted[1];
p_crypted[1] = k[1] ^ p_css_tab1[p_crypted[1]] ^ p_crypted[0];
p_crypted[0] = k[0] ^ p_css_tab1[p_crypted[0]];
return;
}
/*****************************************************************************
* CSSDiscCrack: brute force disc key
* CSS hash reversal function designed by Frank Stevenson
*****************************************************************************
* This function uses a big amount of memory to crack the disc key from the
* disc key hash, if player keys are not available.
*****************************************************************************/
#define K1TABLEWIDTH 10
/*
* Simple function to test if a candidate key produces the given hash
*/
static int investigate( unsigned char* hash, unsigned char *ckey )
{
unsigned char key[5];
unsigned char pkey[5];
memcpy( key, hash, 5 );
memcpy( pkey, ckey, 5 );
CSSDecryptKey( key, pkey, 0 );
return memcmp( key, pkey, 5 );
}
static int CSSDiscCrack( u8 * p_disc_key )
{
unsigned char B[5] = { 0,0,0,0,0 }; /* Second Stage of mangle cipher */
unsigned char C[5] = { 0,0,0,0,0 }; /* Output Stage of mangle cipher
* IntermediateKey */
unsigned char k[5] = { 0,0,0,0,0 }; /* Mangling cipher key
* Also output from CSS( C ) */
unsigned char out1[5]; /* five first output bytes of LFSR1 */
unsigned char out2[5]; /* five first output bytes of LFSR2 */
unsigned int lfsr1a; /* upper 9 bits of LFSR1 */
unsigned int lfsr1b; /* lower 8 bits of LFSR1 */
unsigned int tmp, tmp2, tmp3, tmp4,tmp5;
int i,j;
unsigned int nStepA; /* iterator for LFSR1 start state */
unsigned int nStepB; /* iterator for possible B[0] */
unsigned int nTry; /* iterator for K[1] possibilities */
unsigned int nPossibleK1; /* #of possible K[1] values */
unsigned char* K1table; /* Lookup table for possible K[1] */
unsigned int* BigTable; /* LFSR2 startstate indexed by
* 1,2,5 output byte */
/*
* Prepare tables for hash reversal
*/
/* initialize lookup tables for k[1] */
K1table = malloc( 65536 * K1TABLEWIDTH );
memset( K1table, 0 , 65536 * K1TABLEWIDTH );
if( K1table == NULL )
{
return -1;
}
tmp = p_disc_key[0] ^ p_css_tab1[ p_disc_key[1] ];
for( i = 0 ; i < 256 ; i++ ) /* k[1] */
{
tmp2 = p_css_tab1[ tmp ^ i ]; /* p_css_tab1[ B[1] ]*/
for( j = 0 ; j < 256 ; j++ ) /* B[0] */
{
tmp3 = j ^ tmp2 ^ i; /* C[1] */
tmp4 = K1table[ K1TABLEWIDTH * ( 256 * j + tmp3 ) ]; /* count of entries here */
tmp4++;
if( tmp4 == K1TABLEWIDTH )
{
// _dvdcss_debug( dvdcss, "Table disaster %d", tmp4 );
}
if( tmp4 < K1TABLEWIDTH )
{
K1table[ K1TABLEWIDTH * ( 256 * j + tmp3 ) + tmp4 ] = i;
}
K1table[ K1TABLEWIDTH * ( 256 * j + tmp3 ) ] = tmp4;
}
}
/* Initing our Really big table */
BigTable = malloc( 16777216 * sizeof(int) );
memset( BigTable, 0 , 16777216 * sizeof(int) );
if( BigTable == NULL )
{
return -1;
}
tmp3 = 0;
for( i = 0 ; i < 16777216 ; i++ )
{
/*
if( ( i & 0x07ffff ) == 0 )
{
printf( "#" );
fflush( stdout );
}
*/
tmp = (( i + i ) & 0x1fffff0 ) | 0x8 | ( i & 0x7 );
for( j = 0 ; j < 5 ; j++ )
{
tmp2=((((((( tmp >> 3 ) ^ tmp ) >> 1 ) ^ tmp ) >> 8 )
^ tmp ) >> 5 ) & 0xff;
tmp = ( tmp << 8) | tmp2;
out2[j] = p_css_tab4[ tmp2 ];
}
j = ( out2[0] << 16 ) | ( out2[1] << 8 ) | out2[4];
BigTable[j] = i;
}
// printf( "\n" );
/*
* We are done initing, now reverse hash
*/
tmp5 = p_disc_key[0] ^ p_css_tab1[ p_disc_key[1] ];
for( nStepA = 0 ; nStepA < 65536 ; nStepA ++ )
{
lfsr1a = 0x100 | ( nStepA >> 8 );
lfsr1b = nStepA & 0xff;
/* Generate 5 first output bytes from lfsr1 */
for( i = 0 ; i < 5 ; i++ )
{
tmp = p_css_tab2[ lfsr1b ] ^ p_css_tab3[ lfsr1a ];
lfsr1b = lfsr1a >> 1;
lfsr1a = ((lfsr1a&1)<<8) ^ tmp;
out1[ i ] = p_css_tab4[ tmp ];
}
/* cumpute and cache some variables */
C[0] = nStepA >> 8;
C[1] = nStepA & 0xff;
tmp = p_disc_key[3] ^ p_css_tab1[ p_disc_key[4] ];
tmp2 = p_css_tab1[ p_disc_key[0] ];
/* Search through all possible B[0] */
for( nStepB = 0 ; nStepB < 256 ; nStepB++ )
{
/* reverse parts of the mangling cipher */
B[0] = nStepB;
k[0] = p_css_tab1[ B[0] ] ^ C[0];
B[4] = B[0] ^ k[0] ^ tmp2;
k[4] = B[4] ^ tmp;
nPossibleK1 = K1table[ K1TABLEWIDTH * (256 * B[0] + C[1]) ];
/* Try out all possible values for k[1] */
for( nTry = 0 ; nTry < nPossibleK1 ; nTry++ )
{
k[1] = K1table[ K1TABLEWIDTH * (256 * B[0] + C[1]) + nTry + 1 ];
B[1] = tmp5 ^ k[1];
/* reconstruct output from LFSR2 */
tmp3 = ( 0x100 + k[0] - out1[0] );
out2[0] = tmp3 & 0xff;
tmp3 = tmp3 & 0x100 ? 0x100 : 0xff;
tmp3 = ( tmp3 + k[1] - out1[1] );
out2[1] = tmp3 & 0xff;
tmp3 = ( 0x100 + k[4] - out1[4] );
out2[4] = tmp3 & 0xff; /* Can be 1 off */
/* test first possible out2[4] */
tmp4 = ( out2[0] << 16 ) | ( out2[1] << 8 ) | out2[4];
tmp4 = BigTable[ tmp4 ];
C[2] = tmp4 & 0xff;
C[3] = ( tmp4 >> 8 ) & 0xff;
C[4] = ( tmp4 >> 16 ) & 0xff;
B[3] = p_css_tab1[ B[4] ] ^ k[4] ^ C[4];
k[3] = p_disc_key[2] ^ p_css_tab1[ p_disc_key[3] ] ^ B[3];
B[2] = p_css_tab1[ B[3] ] ^ k[3] ^ C[3];
k[2] = p_disc_key[1] ^ p_css_tab1[ p_disc_key[2] ] ^ B[2];
if( ( B[1] ^ p_css_tab1[ B[2] ] ^ k[ 2 ] ) == C[ 2 ] )
{
if( ! investigate( &p_disc_key[0] , &C[0] ) )
{
goto end;
}
}
/* Test second possible out2[4] */
out2[4] = ( out2[4] + 0xff ) & 0xff;
tmp4 = ( out2[0] << 16 ) | ( out2[1] << 8 ) | out2[4];
tmp4 = BigTable[ tmp4 ];
C[2] = tmp4 & 0xff;
C[3] = ( tmp4 >> 8 ) & 0xff;
C[4] = ( tmp4 >> 16 ) & 0xff;
B[3] = p_css_tab1[ B[4] ] ^ k[4] ^ C[4];
k[3] = p_disc_key[2] ^ p_css_tab1[ p_disc_key[3] ] ^ B[3];
B[2] = p_css_tab1[ B[3] ] ^ k[3] ^ C[3];
k[2] = p_disc_key[1] ^ p_css_tab1[ p_disc_key[2] ] ^ B[2];
if( ( B[1] ^ p_css_tab1[ B[2] ] ^ k[ 2 ] ) == C[ 2 ] )
{
if( ! investigate( &p_disc_key[0] , &C[0] ) )
{
goto end;
}
}
}
}
}
end:
memcpy( p_disc_key, &C[0], KEY_SIZE );
free( K1table );
free( BigTable );
return( 0 );
}
/*****************************************************************************
* CSSTitleCrack : title key decryption by cracking
* Function designed by Frank Stevenson
*****************************************************************************
* This function is called by CSSGetTitleKey to find a title key, if we've
* chosen to crack title key instead of decrypting it with the disc key.
*****************************************************************************/
static int CSSTitleCrack( int i_start,
unsigned char * p_crypted,
unsigned char * p_decrypted,
dvd_key_t * p_sector_key,
dvd_key_t * p_key )
{
unsigned char p_buffer[10];
unsigned int i_t1, i_t2, i_t3, i_t4, i_t5, i_t6;
@ -806,4 +1195,3 @@ static int CSSCracker( int i_start,
return i_exit;
}

View File

@ -2,7 +2,7 @@
* css.h: Structures for DVD authentification and unscrambling
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
* $Id: css.h,v 1.5 2001/07/25 00:23:40 sam Exp $
* $Id: css.h,v 1.6 2001/10/13 15:34:21 stef Exp $
*
* Author: Stéphane Borel <stef@via.ecp.fr>
*
@ -37,6 +37,7 @@ typedef struct disc_s
dvd_key_t p_key2;
dvd_key_t p_key_check;
u8 i_varient;
u8 p_disc_key[2048];
} disc_t;
typedef struct dvd_title_s
@ -50,7 +51,7 @@ typedef struct css_s
{
int i_agid;
disc_t disc;
u8 p_disc_key[2048];
dvd_key_t p_title_key;
} css_t;
/*****************************************************************************
@ -59,7 +60,8 @@ typedef struct css_s
struct css_s;
int CSSTest ( dvdcss_handle );
int CSSInit ( dvdcss_handle );
int CSSGetKey ( dvdcss_handle, int, dvd_key_t );
int CSSAuth ( dvdcss_handle );
int CSSGetDiscKey ( dvdcss_handle );
int CSSGetTitleKey ( dvdcss_handle, int );
int CSSDescrambleSector ( u8 * , u8 * );

View File

@ -2,7 +2,7 @@
* csstables.h: CSS Tables for DVD unscrambling
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
* $Id: csstables.h,v 1.2 2001/07/11 02:01:03 sam Exp $
* $Id: csstables.h,v 1.3 2001/10/13 15:34:21 stef Exp $
*
* Author: Stéphane Borel <stef@via.ecp.fr>
*
@ -29,6 +29,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
static u8 p_css_tab1[ 256 ] =
{
0x33, 0x73, 0x3b, 0x26, 0x63, 0x23, 0x6b, 0x76,

View File

@ -2,7 +2,7 @@
* ioctl.c: DVD ioctl replacement function
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
* $Id: ioctl.c,v 1.12 2001/09/28 15:24:11 massiot Exp $
* $Id: ioctl.c,v 1.13 2001/10/13 15:34:21 stef Exp $
*
* Authors: Markus Kuespert <ltlBeBoy@beosmail.com>
* Samuel Hocevar <sam@zoy.org>
@ -30,6 +30,8 @@
*****************************************************************************/
#include "defs.h"
#include <stdio.h>
#include <string.h> /* memcpy(), memset() */
#include <sys/types.h>
@ -77,6 +79,7 @@
#include "ioctl.h"
/*****************************************************************************
* Local prototypes, BeOS specific
*****************************************************************************/
@ -234,9 +237,9 @@ int ioctl_ReadCopyright( int i_fd, int i_layer, int *pi_copyright )
}
/*****************************************************************************
* ioctl_ReadKey: get the disc key
* ioctl_ReadDiscKey: get the disc key
*****************************************************************************/
int ioctl_ReadKey( int i_fd, int *pi_agid, u8 *p_key )
int ioctl_ReadDiscKey( int i_fd, int *pi_agid, u8 *p_key )
{
int i_ret;
@ -316,7 +319,6 @@ int ioctl_ReadKey( int i_fd, int *pi_agid, u8 *p_key )
dvd.grantID = *pi_agid;
i_ret = ioctl( i_fd, DKIOCDVDREADSTRUCTURE, &dvd );
memcpy( p_key, dvddki.discKeyStructures, 2048 );
#elif defined( WIN32 )
@ -368,6 +370,57 @@ int ioctl_ReadKey( int i_fd, int *pi_agid, u8 *p_key )
return i_ret;
}
/*****************************************************************************
* ioctl_ReadTitleKey: get the title key
*****************************************************************************/
int ioctl_ReadTitleKey( int i_fd, int *pi_agid, int i_pos, u8 *p_key )
{
int i_ret;
#if defined( HAVE_LINUX_DVD_STRUCT )
dvd_authinfo dvd_ai;
memset( &dvd_ai, 0, sizeof(dvd_ai) );
dvd_ai.type = DVD_LU_SEND_TITLE_KEY;
dvd_ai.lstk.agid = *pi_agid;
dvd_ai.lstk.lba = i_pos;
i_ret = ioctl( i_fd, DVD_AUTH, &dvd_ai );
if( i_ret < 0 )
{
return i_ret;
}
memcpy( p_key, dvd_ai.lstk.title_key, 5 );
#elif defined( HAVE_BSD_DVD_STRUCT )
i_ret = -1;
#elif defined( SYS_BEOS )
i_ret = -1;
#elif defined( SOLARIS_USCSI )
i_ret = -1;
#elif defined( SYS_DARWIN )
i_ret = 0;
memset( p_key, 0x00, KEY_SIZE );
#elif defined( WIN32 )
i_ret = -1;
#else
i_ret = -1;
#endif
return i_ret;
}
/*****************************************************************************
* ioctl_ReportAgid: get AGID from the drive
*****************************************************************************/
@ -745,14 +798,12 @@ int ioctl_ReportKey1( int i_fd, int *pi_agid, u8 *p_key )
memset(&dvd, 0, sizeof(dvd));
memset(&dvdk1i, 0, sizeof(dvdk1i));
dvd.buffer = &dvdk1i;
dvd.bufferLength = sizeof(dvdk1i);
dvd.format = kDVDKeyFormatKey1;
dvd.grantID = *pi_agid;
i_ret = ioctl( i_fd, DKIOCDVDREPORTKEY, &dvd );
memcpy( p_key, dvdk1i.key1Value, 5 );
#elif defined( WIN32 )

View File

@ -2,7 +2,7 @@
* ioctl.h: DVD ioctl replacement function
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
* $Id: ioctl.h,v 1.6 2001/08/08 02:48:44 sam Exp $
* $Id: ioctl.h,v 1.7 2001/10/13 15:34:21 stef Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
@ -22,8 +22,8 @@
*****************************************************************************/
int ioctl_ReadCopyright ( int, int, int * );
int ioctl_ReadKey ( int, int *, u8 * );
int ioctl_ReadDiscKey ( int, int *, u8 * );
int ioctl_ReadTitleKey ( int, int *, int, u8 * );
int ioctl_ReportAgid ( int, int * );
int ioctl_ReportChallenge ( int, int *, u8 * );
int ioctl_ReportKey1 ( int, int *, u8 * );

View File

@ -2,7 +2,7 @@
* libdvdcss.c: DVD reading library.
*****************************************************************************
* Copyright (C) 1998-2001 VideoLAN
* $Id: libdvdcss.c,v 1.15 2001/09/09 13:43:25 sam Exp $
* $Id: libdvdcss.c,v 1.16 2001/10/13 15:34:21 stef Exp $
*
* Authors: Stéphane Borel <stef@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
@ -80,7 +80,7 @@ static int _win32_dvdcss_aread ( int i_fd, void *p_data, int i_blocks );
/*****************************************************************************
* dvdcss_open: initialize library, open a DVD device, crack CSS key
*****************************************************************************/
extern dvdcss_handle dvdcss_open ( char *psz_target, int i_flags )
extern dvdcss_handle dvdcss_open ( char *psz_target, int i_method, int i_flags )
{
int i_ret;
@ -102,6 +102,7 @@ extern dvdcss_handle dvdcss_open ( char *psz_target, int i_flags )
dvdcss->p_titles = NULL;
dvdcss->b_debug = i_flags & DVDCSS_INIT_DEBUG;
dvdcss->b_errors = !(i_flags & DVDCSS_INIT_QUIET);
dvdcss->i_method = i_method;
dvdcss->psz_error = "no error";
i_ret = _dvdcss_open( dvdcss, psz_target );
@ -128,7 +129,7 @@ extern dvdcss_handle dvdcss_open ( char *psz_target, int i_flags )
/* If disc is CSS protected and the ioctls work, authenticate the drive */
if( dvdcss->b_encrypted && dvdcss->b_ioctls )
{
i_ret = CSSInit( dvdcss );
i_ret = CSSGetDiscKey( dvdcss );
if( i_ret < 0 )
{
@ -152,27 +153,36 @@ extern char * dvdcss_error ( dvdcss_handle dvdcss )
/*****************************************************************************
* dvdcss_seek: seek into the device
*****************************************************************************/
extern int dvdcss_seek ( dvdcss_handle dvdcss, int i_blocks )
extern int dvdcss_seek ( dvdcss_handle dvdcss, int i_blocks, int i_flags )
{
/* title cracking method is too slow to be used at each seek */
if( ( ( i_flags & DVDCSS_SEEK_MPEG ) && ( dvdcss->i_method != DVDCSS_TITLE ) )
|| ( i_flags & DVDCSS_SEEK_INI ) )
{
/* check the title key */
dvdcss_title( dvdcss, i_blocks );
}
return _dvdcss_seek( dvdcss, i_blocks );
}
/*****************************************************************************
* dvdcss_title: crack the current title key if needed
* dvdcss_title: crack or decrypt the current title key if needed
*****************************************************************************
* This function should only be called by dvdcss_seek and should eventually
* not be external if possible.
*****************************************************************************/
extern int dvdcss_title ( dvdcss_handle dvdcss, int i_block )
{
dvd_title_t *p_title;
dvd_key_t p_key;
int i_ret;
dvd_title_t *p_newtitle;
int i_ret;
if( ! dvdcss->b_encrypted )
{
return 0;
}
//fprintf( stderr, "looking for a key for offset %i\n", i_block );
/* Check if we've already cracked this key */
p_title = dvdcss->p_titles;
while( p_title != NULL
@ -186,11 +196,12 @@ extern int dvdcss_title ( dvdcss_handle dvdcss, int i_block )
&& p_title->i_startlb == i_block )
{
/* We've already cracked this key, nothing to do */
memcpy( dvdcss->css.p_title_key, p_title->p_key, sizeof(dvd_key_t) );
return 0;
}
/* Crack CSS title key for current VTS */
i_ret = CSSGetKey( dvdcss, i_block, p_key );
/* Crack or decrypt CSS title key for current VTS */
i_ret = CSSGetTitleKey( dvdcss, i_block );
if( i_ret < 0 )
{
@ -203,49 +214,39 @@ extern int dvdcss_title ( dvdcss_handle dvdcss, int i_block )
return -1;
}
//fprintf( stderr, "cracked key is %.2x %.2x %.2x %.2x %.2x\n",
// p_key[0], p_key[1], p_key[2], p_key[3], p_key[4] );
/* Add key to keytable if it isn't empty */
/* We need to cache the fact that a title is unencrypted
if( p_key[0] | p_key[1] | p_key[2] | p_key[3] | p_key[4] ) */
/* Find our spot in the list */
p_newtitle = NULL;
p_title = dvdcss->p_titles;
while( ( p_title != NULL ) && ( p_title->i_startlb < i_block ) )
{
dvd_title_t *p_newtitle;
p_newtitle = p_title;
p_title = p_title->p_next;
}
/* Find our spot in the list */
p_newtitle = NULL;
p_title = dvdcss->p_titles;
while( p_title != NULL
&& p_title->i_startlb < i_block )
{
p_newtitle = p_title;
p_title = p_title->p_next;
}
/* Save the found title */
p_title = p_newtitle;
/* Save the found title */
p_title = p_newtitle;
/* Write in the new title and its key */
p_newtitle = malloc( sizeof( dvd_title_t ) );
p_newtitle->i_startlb = i_block;
memcpy( p_newtitle->p_key, dvdcss->css.p_title_key, KEY_SIZE );
/* Write in the new title and its key */
p_newtitle = malloc( sizeof( dvd_title_t ) );
p_newtitle->i_startlb = i_block;
memcpy( p_newtitle->p_key, p_key, KEY_SIZE );
/* Link the new title, either at the beginning or inside the list */
if( p_title == NULL )
{
dvdcss->p_titles = p_newtitle;
p_newtitle->p_next = NULL;
}
else
{
p_newtitle->p_next = p_title->p_next;
p_title->p_next = p_newtitle;
}
/* Link the new title, either at the beginning or inside the list */
if( p_title == NULL )
{
dvdcss->p_titles = p_newtitle;
p_newtitle->p_next = NULL;
}
else
{
p_newtitle->p_next = p_title->p_next;
p_title->p_next = p_newtitle;
}
return 0;
}
#define Pkey dvdcss->css.p_title_key
/*****************************************************************************
* dvdcss_read: read data from the device, decrypt if requested
*****************************************************************************/
@ -253,7 +254,6 @@ extern int dvdcss_read ( dvdcss_handle dvdcss, void *p_buffer,
int i_blocks,
int i_flags )
{
dvd_title_t *p_title;
int i_ret, i_index;
i_ret = _dvdcss_read( dvdcss, p_buffer, i_blocks );
@ -265,25 +265,9 @@ extern int dvdcss_read ( dvdcss_handle dvdcss, void *p_buffer,
return i_ret;
}
/* find our key */
p_title = dvdcss->p_titles;
while( p_title != NULL
&& p_title->p_next
&& p_title->p_next->i_startlb <= dvdcss->i_seekpos )
{
p_title = p_title->p_next;
}
if( p_title == NULL )
{
/* no css key found to use, so no decryption to do */
return 0;
}
/* For what we believe is an unencrypted title,
check that there are no encrypted blocks */
if( !( p_title->p_key[0] | p_title->p_key[1] | p_title->p_key[2] |
p_title->p_key[3] | p_title->p_key[4] ) )
if( !( Pkey[0] | Pkey[1] | Pkey[2] | Pkey[3] | Pkey[4] ) )
{
for( i_index = i_ret; i_index; i_index-- )
{
@ -301,7 +285,7 @@ extern int dvdcss_read ( dvdcss_handle dvdcss, void *p_buffer,
/* Decrypt the blocks we managed to read */
for( i_index = i_ret; i_index; i_index-- )
{
CSSDescrambleSector( p_title->p_key, p_buffer );
CSSDescrambleSector( dvdcss->css.p_title_key, p_buffer );
((u8*)p_buffer)[0x14] &= 0x8f;
(u8*)p_buffer += DVDCSS_BLOCK_SIZE;
}
@ -310,14 +294,13 @@ extern int dvdcss_read ( dvdcss_handle dvdcss, void *p_buffer,
}
/*****************************************************************************
* dvdcss_readv: read data to an iovec structure, decrypt if reaquested
* dvdcss_readv: read data to an iovec structure, decrypt if requested
*****************************************************************************/
extern int dvdcss_readv ( dvdcss_handle dvdcss, void *p_iovec,
int i_blocks,
int i_flags )
{
#define P_IOVEC ((struct iovec*)p_iovec)
dvd_title_t *p_title;
int i_ret, i_index;
void *iov_base;
size_t iov_len;
@ -331,20 +314,6 @@ extern int dvdcss_readv ( dvdcss_handle dvdcss, void *p_iovec,
return i_ret;
}
/* Find our key */
p_title = dvdcss->p_titles;
while( p_title != NULL
&& p_title->p_next != NULL
&& p_title->p_next->i_startlb <= dvdcss->i_seekpos )
{
p_title = p_title->p_next;
}
if( p_title == NULL )
{
/* no css key found to use, so no decryption to do */
return 0;
}
/* Initialize loop for decryption */
iov_base = P_IOVEC->iov_base;
@ -366,7 +335,7 @@ extern int dvdcss_readv ( dvdcss_handle dvdcss, void *p_iovec,
iov_len = P_IOVEC->iov_len;
}
CSSDescrambleSector( p_title->p_key, iov_base );
CSSDescrambleSector( dvdcss->css.p_title_key, iov_base );
((u8*)iov_base)[0x14] &= 0x8f;
(u8*)iov_base += DVDCSS_BLOCK_SIZE;
@ -376,6 +345,7 @@ extern int dvdcss_readv ( dvdcss_handle dvdcss, void *p_iovec,
return i_ret;
#undef P_IOVEC
}
#undef Pkey
/*****************************************************************************
* dvdcss_close: close the DVD device and clean up the library

View File

@ -2,7 +2,7 @@
* private.h: private DVD reading library data
*****************************************************************************
* Copyright (C) 1998-2001 VideoLAN
* $Id: libdvdcss.h,v 1.7 2001/09/09 13:43:25 sam Exp $
* $Id: libdvdcss.h,v 1.8 2001/10/13 15:34:21 stef Exp $
*
* Authors: Stéphane Borel <stef@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
@ -37,6 +37,7 @@ struct dvdcss_s
int i_seekpos;
/* Decryption stuff */
int i_method;
css_t css;
boolean_t b_ioctls;
boolean_t b_encrypted;

View File

@ -2,7 +2,7 @@
* libdvdcss.h: DVD reading library, exported functions.
*****************************************************************************
* Copyright (C) 1998-2001 VideoLAN
* $Id: dvdcss.h,v 1.5 2001/07/27 14:43:30 sam Exp $
* $Id: dvdcss.h,v 1.6 2001/10/13 15:34:21 stef Exp $
*
* Authors: Stéphane Borel <stef@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
@ -37,18 +37,30 @@ typedef struct dvdcss_s* dvdcss_handle;
#define DVDCSS_READ_DECRYPT (1 << 0)
#define DVDCSS_SEEK_INI (1 << 0)
#define DVDCSS_SEEK_MPEG (2 << 0)
#define DVDCSS_BLOCK_SIZE 2048
/*****************************************************************************
* libdvdcss method: used like init flags
*****************************************************************************/
#define DVDCSS_KEY 0
#define DVDCSS_DISC 1
#define DVDCSS_TITLE 2
/*****************************************************************************
* Exported prototypes
*****************************************************************************/
extern dvdcss_handle dvdcss_open ( char *psz_target,
int i_method,
int i_flags );
extern int dvdcss_close ( dvdcss_handle );
extern int dvdcss_title ( dvdcss_handle,
int i_block );
extern int dvdcss_seek ( dvdcss_handle,
int i_blocks );
int i_blocks,
int i_flags );
extern int dvdcss_read ( dvdcss_handle,
void *p_buffer,
int i_blocks,

View File

@ -220,6 +220,8 @@
#define INPUT_AUDIO_VAR "vlc_input_audio"
#define INPUT_CHANNEL_VAR "vlc_input_channel"
#define INPUT_SUBTITLE_VAR "vlc_input_subtitle"
#define INPUT_DVDCSS_VAR "vlc_input_dvdcss"
#define INPUT_DVDCSS_DEFAULT "title"
/* VCD defaults */
#define INPUT_VCD_DEVICE_VAR "vlc_vcd_device"

View File

@ -172,6 +172,9 @@
/* Define if you have the pth library (-lpth). */
#undef HAVE_LIBPTH
/* css decryption with player keys */
#undef HAVE_CSSKEYS
/* long getopt support */
#undef HAVE_GETOPT_LONG

View File

@ -2,7 +2,7 @@
* dvd_ifo.c: Functions for ifo parsing
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
* $Id: dvd_ifo.c,v 1.37 2001/08/09 20:16:17 jlj Exp $
* $Id: dvd_ifo.c,v 1.38 2001/10/13 15:34:21 stef Exp $
*
* Authors: Stéphane Borel <stef@via.ecp.fr>
* German Tischler <tanis@gaspode.franken.de>
@ -1047,7 +1047,8 @@ static int ReadTitle( ifo_t * p_ifo, title_t * p_title, int i_block, int i_bytes
if( p_title->i_chapter_map_start_byte )
{
p_ifo->i_pos = dvdcss_seek( p_ifo->dvdhandle,
OFF2LB( i_start + p_title->i_chapter_map_start_byte ) );
OFF2LB( i_start + p_title->i_chapter_map_start_byte ),
DVDCSS_NOFLAGS );
p_title->chapter_map.pi_start_cell =
malloc( p_title->i_chapter_nb * sizeof(chapter_map_t) );
@ -2098,7 +2099,7 @@ void CommandPrint( ifo_t ifo )
*****************************************************************************/
static u8* FillBuffer( ifo_t* p_ifo, u8* p_buf, int i_pos )
{
p_ifo->i_pos = dvdcss_seek( p_ifo->dvdhandle, i_pos );
p_ifo->i_pos = dvdcss_seek( p_ifo->dvdhandle, i_pos, DVDCSS_NOFLAGS );
dvdcss_read( p_ifo->dvdhandle, p_buf, 1, DVDCSS_NOFLAGS );
return p_buf;

View File

@ -5,7 +5,7 @@
* contains the basic udf handling functions
*****************************************************************************
* Copyright (C) 1998-2001 VideoLAN
* $Id: dvd_udf.c,v 1.13 2001/08/06 13:28:00 sam Exp $
* $Id: dvd_udf.c,v 1.14 2001/10/13 15:34:21 stef Exp $
*
* Author: Stéphane Borel <stef@via.ecp.fr>
*
@ -109,7 +109,7 @@ typedef struct ad_s
static int UDFReadLB( dvdcss_handle dvdhandle, off_t i_lba,
size_t i_block_count, u8 *pi_data )
{
if( dvdcss_seek( dvdhandle, i_lba ) < 0 )
if( dvdcss_seek( dvdhandle, i_lba, DVDCSS_NOFLAGS ) < 0 )
{
intf_ErrMsg( "UDF: Postion not found" );
return 0;

View File

@ -10,7 +10,7 @@
* -dvd_udf to find files
*****************************************************************************
* Copyright (C) 1998-2001 VideoLAN
* $Id: input_dvd.c,v 1.87 2001/10/02 16:46:59 massiot Exp $
* $Id: input_dvd.c,v 1.88 2001/10/13 15:34:21 stef Exp $
*
* Author: Stéphane Borel <stef@via.ecp.fr>
*
@ -199,7 +199,7 @@ static void DVDInit( input_thread_t * p_input )
p_dvd->dvdhandle = (dvdcss_handle) p_input->i_handle;
dvdcss_seek( p_dvd->dvdhandle, 0 );
dvdcss_seek( p_dvd->dvdhandle, 0, DVDCSS_NOFLAGS );
/* We read DVD_BLOCK_READ_ONCE in each loop, so the input will receive
* DVD_DATA_READ_ONCE at most */
@ -306,6 +306,8 @@ static void DVDInit( input_thread_t * p_input )
static void DVDOpen( struct input_thread_s *p_input )
{
dvdcss_handle dvdhandle;
char * psz_method;
int i_method;
vlc_mutex_lock( &p_input->stream.stream_lock );
@ -320,14 +322,33 @@ static void DVDOpen( struct input_thread_s *p_input )
vlc_mutex_unlock( &p_input->stream.stream_lock );
/* XXX: put this shit in an access plugin */
if( strlen( p_input->p_source ) > 4
&& !strncasecmp( p_input->p_source, "dvd:", 4 ) )
psz_method = main_GetPszVariable( INPUT_DVDCSS_VAR,
INPUT_DVDCSS_DEFAULT );
if( !strncmp( psz_method, "key", 3 ) )
{
dvdhandle = dvdcss_open( p_input->p_source + 4, DVDCSS_INIT_QUIET );
i_method = DVDCSS_KEY;
}
else if( !strncmp( psz_method, "disc", 4 ) )
{
i_method = DVDCSS_DISC;
}
else
{
dvdhandle = dvdcss_open( p_input->p_source, DVDCSS_INIT_QUIET );
i_method = DVDCSS_TITLE;
}
if( strlen( p_input->p_source ) > 4
&& !strncasecmp( p_input->p_source, "dvd:", 4 ) )
{
dvdhandle = dvdcss_open( p_input->p_source + 4,
i_method,
DVDCSS_INIT_QUIET );
}
else
{
dvdhandle = dvdcss_open( p_input->p_source,
i_method,
DVDCSS_INIT_QUIET );
}
if( dvdhandle == NULL )
@ -429,11 +450,6 @@ static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area )
intf_WarnMsgImm( 3, "dvd: title %d vts_title %d pgc %d",
p_dvd->i_title, i_vts_title, p_dvd->i_title_id );
/*
* Tell libdvdcss we changed title
*/
dvdcss_title( p_dvd->dvdhandle,
vts.i_pos + vts.manager_inf.i_title_vob_start_sector );
/*
* Angle management
@ -745,6 +761,13 @@ static int DVDSetArea( input_thread_t * p_input, input_area_t * p_area )
}
}
/*
* Force libdvdcss to check its title key.
* It is only useful for title cracking method. Methods using the decrypted
* disc key are fast enough to check the key at each seek
*/
dvdcss_seek( p_dvd->dvdhandle, p_dvd->i_start, DVDCSS_SEEK_INI );
#define title \
p_dvd->p_ifo->vts.title_unit.p_title[p_dvd->i_title_id-1].title
if( p_area->i_angle != p_dvd->i_angle )
@ -809,6 +832,7 @@ static int DVDRead( input_thread_t * p_input,
i_sector = p_dvd->i_title_start + p_dvd->i_sector;
i_block_once = p_dvd->i_end_sector - p_dvd->i_sector + 1;
/* Get the position of the next cell if we're at cell end */
if( i_block_once <= 0 )
{
@ -827,7 +851,8 @@ static int DVDRead( input_thread_t * p_input,
/* Position the fd pointer on the right address */
i_sector = dvdcss_seek( p_dvd->dvdhandle,
p_dvd->i_title_start + p_dvd->i_sector );
p_dvd->i_title_start + p_dvd->i_sector,
DVDCSS_SEEK_MPEG );
/* update chapter : it will be easier when we have navigation
* ES support */
@ -1079,8 +1104,9 @@ static void DVDSeek( input_thread_t * p_input, off_t i_off )
p_input->stream.p_selected_area->i_part = p_dvd->i_chapter;
p_input->stream.p_selected_area->i_tell =
LB2OFF ( dvdcss_seek( p_dvd->dvdhandle, p_dvd->i_title_start
+ p_dvd->i_sector ) )
LB2OFF ( dvdcss_seek( p_dvd->dvdhandle,
p_dvd->i_title_start + p_dvd->i_sector,
DVDCSS_SEEK_MPEG ) )
- p_input->stream.p_selected_area->i_start;
intf_WarnMsg( 7, "Program Cell: %d Cell: %d Chapter: %d",
@ -1211,7 +1237,9 @@ static int DVDChapterSelect( thread_dvd_data_t * p_dvd, int i_chapter )
p_dvd->i_start = p_dvd->i_title_start + p_dvd->i_sector;
/* Position the fd pointer on the right address */
p_dvd->i_start = dvdcss_seek( p_dvd->dvdhandle, p_dvd->i_start );
p_dvd->i_start = dvdcss_seek( p_dvd->dvdhandle,
p_dvd->i_start,
DVDCSS_SEEK_MPEG );
p_dvd->i_chapter = i_chapter;
return 0;

View File

@ -2,7 +2,7 @@
* aout_spdif: ac3 passthrough output
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: aout_spdif.c,v 1.16 2001/09/30 00:33:22 stef Exp $
* $Id: aout_spdif.c,v 1.17 2001/10/13 15:34:21 stef Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Stéphane Borel <stef@via.ecp.fr>
@ -118,7 +118,7 @@ void aout_SpdifThread( aout_thread_t * p_aout )
}
else
{
mwait( m_play - 4* m_frame_time );
mwait( m_play - 3* m_frame_time );
}
m_old = m_play;

View File

@ -4,7 +4,7 @@
* and spawn threads.
*****************************************************************************
* Copyright (C) 1998, 1999, 2000 VideoLAN
* $Id: main.c,v 1.117 2001/10/03 15:10:55 sam Exp $
* $Id: main.c,v 1.118 2001/10/13 15:34:21 stef Exp $
*
* Authors: Vincent Seguin <seguin@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
@ -129,6 +129,7 @@
#define OPT_YUV 183
#define OPT_DOWNMIX 184
#define OPT_IMDCT 185
#define OPT_DVDCSS 186
#define OPT_SYNCHRO 190
#define OPT_WARNING 191
@ -199,6 +200,7 @@ static const struct option longopts[] =
{ "dvdaudio", 1, 0, 'a' },
{ "dvdchannel", 1, 0, 'c' },
{ "dvdsubtitle", 1, 0, 's' },
{ "dvdcss_method", 1, 0, OPT_DVDCSS },
/* Input options */
{ "input", 1, 0, OPT_INPUT },
@ -738,16 +740,16 @@ static int GetConfiguration( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] )
break;
/* DVD options */
case 't':
case 't': /* --dvdtitle */
main_PutIntVariable( INPUT_TITLE_VAR, atoi(optarg) );
break;
case 'T':
case 'T': /* --dvdchapter */
main_PutIntVariable( INPUT_CHAPTER_VAR, atoi(optarg) );
break;
case 'u':
case 'u': /* --dvdangle */
main_PutIntVariable( INPUT_ANGLE_VAR, atoi(optarg) );
break;
case 'a':
case 'a': /* --dvdaudio */
if ( ! strcmp(optarg, "ac3") )
main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_AC3 );
else if ( ! strcmp(optarg, "lpcm") )
@ -757,12 +759,15 @@ static int GetConfiguration( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] )
else
main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_NOAUDIO );
break;
case 'c':
case 'c': /* --dvdchannel */
main_PutIntVariable( INPUT_CHANNEL_VAR, atoi(optarg) );
break;
case 's':
case 's': /* --dvdsubtitle */
main_PutIntVariable( INPUT_SUBTITLE_VAR, atoi(optarg) );
break;
case OPT_DVDCSS: /* --dvdcss */
main_PutPszVariable( INPUT_DVDCSS_VAR, optarg );
break;
/* Input options */
case OPT_INPUT: /* --input */
@ -888,6 +893,7 @@ static void Usage( int i_fashion )
"\n -a, --dvdaudio <type> \tchoose DVD audio type"
"\n -c, --dvdchannel <channel> \tchoose DVD audio channel"
"\n -s, --dvdsubtitle <channel> \tchoose DVD subtitle channel"
"\n , --dvdcss <method> \tselect DVDCSS decryption method"
"\n"
"\n --input \tinput method"
"\n --channels \tenable channels"
@ -917,7 +923,7 @@ static void Usage( int i_fashion )
"\n " AOUT_SPDIF_VAR "={1|0} \tAC3 pass-through mode"
"\n " DOWNMIX_METHOD_VAR "=<method name> \tAC3 downmix method"
"\n " IMDCT_METHOD_VAR "=<method name> \tAC3 IMDCT method"
"\n " AOUT_RATE_VAR "=<rate> \toutput rate" );
"\n " AOUT_RATE_VAR "=<rate> \toutput rate" );
/* Video parameters */
intf_MsgImm( "\nVideo parameters:"
@ -938,22 +944,23 @@ static void Usage( int i_fashion )
/* DVD parameters */
intf_MsgImm( "\nDVD parameters:"
"\n " INPUT_DVD_DEVICE_VAR "=<device> \tDVD device"
"\n " INPUT_TITLE_VAR "=<title> \ttitle number"
"\n " INPUT_CHAPTER_VAR "=<chapter> \tchapter number"
"\n " INPUT_ANGLE_VAR "=<angle> \tangle number"
"\n " INPUT_AUDIO_VAR "={ac3|lpcm|mpeg|off} \taudio type"
"\n " INPUT_CHANNEL_VAR "=[0-15] \taudio channel"
"\n " INPUT_SUBTITLE_VAR "=[0-31] \tsubtitle channel" );
"\n " INPUT_DVD_DEVICE_VAR "=<device> \tDVD device"
"\n " INPUT_TITLE_VAR "=<title> \ttitle number"
"\n " INPUT_CHAPTER_VAR "=<chapter> \tchapter number"
"\n " INPUT_ANGLE_VAR "=<angle> \tangle number"
"\n " INPUT_AUDIO_VAR "={ac3|lpcm|mpeg|off} \taudio type"
"\n " INPUT_CHANNEL_VAR "=[0-15] \taudio channel"
"\n " INPUT_SUBTITLE_VAR "=[0-31] \tsubtitle channel"
"\n " INPUT_DVDCSS_VAR "={csskey|disc|title} \tdvdcss method" );
/* Input parameters */
intf_MsgImm( "\nInput parameters:"
"\n " INPUT_SERVER_VAR "=<hostname> \tvideo server"
"\n " INPUT_PORT_VAR "=<port> \tvideo server port"
"\n " INPUT_IFACE_VAR "=<interface> \tnetwork interface"
"\n " INPUT_BCAST_ADDR_VAR "=<addr> \tbroadcast mode"
"\n " INPUT_CHANNEL_SERVER_VAR "=<hostname> \tchannel server"
"\n " INPUT_CHANNEL_PORT_VAR "=<port> \tchannel server port" );
"\n " INPUT_SERVER_VAR "=<hostname> \tvideo server"
"\n " INPUT_PORT_VAR "=<port> \tvideo server port"
"\n " INPUT_IFACE_VAR "=<interface> \tnetwork interface"
"\n " INPUT_BCAST_ADDR_VAR "=<addr> \tbroadcast mode"
"\n " INPUT_CHANNEL_SERVER_VAR "=<hostname> \tchannel server"
"\n " INPUT_CHANNEL_PORT_VAR "=<port> \tchannel server port" );
}