/*****************************************************************************
* css.c: Functions for DVD authentication and descrambling
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
* $Id$
*
* Author: Stéphane Borel <stef@via.ecp.fr>
* Håkan Hjort <d95hjort@dtek.chalmers.se>
*
* based on:
* - css-auth by Derek Fawcus <derek@spider.com>
* - DVD CSS ioctls example program by Andrew T. Veliath <andrewtv@usa.net>
* - The Divide and conquer attack by Frank A. Stevenson <frank@funcom.com>
* - DeCSSPlus by Ethan Hawke
* - DecVOB
* see http://www.lemuria.org/DeCSS/ by Tom Vogt for more information.
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dvdcss/dvdcss.h"
#include "common.h"
#include "css.h"
#include "libdvdcss.h"
#include "csstables.h"
#include "ioctl.h"
#include "device.h"
/*****************************************************************************
* Local prototypes
*****************************************************************************/
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_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_t, int, int, dvd_key_t );
static int AttackPattern ( u8 const[], int, u8 * );
#if 0
static int AttackPadding ( u8 const[], int, u8 * );
#endif
/*****************************************************************************
* _dvdcss_test: check if the disc is encrypted or not
*****************************************************************************/
int _dvdcss_test( dvdcss_t dvdcss )
{
int i_ret, i_copyright;
i_ret = ioctl_ReadCopyright( dvdcss->i_fd, 0 /* i_layer */, &i_copyright );
if( i_ret < 0 )
{
/* Since it's the first ioctl we try to issue, we add a notice */
_dvdcss_error( dvdcss, "css error: ioctl_ReadCopyright failed, "
"make sure there is a DVD in the drive, and that "
"you have used the correct device node."
#if defined( WIN32 )
"\nAlso note that if you are using Windows NT/2000/XP "
"you need to have administrator priviledges to be able "
"to use ioctls."
#endif
);
return i_ret;
}
return i_copyright;
}
/*****************************************************************************
* GetBusKey : Go through the CSS Authentication process
*****************************************************************************
* It simulates the mutual authentication between logical unit and host,
* and stops when a session key (called bus key) has been established.
* Always do the full auth sequence. Some drives seem to lie and always
* respond with ASF=1. For instance the old DVD roms on Compaq Armada says
* that ASF=1 from the start and then later fail with a 'read of scrambled
* block without authentication' error.
*****************************************************************************/
static int GetBusKey( dvdcss_t dvdcss )
{
u8 p_buffer[10];
u8 p_challenge[2*KEY_SIZE];
dvd_key_t p_key1;
dvd_key_t p_key2;
dvd_key_t p_key_check;
u8 i_variant = 0;
char psz_warning[80];
int i_ret = -1;
int i;
_dvdcss_debug( dvdcss, "requesting AGID" );
i_ret = ioctl_ReportAgid( dvdcss->i_fd, &dvdcss->css.i_agid );
/* We might have to reset hung authenticati
|