ref: 04675299a604238ec1d03cbfdb7e1067f2416c5d
parent: 03de9c0aca9a021f7c9137a530c22c39748acd5c
author: Sam Hocevar <[email protected]>
date: Sat Aug 10 10:27:26 EDT 2002
* ./src/dvdcss/dvdcss.h: marked deprecated stuff. * ./test/csstest.c: more documentation. see http://www.videolan.org/libdvdcss/doc/
--- a/src/css.c
+++ b/src/css.c
@@ -2,7 +2,7 @@
* css.c: Functions for DVD authentication and descrambling
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
- * $Id: css.c,v 1.13 2002/08/09 22:03:34 sam Exp $
+ * $Id: css.c,v 1.14 2002/08/10 14:27:26 sam Exp $
*
* Author: St�phane Borel <[email protected]>
* H�kan Hjort <[email protected]>
@@ -51,18 +51,18 @@
/*****************************************************************************
* Local prototypes
*****************************************************************************/
-static int GetBusKey ( dvdcss_handle );
-static int GetASF ( dvdcss_handle );
+static int GetBusKey ( dvdcss_t );
+static int GetASF ( dvdcss_t );
static void CryptKey ( int, int, u8 const *, u8 * );
static void DecryptKey ( u8, u8 const *, u8 const *, u8 * );
static int DecryptDiscKey ( u8 const *, dvd_key_t );
-static int CrackDiscKey ( dvdcss_handle, u8 * );
+static int CrackDiscKey ( dvdcss_t, u8 * );
static void DecryptTitleKey ( dvd_key_t, dvd_key_t );
static int RecoverTitleKey ( int, u8 const *, u8 const *, u8 const *, u8 * );
-static int CrackTitleKey ( dvdcss_handle, int, int, dvd_key_t );
+static int CrackTitleKey ( dvdcss_t, int, int, dvd_key_t );
static int AttackPattern ( u8 const[], int, u8 * );
#if 0
@@ -72,7 +72,7 @@
/*****************************************************************************
* _dvdcss_test: check if the disc is encrypted or not
*****************************************************************************/
-int _dvdcss_test( dvdcss_handle dvdcss )
+int _dvdcss_test( dvdcss_t dvdcss )
{
int i_ret, i_copyright;
@@ -107,7 +107,7 @@
* that ASF=1 from the start and then later fail with a 'read of scrambled
* block without authentication' error.
*****************************************************************************/
-static int GetBusKey( dvdcss_handle dvdcss )
+static int GetBusKey( dvdcss_t dvdcss )
{
u8 p_buffer[10];
u8 p_challenge[2*KEY_SIZE];
@@ -249,7 +249,7 @@
/*****************************************************************************
* PrintKey : debug function that dumps a key value
*****************************************************************************/
-static void PrintKey( dvdcss_handle dvdcss, char *prefix, u8 const *data )
+static void PrintKey( dvdcss_t dvdcss, char *prefix, u8 const *data )
{
char psz_output[80];
@@ -264,7 +264,7 @@
* This function should only be called by dvdcss_seek and should eventually
* not be external if possible.
*****************************************************************************/
-int _dvdcss_title ( dvdcss_handle dvdcss, int i_block )
+int _dvdcss_title ( dvdcss_t dvdcss, int i_block )
{
dvd_title_t *p_title;
dvd_title_t *p_newtitle;
@@ -351,7 +351,7 @@
* -disc key hash crack,
* -decryption with player keys if they are available.
*****************************************************************************/
-int _dvdcss_disckey( dvdcss_handle dvdcss )
+int _dvdcss_disckey( dvdcss_t dvdcss )
{
unsigned char p_buffer[2048];
dvd_key_t p_disc_key;
@@ -434,7 +434,7 @@
/*****************************************************************************
* _dvdcss_titlekey: get title key.
*****************************************************************************/
-int _dvdcss_titlekey( dvdcss_handle dvdcss, int i_pos, dvd_key_t p_title_key )
+int _dvdcss_titlekey( dvdcss_t dvdcss, int i_pos, dvd_key_t p_title_key )
{
static u8 p_garbage[ 2048 ]; /* static because we never read it */
u8 p_key[KEY_SIZE];
@@ -599,7 +599,7 @@
* 0 if the device needs to be authenticated,
* 1 either.
*****************************************************************************/
-static int GetASF( dvdcss_handle dvdcss )
+static int GetASF( dvdcss_t dvdcss )
{
int i_asf = 0;
@@ -998,7 +998,7 @@
return memcmp( key, ckey, KEY_SIZE );
}
-static int CrackDiscKey( dvdcss_handle dvdcss, u8 *p_disc_key )
+static int CrackDiscKey( dvdcss_t dvdcss, 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
@@ -1340,7 +1340,7 @@
* The DVD should have been opened and be in an authenticated state.
* i_pos is the starting sector, i_len is the maximum number of sectors to read
*****************************************************************************/
-static int CrackTitleKey( dvdcss_handle dvdcss, int i_pos, int i_len,
+static int CrackTitleKey( dvdcss_t dvdcss, int i_pos, int i_len,
dvd_key_t p_titlekey )
{
u8 p_buf[0x800];
--- a/src/css.h
+++ b/src/css.h
@@ -2,7 +2,7 @@
* css.h: Structures for DVD authentication and unscrambling
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
- * $Id: css.h,v 1.6 2002/08/09 14:10:43 sam Exp $
+ * $Id: css.h,v 1.7 2002/08/10 14:27:26 sam Exp $
*
* Author: St�phane Borel <[email protected]>
*
@@ -48,9 +48,9 @@
/*****************************************************************************
* Prototypes in css.c
*****************************************************************************/
-int _dvdcss_test ( dvdcss_handle );
-int _dvdcss_title ( dvdcss_handle, int );
-int _dvdcss_disckey ( dvdcss_handle );
-int _dvdcss_titlekey ( dvdcss_handle, int , dvd_key_t );
+int _dvdcss_test ( dvdcss_t );
+int _dvdcss_title ( dvdcss_t, int );
+int _dvdcss_disckey ( dvdcss_t );
+int _dvdcss_titlekey ( dvdcss_t, int , dvd_key_t );
int _dvdcss_unscramble ( u8 *, u8 * );
--- a/src/device.c
+++ b/src/device.c
@@ -2,7 +2,7 @@
* device.h: DVD device access
*****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
- * $Id: device.c,v 1.1 2002/08/09 14:10:43 sam Exp $
+ * $Id: device.c,v 1.2 2002/08/10 14:27:26 sam Exp $
*
* Authors: St�phane Borel <[email protected]>
* Samuel Hocevar <[email protected]>
@@ -100,7 +100,7 @@
}
#endif /* WIN32 */
-int _dvdcss_use_ioctls( dvdcss_handle dvdcss )
+int _dvdcss_use_ioctls( dvdcss_t dvdcss )
{
#if defined( WIN32 )
/* Some one need to implement this for Windows */
@@ -148,7 +148,7 @@
#endif
}
-int _dvdcss_open ( dvdcss_handle dvdcss )
+int _dvdcss_open ( dvdcss_t dvdcss )
{
char *psz_device = dvdcss->psz_device;
@@ -184,7 +184,7 @@
}
else
{
- dvdcss->i_fd = _win32_dvdcss_aopen( psz_device[0], dvdcss );
+ dvdcss->i_fd = _win32_dvdcss_aopen( dvdcss, psz_device[0] );
if( dvdcss->i_fd == -1 )
{
_dvdcss_error( dvdcss, "failed opening device" );
@@ -211,7 +211,7 @@
}
#ifndef WIN32
-int _dvdcss_raw_open ( dvdcss_handle dvdcss, char *psz_device )
+int _dvdcss_raw_open ( dvdcss_t dvdcss, char *psz_device )
{
dvdcss->i_raw_fd = open( psz_device, 0 );
@@ -229,7 +229,7 @@
}
#endif
-int _dvdcss_close ( dvdcss_handle dvdcss )
+int _dvdcss_close ( dvdcss_t dvdcss )
{
#if defined( WIN32 )
if( WIN2K )
@@ -263,7 +263,7 @@
return 0;
}
-int _dvdcss_seek ( dvdcss_handle dvdcss, int i_blocks )
+int _dvdcss_seek ( dvdcss_t dvdcss, int i_blocks )
{
#if defined( WIN32 )
dvdcss->i_seekpos = i_blocks;
@@ -312,7 +312,7 @@
}
-int _dvdcss_read ( dvdcss_handle dvdcss, void *p_buffer, int i_blocks )
+int _dvdcss_read ( dvdcss_t dvdcss, void *p_buffer, int i_blocks )
{
#if defined( WIN32 )
if( WIN2K )
@@ -349,7 +349,7 @@
}
-int _dvdcss_readv ( dvdcss_handle dvdcss, struct iovec *p_iovec, int i_blocks )
+int _dvdcss_readv ( dvdcss_t dvdcss, struct iovec *p_iovec, int i_blocks )
{
int i_read;
@@ -449,7 +449,7 @@
* _win32_dvdcss_aopen: open dvd drive (load aspi and init w32_aspidev
* structure)
*****************************************************************************/
-int _win32_dvdcss_aopen( char c_drive, dvdcss_handle dvdcss )
+int _win32_dvdcss_aopen( dvdcss_t dvdcss, char c_drive )
{
HMODULE hASPI;
DWORD dwSupportInfo;
--- a/src/device.h
+++ b/src/device.h
@@ -2,7 +2,7 @@
* device.h: DVD device access
*****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
- * $Id: device.h,v 1.1 2002/08/09 14:10:43 sam Exp $
+ * $Id: device.h,v 1.2 2002/08/10 14:27:26 sam Exp $
*
* Authors: St�phane Borel <[email protected]>
* Samuel Hocevar <[email protected]>
@@ -43,10 +43,10 @@
/*****************************************************************************
* Device reading prototypes
*****************************************************************************/
-int _dvdcss_use_ioctls ( dvdcss_handle );
-int _dvdcss_open ( dvdcss_handle );
-int _dvdcss_close ( dvdcss_handle );
-int _dvdcss_readv ( dvdcss_handle, struct iovec *, int );
+int _dvdcss_use_ioctls ( dvdcss_t );
+int _dvdcss_open ( dvdcss_t );
+int _dvdcss_close ( dvdcss_t );
+int _dvdcss_readv ( dvdcss_t, struct iovec *, int );
/*****************************************************************************
* Device reading prototypes, win32 specific
@@ -53,7 +53,7 @@
*****************************************************************************/
#ifdef WIN32
int _win32_dvdcss_readv ( int, struct iovec *, int, char * );
-int _win32_dvdcss_aopen ( char, dvdcss_handle );
+int _win32_dvdcss_aopen ( char, dvdcss_t );
int _win32_dvdcss_aclose ( int );
int _win32_dvdcss_aseek ( int, int, int );
int _win32_dvdcss_aread ( int, void *, int );
@@ -63,6 +63,6 @@
* Device reading prototypes, raw-device specific
*****************************************************************************/
#ifndef WIN32
-int _dvdcss_raw_open ( dvdcss_handle, char * );
+int _dvdcss_raw_open ( dvdcss_t, char * );
#endif
--- a/src/dvdcss/dvdcss.h
+++ b/src/dvdcss/dvdcss.h
@@ -10,7 +10,7 @@
/*
* Copyright (C) 1998-2002 VideoLAN
- * $Id: dvdcss.h,v 1.3 2002/08/10 12:21:28 sam Exp $
+ * $Id: dvdcss.h,v 1.4 2002/08/10 14:27:26 sam Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -37,7 +37,7 @@
#endif
/** Library instance handle, to be used for each library call. */
-typedef struct dvdcss_s* dvdcss_handle;
+typedef struct dvdcss_s* dvdcss_t;
/** The block size of a DVD. */
@@ -65,22 +65,30 @@
/*
* Exported prototypes.
*/
-extern dvdcss_handle dvdcss_open ( char *psz_target );
-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_flags );
-extern int dvdcss_read ( dvdcss_handle,
- void *p_buffer,
- int i_blocks,
- int i_flags );
-extern int dvdcss_readv ( dvdcss_handle,
- void *p_iovec,
- int i_blocks,
- int i_flags );
-extern char * dvdcss_error ( dvdcss_handle );
+extern dvdcss_t dvdcss_open ( char *psz_target );
+extern int dvdcss_close ( dvdcss_t );
+extern int dvdcss_seek ( dvdcss_t,
+ int i_blocks,
+ int i_flags );
+extern int dvdcss_read ( dvdcss_t,
+ void *p_buffer,
+ int i_blocks,
+ int i_flags );
+extern int dvdcss_readv ( dvdcss_t,
+ void *p_iovec,
+ int i_blocks,
+ int i_flags );
+extern char * dvdcss_error ( dvdcss_t );
+
+
+/*
+ * Deprecated stuff.
+ */
+#ifndef _DOXYGEN_SKIP_ME
+#define dvdcss_title(a,b) dvdcss_seek(a,b,DVDCSS_SEEK_KEY)
+#define dvdcss_handle dvdcss_t
+#endif
+
#ifdef __cplusplus
}
--- a/src/error.c
+++ b/src/error.c
@@ -2,7 +2,7 @@
* error.c: error management functions
*****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
- * $Id: error.c,v 1.1 2002/08/09 14:10:43 sam Exp $
+ * $Id: error.c,v 1.2 2002/08/10 14:27:26 sam Exp $
*
* Author: Samuel Hocevar <[email protected]>
*
@@ -34,7 +34,7 @@
/*****************************************************************************
* Error messages
*****************************************************************************/
-void _dvdcss_error( dvdcss_handle dvdcss, char *psz_string )
+void _dvdcss_error( dvdcss_t dvdcss, char *psz_string )
{
if( dvdcss->b_errors )
{
@@ -47,7 +47,7 @@
/*****************************************************************************
* Debug messages
*****************************************************************************/
-void _dvdcss_debug( dvdcss_handle dvdcss, char *psz_string )
+void _dvdcss_debug( dvdcss_t dvdcss, char *psz_string )
{
if( dvdcss->b_debug )
{
--- a/src/libdvdcss.c
+++ b/src/libdvdcss.c
@@ -5,7 +5,7 @@
* H�kan Hjort <[email protected]>
*
* Copyright (C) 1998-2002 VideoLAN
- * $Id: libdvdcss.c,v 1.16 2002/08/10 12:56:03 sam Exp $
+ * $Id: libdvdcss.c,v 1.17 2002/08/10 14:27:26 sam Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -33,16 +33,52 @@
* \li portability: currently supported platforms are GNU/Linux, FreeBSD,
* NetBSD, OpenBSD, BSD/OS, BeOS, Windows 95/98, Windows NT/2000, MacOS X,
* Solaris, HP-UX and OS/2.
+ * \li adaptability: unlike most similar projects, libdvdcss doesn't require
+ * the region of your drive to be set and will try its best to read from
+ * the disc even in the case of a region mismatch.
* \li simplicity: a DVD player can be built around the \e libdvdcss API using
* no more than 4 or 5 library calls.
- * \li freedom: \e libdvdcss is released under the General Public License,
- * ensuring it will stay free, and used only in free software.
- * \li just better: unlike most similar projects, libdvdcss doesn't require
- * the region of your drive to be set.
*
- * \section main How to use libdvdcss
+ * \e libdvdcss is free software, released under the General Public License.
+ * This ensures that \e libdvdcss remains free and used only with free
+ * software.
*
- * The \e libdvdcss API is documented in the dvdcss.h file.
+ * \section api The libdvdcss API
+ *
+ * The complete \e libdvdcss programming interface is documented in the
+ * dvdcss.h file.
+ *
+ * \section env Environment variables
+ *
+ * Some environment variables can be used to change the behaviour of
+ * \e libdvdcss without having to modify the program which uses it. These
+ * variables are:
+ *
+ * \li \b DVDCSS_VERBOSE: sets the verbosity level.
+ * - \c 0 outputs no messages at all.
+ * - \c 1 outputs error messages to stderr.
+ * - \c 2 outputs error messages and debug messages to stderr.
+ *
+ * \li \b DVDCSS_METHOD: sets the authentication and decryption method
+ * that \e libdvdcss will use to read scrambled discs. Can be one
+ * of \c title, \c key or \c disc.
+ * - \c key is the default method. \e libdvdcss will use a set of
+ * calculated player keys to try and get the disc key. This can fail
+ * if the drive does not recognize any of the player keys.
+ * - \c disc is a fallback method when \c key has failed. Instead of
+ * using player keys, \e libdvdcss will crack the disc key using
+ * a brute force algorithm. This process is CPU intensive and requires
+ * 64 MB of memory to store temporary data.
+ * - \c title is the fallback when all other methods have failed. It does
+ * not rely on a key exchange with the DVD drive, but rather uses a
+ * crypto attack to guess the title key. On rare cases this may fail
+ * because there is not enough encrypted data on the disc to perform
+ * a statistical attack, but in the other hand it is the only way to
+ * decrypt a DVD stored on a hard disc, or a DVD with the wrong region
+ * on an RPC2 drive.
+ *
+ * \li \b DVDCSS_RAW_DEVICE: specify the raw device to use.
+ *
*/
/*
@@ -95,7 +131,7 @@
* dvdcss_open() returns a handle to be used for all subsequent \e libdvdcss
* calls. If an error occured, NULL is returned.
*/
-extern dvdcss_handle dvdcss_open ( char *psz_target )
+extern dvdcss_t dvdcss_open ( char *psz_target )
{
int i_ret;
@@ -105,7 +141,7 @@
char *psz_raw_device = getenv( "DVDCSS_RAW_DEVICE" );
#endif
- dvdcss_handle dvdcss;
+ dvdcss_t dvdcss;
/*
* Allocate the library structure
@@ -239,7 +275,7 @@
* occured in \e libdvdcss. It can be used to format error messages at your
* convenience in your application.
*/
-extern char * dvdcss_error ( dvdcss_handle dvdcss )
+extern char * dvdcss_error ( dvdcss_t dvdcss )
{
return dvdcss->psz_error;
}
@@ -268,7 +304,7 @@
* deprecated dvdcss_title() call. This flag is typically used when seeking
* in a new title.
*/
-extern int dvdcss_seek ( dvdcss_handle dvdcss, int i_blocks, int i_flags )
+extern int dvdcss_seek ( dvdcss_t 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 )
@@ -286,21 +322,6 @@
}
/**
- * \brief Deprecated. See dvdcss_seek().
- */
-extern int dvdcss_title ( dvdcss_handle dvdcss, int i_block )
-{
- fprintf( stderr, "WARNING: dvdcss_title() is DEPRECATED, "
- "use dvdcss_seek() instead\n" );
- if( ! dvdcss->b_scrambled )
- {
- return 0;
- }
-
- return _dvdcss_title( dvdcss, i_block );
-}
-
-/**
* \brief Read from the disc and decrypt data if requested.
*
* \param dvdcss a \e libdvdcss instance.
@@ -323,9 +344,9 @@
* \warning dvdcss_read() expects to be able to write \p i_blocks *
* #DVDCSS_BLOCK_SIZE bytes in \p p_buffer.
*/
-extern int dvdcss_read ( dvdcss_handle dvdcss, void *p_buffer,
- int i_blocks,
- int i_flags )
+extern int dvdcss_read ( dvdcss_t dvdcss, void *p_buffer,
+ int i_blocks,
+ int i_flags )
{
int i_ret, i_index;
@@ -396,9 +417,9 @@
* Moreover, all iov_len members of the iovec structures should be
* multiples of #DVDCSS_BLOCK_SIZE.
*/
-extern int dvdcss_readv ( dvdcss_handle dvdcss, void *p_iovec,
- int i_blocks,
- int i_flags )
+extern int dvdcss_readv ( dvdcss_t dvdcss, void *p_iovec,
+ int i_blocks,
+ int i_flags )
{
struct iovec *_p_iovec = (struct iovec *)p_iovec;
int i_ret, i_index;
@@ -451,10 +472,10 @@
* \return zero in case of success, a negative value otherwise.
*
* This function closes the DVD device and frees all the memory allocated
- * by \e libdvdcss. On return, the #dvdcss_handle is invalidated and may not be
+ * by \e libdvdcss. On return, the #dvdcss_t is invalidated and may not be
* used again.
*/
-extern int dvdcss_close ( dvdcss_handle dvdcss )
+extern int dvdcss_close ( dvdcss_t dvdcss )
{
dvd_title_t *p_title;
int i_ret;
@@ -479,5 +500,21 @@
free( dvdcss );
return 0;
+}
+
+/*
+ * Deprecated. See dvdcss_seek().
+ */
+#undef dvdcss_title
+extern int dvdcss_title ( dvdcss_t dvdcss, int i_block )
+{
+ fprintf( stderr, "WARNING: dvdcss_title() is DEPRECATED, "
+ "use dvdcss_seek() instead\n" );
+ if( ! dvdcss->b_scrambled )
+ {
+ return 0;
+ }
+
+ return _dvdcss_title( dvdcss, i_block );
}
--- a/src/libdvdcss.h
+++ b/src/libdvdcss.h
@@ -2,7 +2,7 @@
* private.h: private DVD reading library data
*****************************************************************************
* Copyright (C) 1998-2001 VideoLAN
- * $Id: libdvdcss.h,v 1.3 2002/08/09 14:10:43 sam Exp $
+ * $Id: libdvdcss.h,v 1.4 2002/08/10 14:27:26 sam Exp $
*
* Authors: St�phane Borel <[email protected]>
* Samuel Hocevar <[email protected]>
@@ -65,9 +65,9 @@
/*****************************************************************************
* Functions used across the library
*****************************************************************************/
-int _dvdcss_seek ( dvdcss_handle, int );
-int _dvdcss_read ( dvdcss_handle, void *, int );
+int _dvdcss_seek ( dvdcss_t, int );
+int _dvdcss_read ( dvdcss_t, void *, int );
-void _dvdcss_error ( dvdcss_handle, char * );
-void _dvdcss_debug ( dvdcss_handle, char * );
+void _dvdcss_error ( dvdcss_t, char * );
+void _dvdcss_debug ( dvdcss_t, char * );
--- a/test/csstest.c
+++ b/test/csstest.c
@@ -11,15 +11,12 @@
#include <dvdcss/dvdcss.h>
-/* Macro to check if a sector is scrambled */
-#define IsSectorScrambled(buf) (((unsigned char*)(buf))[0x14] & 0x30)
+static int isscrambled( unsigned char * );
+static void dumpsector ( unsigned char * );
-/* Print parts of a 2048 bytes buffer */
-static void dumpsector( unsigned char * );
-
int main( int i_argc, char *ppsz_argv[] )
{
- dvdcss_handle dvdcss;
+ dvdcss_t dvdcss;
unsigned char p_buffer[ DVDCSS_BLOCK_SIZE ];
unsigned int i_sector;
int i_ret;
@@ -67,7 +64,7 @@
dumpsector( p_buffer );
/* Check if sector was encrypted */
- if( IsSectorScrambled( p_buffer ) )
+ if( isscrambled( p_buffer ) )
{
/* Set the file descriptor position to the previous location */
/* ... and get the appropriate key for this sector */
@@ -98,9 +95,15 @@
}
/* Close the device */
- dvdcss_close( dvdcss );
+ i_ret = dvdcss_close( dvdcss );
- return 0;
+ return i_ret;
+}
+
+/* Check if a sector is scrambled */
+static int isscrambled( unsigned char *p_buffer )
+{
+ return p_buffer[ 0x14 ] & 0x30;
}
/* Print parts of a 2048 bytes buffer */