Commit a50a0a25 authored by Sam Hocevar's avatar Sam Hocevar

  * libdvdcss enhancements by Billy Biggs <vektor@dumbterm.net>. This breaks
    vlc's DVD input (looks like decoders are expecting data too early and
    DVD input can't cope with it due to decryption). Needs to be investigated.
  * Plugins are now compiled in plugins/* and libraries in lib/*.
  * The KDE UI compiles again but does not work yet.
  * ALSA plugin message corrections.
  * Calculation modules can now be calledwith a shorter name
    (eg. '--downmix mmx' instead of '--downmix downmixmmx').
  * Fixed insane verbosity of the SDL plugin.
parent 96ab9e69
......@@ -21,9 +21,14 @@ D: directory browsing code in modules.c
N: Gildas Bazin
E: gbazin@netcourrier.com
C: gbazin
D: mingw32 port, various win32 fixes
D: DirectX audio and video output
N: Billy Biggs
E: vektor@dumbterm.net
D: libdvdcss enhancements
N: Stphane Borel
E: stef@via.ecp.fr
C: stef
......
......@@ -11,12 +11,12 @@
#
# All possible plugin directories, needed for make clean
#
PLUGINS_DIR := alsa beos darwin directx dsp dummy dvd esd fb ggi glide gtk downmix idct imdct macosx mga motion mpeg qt sdl text x11 yuv
PLUGINS_DIR := alsa beos darwin directx dsp dummy dvd esd fb ggi glide gtk downmix idct imdct kde macosx mga motion mpeg qt sdl text x11 yuv
#
# All possible plugin objects
#
PLUGINS_TARGETS := alsa/alsa beos/beos darwin/darwin directx/directx dsp/dsp dummy/dummy dummy/null dvd/dvd esd/esd fb/fb ggi/ggi glide/glide gtk/gnome gtk/gtk downmix/downmix downmix/downmixsse downmix/downmix3dn idct/idct idct/idctclassic idct/idctmmx idct/idctmmxext imdct/imdct imdct/imdct3dn imdct/imdctsse macosx/macosx mga/mga motion/motion motion/motionmmx motion/motionmmxext mpeg/es mpeg/ps mpeg/ts qt/qt sdl/sdl text/ncurses text/rc x11/x11 x11/xvideo yuv/yuv yuv/yuvmmx
PLUGINS_TARGETS := alsa/alsa beos/beos darwin/darwin directx/directx dsp/dsp dummy/dummy dummy/null dvd/dvd esd/esd fb/fb ggi/ggi glide/glide gtk/gnome gtk/gtk downmix/downmix downmix/downmixsse downmix/downmix3dn idct/idct idct/idctclassic idct/idctmmx idct/idctmmxext imdct/imdct imdct/imdct3dn imdct/imdctsse kde/kde macosx/macosx mga/mga motion/motion motion/motionmmx motion/motionmmxext mpeg/es mpeg/ps mpeg/ts qt/qt sdl/sdl text/ncurses text/rc x11/x11 x11/xvideo yuv/yuv yuv/yuvmmx
#
# C Objects
......@@ -83,10 +83,10 @@ CPP_DEP := $(CPP_OBJ:%.o=.dep/%.dpp)
# Translate plugin names
#
ifneq (,$(PLUGINS))
PLUGIN_OBJ := $(shell for i in $(PLUGINS) ; do echo " "$(PLUGINS_TARGETS)" " | sed -e 's@.*/\('$$i'\) .*@lib/\1.so@' -e 's@^ .*@@' ; done)
PLUGIN_OBJ := $(shell for i in $(PLUGINS) ; do echo " "$(PLUGINS_TARGETS)" " | sed -e 's@.*/\('$$i'\) .*@plugins/\1.so@' -e 's@^ .*@@' ; done)
endif
ifneq (,$(BUILTINS))
BUILTIN_OBJ := $(shell for i in $(BUILTINS) ; do echo " "$(PLUGINS_TARGETS)" " | sed -e 's@.*/\('$$i'\) .*@lib/\1.a@' -e 's@^ .*@@' ; done)
BUILTIN_OBJ := $(shell for i in $(BUILTINS) ; do echo " "$(PLUGINS_TARGETS)" " | sed -e 's@.*/\('$$i'\) .*@plugins/\1.a@' -e 's@^ .*@@' ; done)
endif
# All symbols must be exported
......@@ -104,6 +104,7 @@ all: vlc ${ALIASES} plugins vlc.app
clean: libdvdcss-clean plugins-clean vlc-clean
rm -f src/*/*.o extras/*/*.o
rm -f lib/*.so lib/*.so.* lib/*.a
rm -f plugins/*.so plugins/*.so.* plugins/*.a
libdvdcss-clean:
cd extras/libdvdcss && $(MAKE) clean
......@@ -144,7 +145,7 @@ endif
plugins-install:
mkdir -p $(DESTDIR)$(libdir)/videolan/vlc
ifneq (,$(PLUGINS))
$(INSTALL) -m 644 $(PLUGINS:%=lib/%.so) $(DESTDIR)$(libdir)/videolan/vlc
$(INSTALL) -m 644 $(PLUGINS:%=plugins/%.so) $(DESTDIR)$(libdir)/videolan/vlc
endif
libdvdcss-install:
......@@ -270,7 +271,7 @@ ifneq (,$(findstring darwin,$(SYS)))
$(INSTALL) vlc vlc.app/Contents/MacOS/
$(INSTALL) share/vlc.icns vlc.app/Contents/Resources/
ifneq (,$(PLUGINS))
$(INSTALL) $(PLUGINS:%=lib/%.so) vlc.app/Contents/MacOS/lib
$(INSTALL) $(PLUGINS:%=plugins/%.so) vlc.app/Contents/MacOS/plugins
endif
$(INSTALL) -m 644 share/*.psf vlc.app/Contents/MacOS/share
endif
......@@ -343,14 +344,14 @@ endif
#
plugins: Makefile.modules Makefile.opts Makefile.dep Makefile $(PLUGIN_OBJ)
$(PLUGIN_OBJ): FORCE
cd $(shell echo " "$(PLUGINS_TARGETS)" " | sed -e 's@.* \([^/]*/\)'$(@:lib/%.so=%)' .*@plugins/\1@' -e 's@^ .*@@') && $(MAKE) $(@:%=../../%)
cd $(shell echo " "$(PLUGINS_TARGETS)" " | sed -e 's@.* \([^/]*/\)'$(@:plugins/%.so=%)' .*@plugins/\1@' -e 's@^ .*@@') && $(MAKE) $(@:%=../../%)
#
# Built-in modules target
#
builtins: Makefile.modules Makefile.opts Makefile.dep Makefile $(BUILTIN_OBJ)
$(BUILTIN_OBJ): FORCE
cd $(shell echo " "$(PLUGINS_TARGETS)" " | sed -e 's@.* \([^/]*/\)'$(@:lib/%.a=%)' .*@plugins/\1@' -e 's@^ .*@@') && $(MAKE) $(@:%=../../%)
cd $(shell echo " "$(PLUGINS_TARGETS)" " | sed -e 's@.* \([^/]*/\)'$(@:plugins/%.a=%)' .*@plugins/\1@' -e 's@^ .*@@') && $(MAKE) $(@:%=../../%)
#
# libdvdcss target
......
......@@ -72,6 +72,7 @@ LIB_GLIDE = @LIB_GLIDE@
LIB_GNOME = @LIB_GNOME@
LIB_GTK = @LIB_GTK@
LIB_IDCTALTIVEC = @LIB_IDCTALTIVEC@
LIB_KDE = @LIB_KDE@
LIB_MACOSX = @LIB_MACOSX@
LIB_NCURSES = @LIB_NCURSES@
LIB_QT = @LIB_QT@
......
......@@ -4208,7 +4208,11 @@ fi
# Check whether --enable-kde or --disable-kde was given.
if test "${enable_kde+set}" = set; then
enableval="$enable_kde"
if test x$enable_kde = xyes; then PLUGINS="${PLUGINS} kde"; ALIASES="${ALIASES} kvlc"; fi
if test x$enable_kde = xyes; then
PLUGINS="${PLUGINS} kde";
ALIASES="${ALIASES} kvlc";
LIB_KDE="-lkfile"
fi
fi
......@@ -4233,7 +4237,7 @@ if test x$enable_gtk != xno; then
# Extract the first word of "gtk-config", so it can be a program name with args.
set dummy gtk-config; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
echo "configure:4237: checking for $ac_word" >&5
echo "configure:4241: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_path_GTK_CONFIG'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
......@@ -4293,17 +4297,17 @@ if test x$enable_x11 != xno; then
do
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
echo "configure:4297: checking for $ac_hdr" >&5
echo "configure:4301: checking for $ac_hdr" >&5
if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 4302 "configure"
#line 4306 "configure"
#include "confdefs.h"
#include <$ac_hdr>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
{ (eval echo configure:4307: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
{ (eval echo configure:4311: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
rm -rf conftest*
......@@ -4355,17 +4359,17 @@ if test x$enable_xvideo != xno; then
do
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
echo "configure:4359: checking for $ac_hdr" >&5
echo "configure:4363: checking for $ac_hdr" >&5
if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 4364 "configure"
#line 4368 "configure"
#include "confdefs.h"
#include <$ac_hdr>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
{ (eval echo configure:4369: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
{ (eval echo configure:4373: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
rm -rf conftest*
......@@ -4403,17 +4407,17 @@ if test "${enable_alsa+set}" = set; then
enableval="$enable_alsa"
if test x$enable_alsa = xyes; then ac_safe=`echo "sys/asoundlib.h" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for sys/asoundlib.h""... $ac_c" 1>&6
echo "configure:4407: checking for sys/asoundlib.h" >&5
echo "configure:4411: checking for sys/asoundlib.h" >&5
if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 4412 "configure"
#line 4416 "configure"
#include "confdefs.h"
#include <sys/asoundlib.h>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
{ (eval echo configure:4417: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
{ (eval echo configure:4421: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
rm -rf conftest*
......@@ -4430,7 +4434,7 @@ fi
if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
echo "$ac_t""yes" 1>&6
echo $ac_n "checking for main in -lasound""... $ac_c" 1>&6
echo "configure:4434: checking for main in -lasound" >&5
echo "configure:4438: checking for main in -lasound" >&5
ac_lib_var=`echo asound'_'main | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
......@@ -4438,14 +4442,14 @@ else
ac_save_LIBS="$LIBS"
LIBS="-lasound $LIBS"
cat > conftest.$ac_ext <<EOF
#line 4442 "configure"
#line 4446 "configure"
#include "confdefs.h"
int main() {
main()
; return 0; }
EOF
if { (eval echo configure:4449: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
if { (eval echo configure:4453: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
......@@ -4526,6 +4530,7 @@ fi
trap '' 1 2 15
......@@ -4708,6 +4713,7 @@ s%@LIB_GLIDE@%$LIB_GLIDE%g
s%@LIB_GNOME@%$LIB_GNOME%g
s%@LIB_GTK@%$LIB_GTK%g
s%@LIB_IDCTALTIVEC@%$LIB_IDCTALTIVEC%g
s%@LIB_KDE@%$LIB_KDE%g
s%@LIB_MACOSX@%$LIB_MACOSX%g
s%@LIB_NCURSES@%$LIB_NCURSES%g
s%@LIB_QT@%$LIB_QT%g
......
......@@ -531,7 +531,11 @@ dnl KDE module
dnl
AC_ARG_ENABLE(kde,
[ --enable-kde KDE interface support (default disabled)],
[if test x$enable_kde = xyes; then PLUGINS="${PLUGINS} kde"; ALIASES="${ALIASES} kvlc"; fi])
[if test x$enable_kde = xyes; then
PLUGINS="${PLUGINS} kde";
ALIASES="${ALIASES} kvlc";
LIB_KDE="-lkfile"
fi])
dnl
dnl Gnome module
......@@ -650,6 +654,7 @@ AC_SUBST(LIB_GLIDE)
AC_SUBST(LIB_GNOME)
AC_SUBST(LIB_GTK)
AC_SUBST(LIB_IDCTALTIVEC)
AC_SUBST(LIB_KDE)
AC_SUBST(LIB_MACOSX)
AC_SUBST(LIB_NCURSES)
AC_SUBST(LIB_QT)
......
......@@ -2,7 +2,7 @@
* css.c: Functions for DVD authentification and unscrambling
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
* $Id: css.c,v 1.4 2001/07/07 21:10:58 gbazin Exp $
* $Id: css.c,v 1.5 2001/07/11 02:01:03 sam Exp $
*
* Author: Stphane Borel <stef@via.ecp.fr>
*
......@@ -56,7 +56,7 @@
#ifdef HAVE_CSS
static int CSSGetASF ( dvdcss_handle dvdcss );
static void CSSCryptKey ( int i_key_type, int i_varient,
u8 const * pi_challenge, u8* pi_key );
u8 const * p_challenge, u8* p_key );
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 );
......@@ -94,7 +94,7 @@ int CSSInit( dvdcss_handle dvdcss )
{
#ifdef HAVE_CSS
/* structures defined in cdrom.h or dvdio.h */
char p_buffer[2048 + 4 + 1];
unsigned char p_buffer[2048 + 4 + 1];
char psz_warning[32];
int i_agid = 0;
int i_ret = -1;
......@@ -143,13 +143,13 @@ int CSSInit( dvdcss_handle dvdcss )
for( i = 0 ; i < 10; ++i )
{
dvdcss->css.disc.pi_challenge[i] = i;
dvdcss->css.disc.p_challenge[i] = i;
}
/* Get challenge from host */
for( i = 0 ; i < 10 ; ++i )
{
p_buffer[9-i] = dvdcss->css.disc.pi_challenge[i];
p_buffer[9-i] = dvdcss->css.disc.p_challenge[i];
}
/* Send challenge to LU */
......@@ -169,16 +169,16 @@ int CSSInit( dvdcss_handle dvdcss )
/* Send key1 to host */
for( i = 0 ; i < KEY_SIZE ; i++ )
{
dvdcss->css.disc.pi_key1[i] = p_buffer[4-i];
dvdcss->css.disc.p_key1[i] = p_buffer[4-i];
}
for( i = 0 ; i < 32 ; ++i )
{
CSSCryptKey( 0, i, dvdcss->css.disc.pi_challenge,
dvdcss->css.disc.pi_key_check );
CSSCryptKey( 0, i, dvdcss->css.disc.p_challenge,
dvdcss->css.disc.p_key_check );
if( memcmp( dvdcss->css.disc.pi_key_check,
dvdcss->css.disc.pi_key1, KEY_SIZE ) == 0 )
if( memcmp( dvdcss->css.disc.p_key_check,
dvdcss->css.disc.p_key1, KEY_SIZE ) == 0 )
{
sprintf( psz_warning, "drive authentic, using variant %d", i );
_dvdcss_debug( dvdcss, psz_warning );
......@@ -203,17 +203,17 @@ int CSSInit( dvdcss_handle dvdcss )
/* Send challenge to host */
for( i = 0 ; i < 10 ; ++i )
{
dvdcss->css.disc.pi_challenge[i] = p_buffer[9-i];
dvdcss->css.disc.p_challenge[i] = p_buffer[9-i];
}
CSSCryptKey( 1, dvdcss->css.disc.i_varient,
dvdcss->css.disc.pi_challenge,
dvdcss->css.disc.pi_key2 );
dvdcss->css.disc.p_challenge,
dvdcss->css.disc.p_key2 );
/* Get key2 from host */
for( i = 0 ; i < KEY_SIZE ; ++i )
{
p_buffer[4-i] = dvdcss->css.disc.pi_key2[i];
p_buffer[4-i] = dvdcss->css.disc.p_key2[i];
}
/* Send key2 to LU */
......@@ -225,14 +225,14 @@ int CSSInit( dvdcss_handle dvdcss )
_dvdcss_debug( dvdcss, "authentication established" );
memcpy( dvdcss->css.disc.pi_challenge,
dvdcss->css.disc.pi_key1, KEY_SIZE );
memcpy( dvdcss->css.disc.pi_challenge+KEY_SIZE,
dvdcss->css.disc.pi_key2, KEY_SIZE );
memcpy( dvdcss->css.disc.p_challenge,
dvdcss->css.disc.p_key1, KEY_SIZE );
memcpy( dvdcss->css.disc.p_challenge+KEY_SIZE,
dvdcss->css.disc.p_key2, KEY_SIZE );
CSSCryptKey( 2, dvdcss->css.disc.i_varient,
dvdcss->css.disc.pi_challenge,
dvdcss->css.disc.pi_key_check );
dvdcss->css.disc.p_challenge,
dvdcss->css.disc.p_key_check );
_dvdcss_debug( dvdcss, "received session key" );
......@@ -267,15 +267,9 @@ fprintf( stderr, "DISK KEY: %02x %02x %02x %02x %02x\n", p_buffer[0], p_buffer[1
/* Unencrypt disc key using bus key */
for( i = 0 ; i < 2048 ; i++ )
{
p_buffer[ i ] ^= dvdcss->css.disc.pi_key_check[ 4 - (i % KEY_SIZE) ];
}
memcpy( dvdcss->css.disc.pi_key_check, p_buffer, 2048 );
/* initialize title key to know it empty */
for( i = 0 ; i < KEY_SIZE ; i++ )
{
dvdcss->css.pi_title_key[i] = 0;
p_buffer[ i ] ^= dvdcss->css.disc.p_key_check[ 4 - (i % KEY_SIZE) ];
}
memcpy( dvdcss->css.disc.p_key_check, p_buffer, 2048 );
/* Test authentication success */
switch( CSSGetASF( dvdcss ) )
......@@ -305,7 +299,7 @@ fprintf( stderr, "DISK KEY: %02x %02x %02x %02x %02x\n", p_buffer[0], p_buffer[1
*****************************************************************************
* The DVD should have been opened and authenticated before.
*****************************************************************************/
int CSSGetKey( dvdcss_handle dvdcss )
int CSSGetKey( dvdcss_handle dvdcss, int i_pos, dvd_key_t p_titlekey )
{
#ifdef HAVE_CSS
/*
......@@ -313,9 +307,8 @@ int CSSGetKey( dvdcss_handle dvdcss )
* with Frank A. Stevenson algorithm.
* Does not use any player key table and ioctls.
*/
u8 pi_buf[0x800];
dvd_key_t pi_key;
int i_pos;
u8 p_buf[0x800];
dvd_key_t p_key;
boolean_t b_encrypted;
boolean_t b_stop_scanning;
int i_blocks_read;
......@@ -325,63 +318,62 @@ int CSSGetKey( dvdcss_handle dvdcss )
for( i = 0 ; i < KEY_SIZE ; i++ )
{
pi_key[i] = 0;
p_key[i] = 0;
}
b_encrypted = 0;
b_stop_scanning = 0;
/* Position of the title on the disc */
i_pos = dvdcss->css.i_title_pos;
do {
i_pos = dvdcss_seek( dvdcss, i_pos );
i_blocks_read = dvdcss_read( dvdcss, pi_buf, 1, DVDCSS_NOFLAGS );
/* PES_scrambling_control */
if( pi_buf[0x14] & 0x30 )
do
{
b_encrypted = 1;
i_best_plen = 0;
i_best_p = 0;
i_pos = dvdcss_seek( dvdcss, i_pos );
i_blocks_read = dvdcss_read( dvdcss, p_buf, 1, DVDCSS_NOFLAGS );
for( i = 2 ; i < 0x30 ; i++ )
/* PES_scrambling_control */
if( p_buf[0x14] & 0x30 )
{
for( j = i+1 ; ( j < 0x80 ) &&
( pi_buf[0x7F - (j%i)] == pi_buf[0x7F-j] ) ; j++ );
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 = CSSCracker( 0, &pi_buf[0x80],
&pi_buf[0x80 - ( i_best_plen / i_best_p) *i_best_p],
(dvd_key_t*)&pi_buf[0x54],
&pi_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 += i_blocks_read;
} while( i_blocks_read == 0x1 && !b_stop_scanning);
i_pos += i_blocks_read;
} while( i_blocks_read == 0x1 && !b_stop_scanning );
if( b_stop_scanning)
if( b_stop_scanning )
{
memcpy( dvdcss->css.pi_title_key,
&pi_key, sizeof(dvd_key_t) );
memcpy( p_titlekey, &p_key, sizeof(dvd_key_t) );
_dvdcss_debug( dvdcss, "vts key initialized" );
return 0;
}
if( !b_encrypted )
{
_dvdcss_debug( dvdcss, "this file was _NOT_ encrypted!" );
_dvdcss_debug( dvdcss, "file was unscrambled" );
return 0;
}
......@@ -400,38 +392,38 @@ int CSSGetKey( dvdcss_handle dvdcss )
* sec : sector to descramble
* key : title key for this sector
*****************************************************************************/
int CSSDescrambleSector( dvd_key_t pi_key, u8* pi_sec )
int CSSDescrambleSector( dvd_key_t p_key, u8* p_sec )
{
#ifdef HAVE_CSS
unsigned int i_t1, i_t2, i_t3, i_t4, i_t5, i_t6;
u8* pi_end = pi_sec + 0x800;
u8* p_end = p_sec + 0x800;
/* PES_scrambling_control */
if( pi_sec[0x14] & 0x30)
if( p_sec[0x14] & 0x30)
{
i_t1 = ((pi_key)[0] ^ pi_sec[0x54]) | 0x100;
i_t2 = (pi_key)[1] ^ pi_sec[0x55];
i_t3 = (((pi_key)[2]) | ((pi_key)[3] << 8) |
((pi_key)[4] << 16)) ^ ((pi_sec[0x56]) |
(pi_sec[0x57] << 8) | (pi_sec[0x58] << 16));
i_t1 = ((p_key)[0] ^ p_sec[0x54]) | 0x100;
i_t2 = (p_key)[1] ^ p_sec[0x55];
i_t3 = (((p_key)[2]) | ((p_key)[3] << 8) |
((p_key)[4] << 16)) ^ ((p_sec[0x56]) |
(p_sec[0x57] << 8) | (p_sec[0x58] << 16));
i_t4 = i_t3 & 7;
i_t3 = i_t3 * 2 + 8 - i_t4;
pi_sec += 0x80;
p_sec += 0x80;
i_t5 = 0;
while( pi_sec != pi_end )
while( p_sec != p_end )
{
i_t4 = pi_css_tab2[i_t2] ^ pi_css_tab3[i_t1];
i_t4 = p_css_tab2[i_t2] ^ p_css_tab3[i_t1];
i_t2 = i_t1>>1;
i_t1 = ( ( i_t1 & 1 ) << 8 ) ^ i_t4;
i_t4 = pi_css_tab5[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 = (i_t3 << 8 ) | i_t6;
i_t6 = pi_css_tab4[i_t6];
i_t6 = p_css_tab4[i_t6];
i_t5 += i_t6 + i_t4;
*pi_sec = pi_css_tab1[*pi_sec] ^( i_t5 & 0xff );
pi_sec++;
*p_sec = p_css_tab1[*p_sec] ^( i_t5 & 0xff );
p_sec++;
i_t5 >>= 8;
}
}
......@@ -491,16 +483,16 @@ static int CSSGetASF( dvdcss_handle dvdcss )
* i_varient : between 0 and 31.
*****************************************************************************/
static void CSSCryptKey( int i_key_type, int i_varient,
u8 const * pi_challenge, u8* pi_key )
u8 const * p_challenge, u8* p_key )
{
/* Permutation table for challenge */
u8 ppi_perm_challenge[3][10] =
u8 pp_perm_challenge[3][10] =
{ { 1, 3, 0, 7, 5, 2, 9, 6, 4, 8 },
{ 6, 1, 9, 3, 8, 5, 7, 4, 0, 2 },
{ 4, 0, 3, 5, 7, 2, 8, 6, 1, 9 } };
/* Permutation table for varient table for key2 and buskey */
u8 ppi_perm_varient[2][32] =
u8 pp_perm_varient[2][32] =
{ { 0x0a, 0x08, 0x0e, 0x0c, 0x0b, 0x09, 0x0f, 0x0d,
0x1a, 0x18, 0x1e, 0x1c, 0x1b, 0x19, 0x1f, 0x1d,
0x02, 0x00, 0x06, 0x04, 0x03, 0x01, 0x07, 0x05,
......@@ -510,19 +502,19 @@ static void CSSCryptKey( int i_key_type, int i_varient,
0x13, 0x1b, 0x17, 0x1f, 0x03, 0x0b, 0x07, 0x0f,
0x11, 0x19, 0x15, 0x1d, 0x01, 0x09, 0x05, 0x0d } };
u8 pi_varients[32] =
u8 p_varients[32] =
{ 0xB7, 0x74, 0x85, 0xD0, 0xCC, 0xDB, 0xCA, 0x73,
0x03, 0xFE, 0x31, 0x03, 0x52, 0xE0, 0xB7, 0x42,
0x63, 0x16, 0xF2, 0x2A, 0x79, 0x52, 0xFF, 0x1B,
0x7A, 0x11, 0xCA, 0x1A, 0x9B, 0x40, 0xAD, 0x01 };
/* The "secret" key */
u8 pi_secret[5] = { 0x55, 0xD6, 0xC4, 0xC5, 0x28 };
u8 p_secret[5] = { 0x55, 0xD6, 0xC4, 0xC5, 0x28 };
u8 pi_bits[30];
u8 pi_scratch[10];
u8 pi_tmp1[5];
u8 pi_tmp2[5];
u8 p_bits[30];
u8 p_scratch[10];
u8 p_tmp1[5];
u8 p_tmp2[5];
u8 i_lfsr0_o; /* 1 bit used */
u8 i_lfsr1_o; /* 1 bit used */
u32 i_lfsr0;
......@@ -538,10 +530,10 @@ static void CSSCryptKey( int i_key_type, int i_varient,
int i;
for (i = 9; i >= 0; --i)
pi_scratch[i] = pi_challenge[ppi_perm_challenge[i_key_type][i]];
p_scratch[i] = p_challenge[pp_perm_challenge[i_key_type][i]];
i_css_varient = ( i_key_type == 0 ) ? i_varient :
ppi_perm_varient[i_key_type-1][i_varient];
pp_perm_varient[i_key_type-1][i_varient];
/*
* This encryption engine implements one of 32 variations
......@@ -562,7 +554,7 @@ static void CSSCryptKey( int i_key_type, int i_varient,
*/
for( i = 5 ; --i >= 0 ; )
{
pi_tmp1[i] = pi_scratch[5 + i] ^ pi_secret[i] ^ pi_crypt_tab2[i];
p_tmp1[i] = p_scratch[5 + i] ^ p_secret[i] ^ p_crypt_tab2[i];
}
/*
......@@ -592,11 +584,11 @@ static void CSSCryptKey( int i_key_type, int i_varient,
* initial values are non-zero. Thus when we initialise them from
* the seed, we ensure that a bit is set.
*/
i_lfsr0 = ( pi_tmp1[0] << 17 ) | ( pi_tmp1[1] << 9 ) |
(( pi_tmp1[2] & ~7 ) << 1 ) | 8 | ( pi_tmp1[2] & 7 );
i_lfsr1 = ( pi_tmp1[3] << 9 ) | 0x100 | pi_tmp1[4];
i_lfsr0 = ( p_tmp1[0] << 17 ) | ( p_tmp1[1] << 9 ) |
(( p_tmp1[2] & ~7 ) << 1 ) | 8 | ( p_tmp1[2] & 7 );
i_lfsr1 = ( p_tmp1[3] << 9 ) | 0x100 | p_tmp1[4];
i_index = sizeof(pi_bits);
i_index = sizeof(p_bits);
i_carry = 0;
do
......@@ -617,74 +609,74 @@ static void CSSCryptKey( int i_key_type, int i_varient,
i_val |= ( i_combined & 1 ) << i_bit;
}