📄 css.cpp
字号:
/*****************************************************************************
******************************************************************************
** **
** Copyright (c) 2002 Videon Central, Inc. **
** All rights reserved. **
** **
** The computer program contained herein contains proprietary information **
** which is the property of Videon Central, Inc. The program may be used **
** and/or copied only with the written permission of Videon Central, Inc. **
** or in accordance with the terms and conditions stipulated in the **
** agreement/contract under which the programs have been supplied. **
** **
******************************************************************************
*****************************************************************************/
/**
* @file css.cpp
*
* DVD disc access module.
*
* $Revision: 1.8 $
*
*/
#include "vdvd_types.h"
#include "loader_app.h"
#include "dbgprint.h"
#include "css.h"
#include "chipcss.h"
#ifdef DMALLOC
#include "dmalloc.h"
#endif
#define CSS_KEY_SIZE 5
#define DEBUG_CSS 0
BYTE bAgid = 0;
/************************************************************************/
/************************************************************************/
/** **/
/************************************************************************/
/************************************************************************/
static CSS_ERROR CSSAuthenticate( LOADER_HANDLE tDev )
{
BYTE ChallengeData[10];
BYTE Key1Data[5];
BYTE Key2Data[5];
BYTE DVDChallData[10];
BYTE bASF;
#if DEBUG_CSS
int i;
#endif
/* verify input */
DbgAssert(tDev);
//*********************************************//
//** 4.3 Authentication Management Procedure **//
//*********************************************//
//4.3.1 Start of Authentication Management in DVD-ROM drive
bAgid = 0;
if (LoaderGetAgid(tDev, &bAgid) != LOADER_SUCCESS)
{
DbgPrint(( "CSSAuthenticate:can not get AGID\n" ));
return( CSS_FAILURE );
}
#if DEBUG_CSS
DbgPrint((" AGID = %d\n", bAgid));
#endif
if (LoaderGetASF(tDev, bAgid, &bASF) != LOADER_SUCCESS)
{
DbgPrint(( " *** ERROR, CANNOT VERIFY DISK KEY STRUCTURE\n" ));
return( CSS_FAILURE );
}
#if DEBUG_CSS
DbgPrint((" ASF = %d\n", bASF));
#endif
//4.3.2 Generate Challenge Data in DVD decoder board
if (CHIPCSSGetChallenge( ChallengeData ) == CHIPCSS_FAILURE)
{
DbgPrint(( " *** ERROR, CANNOT READ CHALLENGE DATA FROM CHIP\n" ));
return( CSS_FAILURE );
}
#if DEBUG_CSS
DbgPrint(( " ChallengeData[] =" ));
for (i=0; i<sizeof(ChallengeData); i++)
{
DbgPrint(( " %02x", ChallengeData[i] ));
}
DbgPrint(( "\n" ));
#endif
//4.3.3.1 Send Challenge Data to the DVD-ROM drive
if (LoaderSendChallenge(tDev, bAgid, ChallengeData) != LOADER_SUCCESS)
{
DbgPrint(( " *** ERROR, CANNOT WRITE DVD CHALLENGE DATA\n" ));
return( CSS_FAILURE );
}
//4.3.3.2 Acquire Key1 fron DVD-ROM drive
if (LoaderGetKey1(tDev, bAgid, Key1Data) != LOADER_SUCCESS)
{
DbgPrint(( " *** ERROR, CANNOT READ KEY1 FROM DVD-ROM\n" ));
return( CSS_FAILURE );
}
#if DEBUG_CSS
DbgPrint(( " Key1Data[] =" ));
for (i=0; i<sizeof(Key1Data); i++)
{
DbgPrint(( " %02x", Key1Data[i] ));
}
DbgPrint(( "\n" ));
#endif
//4.3.4 Send KEY1 data to the decoder board
if (CHIPCSSSendKey1( Key1Data ) == CHIPCSS_FAILURE)
{
DbgPrint(( " *** ERROR, CANOT SEND KEY1 DATA\n" ));
return( CSS_FAILURE );
}
//4.3.5 Acquire Challenge Data from the DVD-ROM drive
if (LoaderGetChallenge(tDev, bAgid, DVDChallData) != LOADER_SUCCESS)
{
DbgPrint(( " *** ERROR, CANNOT READ CHALLENGE DATA FROM DVD-ROM\n" ));
return( CSS_FAILURE );
}
#if DEBUG_CSS
DbgPrint(( " DVDChallData[] =" ));
for( i=0; i<sizeof(DVDChallData); i++ )
{
DbgPrint(( " %02x", DVDChallData[i] ));
}
DbgPrint(( "\n" ));
#endif
//4.3.6 Send Challenge data and generate KEY2 in the DVD decoder board
if (CHIPCSSGetKey2( DVDChallData, Key2Data ) == CHIPCSS_FAILURE)
{
DbgPrint(( " *** ERROR, CANNOT GET KEY2 DATA\n" ));
return( CSS_FAILURE );
}
#if DEBUG_CSS
DbgPrint(( " Key2Data[] =" ));
for( i=0; i<sizeof(Key2Data); i++ )
{
DbgPrint(( " %02x", Key2Data[i] ));
}
DbgPrint(( "\n" ));
#endif
//4.3.7 Send KEY2 to the DVD-ROM drive and finish authentication
if (LoaderSendKey2(tDev, bAgid, Key2Data) != LOADER_SUCCESS)
{
DbgPrint(( " *** ERROR, CANNOT SEND KEY2 DATA TO DVD-ROM\n" ));
return( CSS_FAILURE );
}
DbgPrint(("CSSAuthenticate sucesfull\n"));
return( CSS_SUCCESS );
} /* end CSSAuthenticate() */
/************************************************************************/
/************************************************************************/
/** **/
/************************************************************************/
/************************************************************************/
CSS_ERROR CSSGetDiskKey( LOADER_HANDLE tDev, BYTE *pbData )
{
BYTE bASF;
/* verify input */
if (NULL == tDev)
{
DbgPrint(("%s: loader is NULL\n", __FUNCTION__));
return (CSS_FAILURE);
}
if (NULL == pbData)
{
DbgPrint(("%s: data buffer is NULL\n", __FUNCTION__));
return (CSS_FAILURE);
}
/* Authenticate the keys */
if (CSSAuthenticate( tDev ) == CSS_FAILURE)
{
DbgPrint(( " *** ERROR, CAN NOT AUTHENTICATE\n" ));
LoaderInvalidateAgid(tDev, bAgid);
return (CSS_FAILURE);
}
/* Get the disk key */
if (LoaderReadDiscKey(tDev, bAgid, pbData) != LOADER_SUCCESS)
{
DbgPrint(( " *** ERROR, CAN NOT GET DISK KEY FROM DVD-ROM\n" ));
LoaderInvalidateAgid(tDev, bAgid);
return (CSS_FAILURE);
}
if (CHIPCSSUnencryptDiskKey( pbData ) == CHIPCSS_FAILURE)
{
DbgPrint(( " *** ERROR, CAN NOT UNENCRYPT DISK KEY\n" ));
LoaderInvalidateAgid(tDev, bAgid);
return (CSS_FAILURE);
}
if (LoaderGetASF(tDev, bAgid, &bASF) != LOADER_SUCCESS)
{
DbgPrint(( " *** ERROR, CANNOT VERIFY DISK KEY STRUCTURE\n" ));
return( CSS_FAILURE );
}
#if DEBUG_CSS
DbgPrint((" ASF = %d\n", bASF));
#endif
DbgPrint(("CSSGetDiskKey sucesfull\n"));
return (CSS_SUCCESS);
}
/************************************************************************/
/************************************************************************/
/** **/
/************************************************************************/
/************************************************************************/
CSS_ERROR CSSGetTitleKey(LOADER_HANDLE tDev, ULONG ulLBA, BYTE *pbKey, BYTE *pbKeySize)
{
#if DEBUG_CSS
int i;
#endif
BYTE bTitleKey[5];
/* verify input */
if (NULL == tDev)
{
DbgPrint(("%s: loader is NULL\n", __FUNCTION__));
return (CSS_FAILURE);
}
if (NULL == pbKey)
{
DbgPrint(("%s: key buffer is NULL\n", __FUNCTION__));
return (CSS_FAILURE);
}
/* Authenticate the keys */
if (CSSAuthenticate(tDev) == CSS_FAILURE)
{
DbgPrint(( " *** ERROR, CAN NOT AUTHENTICATE\n" ));
return (CSS_FAILURE);
}
/* Get the title key */
if (LoaderReadTitleKey(tDev, bAgid, ulLBA, bTitleKey) != LOADER_SUCCESS)
{
DbgPrint(( " *** ERROR, CAN NOT GET TITLE KEY FROM DVD-ROM\n" ));
return (CSS_FAILURE);
}
#if DEBUG_CSS
DbgPrint(( " bTitleKey =" ));
for( i=0; i<sizeof(bTitleKey); i++ )
{
DbgPrint(( " %02x", bTitleKey[i] ));
}
DbgPrint(( "\n" ));
#endif
if (CHIPCSSUnencryptTitleKey(bTitleKey, pbKey) == CHIPCSS_FAILURE)
{
DbgPrint(( " *** ERROR, CAN NOT UNENCRYPT TITLE KEY\n" ));
}
#if DEBUG_CSS
DbgPrint(( " pbKey =" ));
for (i=0; i<5; i++)
{
DbgPrint(( " %02x", pbKey[i] ));
}
DbgPrint(( "\n" ));
#endif
*pbKeySize = CSS_KEY_SIZE;
DbgPrint(("CSSGetTitleKey sucesfull\n"));
return (CSS_SUCCESS);
} /* end CSSGetTitleKey() */
CSS_ERROR CSSDescramble (BYTE *pbSector, BYTE* pbKey )
{
BYTE sectorIsEncrypted;
sectorIsEncrypted = pbSector[20] & 0x30;
if ((sectorIsEncrypted) != 0)
{
return( CHIPCSSDescramble(pbSector, pbKey));
}
return CSS_SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -