* remember the ticket decrypted key and dont calculate it every time it is requested

This commit is contained in:
giantpune@gmail.com 2010-12-22 19:19:12 +00:00
parent 30f8070e81
commit 374699c434
4 changed files with 28 additions and 20 deletions

View File

@ -214,6 +214,23 @@ Ticket::Ticket( QByteArray stuff )
return;
SetPointer();
quint8 iv[ 16 ];
quint8 keyin[ 16 ];
quint8 keyout[ 16 ];
quint8 commonkey[ 16 ] = COMMON_KEY;
quint8 *enc_key = (quint8 *)&p_tik->cipher_title_key;
memcpy( keyin, enc_key, sizeof keyin );
memset( keyout, 0, sizeof keyout );
memset( iv, 0, sizeof iv);
memcpy( iv, &p_tik->titleid, sizeof p_tik->titleid );
aes_set_key( commonkey );
aes_decrypt( iv, keyin, keyout, sizeof( keyin ) );
decKey = QByteArray( (const char*)&keyout, 16 );
if( (quint32)data.size() != SignedSize() )
{
data.resize( SignedSize() );
@ -232,29 +249,17 @@ bool Ticket::SetTid( quint64 tid )
{
if( !p_tik )
return false;
//hexdump( data, payLoadOffset, data.size() - payLoadOffset );
p_tik->titleid = qFromBigEndian( tid );
quint64 t = qFromBigEndian( tid );
p_tik->titleid = t;
//hexdump( data, payLoadOffset, data.size() - payLoadOffset );
return true;
}
QByteArray Ticket::DecryptedKey()
{
quint8 iv[ 16 ];
quint8 keyin[ 16 ];
quint8 keyout[ 16 ];
static quint8 commonkey[ 16 ] = COMMON_KEY;
quint8 *enc_key = (quint8 *)&p_tik->cipher_title_key;
memcpy( keyin, enc_key, sizeof keyin );
memset( keyout, 0, sizeof keyout );
memset( iv, 0, sizeof iv);
memcpy( iv, &p_tik->titleid, sizeof p_tik->titleid );
aes_set_key( commonkey );
aes_decrypt( iv, keyin, keyout, sizeof( keyin ) );
return QByteArray( (const char*)&keyout, 16 );
return decKey;
}
quint32 Ticket::SignedSize()
@ -274,7 +279,7 @@ void Ticket::SetPointer()
else if( data.startsWith( "\x0\x1\x0\x2" ) )
payLoadOffset = sizeof( sig_ecdsa );
p_tik = (tik*)((quint8*)data.data() + payLoadOffset);
p_tik = (tik*)((quint8*)(data.data()) + payLoadOffset);
}
bool Ticket::FakeSign()

View File

@ -160,6 +160,7 @@ private:
//let data hold the entire tik data
QByteArray data;
QByteArray decKey;
//point the p_tik to the spot in "data" we want
void SetPointer();

View File

@ -94,7 +94,8 @@ QByteArray PaddedByteArray( const QByteArray &orig, quint32 padTo )
QByteArray AesDecrypt( quint16 index, const QByteArray source )
{
static quint8 iv[ 16 ];
//qDebug() << "AesDecrypt" << hex << index << source.size();
quint8 iv[ 16 ];
quint16 beidx = qFromBigEndian( index );
memset( iv, 0, 16 );
@ -118,6 +119,7 @@ QByteArray AesEncrypt( quint16 index, const QByteArray source )
void AesSetKey( const QByteArray key )
{
// qDebug() << "AesSetKey()" << key.toHex();
aes_set_key( (const quint8*)key.data() );
}

View File

@ -574,7 +574,7 @@ bool MainWindow::InstallNUSItem( NusJob job )
{
//nand.WriteMetaData();
UpdateTree();
ShowMessage( tr( "Deleted old TMD and private contents for\n%1" ).arg( title ) );
ShowMessage( tr( "Deleted old TMD and private contents for<br>%1" ).arg( title ) );
}
cnt = t.Count();