Code:
// Processing Key
static unsigned char processing_key[16] = {0x09,0xF9,0x11,0x02,0x9D,0x74,0xE3,0x5B,0xD8,0x41,0x56,0xC5,0x63,0x56,0x88,0xC0};
// Encrypted C Value
static unsigned char encrypted_c_value[16] = {0x6D,0x02,0xCA,0xC6,0x7B,0x1A,0x7E,0x95,0xC2,0x16,0xEF,0xD4,0xC9,0x28,0x09,0xCF};
//Decrypted C Value
static unsigned char decrypted_c_value[16];
static unsigned char uv[4] = {0x00,0x00,0x00,0x01};
// Media Key
static unsigned char media_key[16];
//Encrypted Verification Data (King Kong)
static unsigned char encrypted_verification_data[16] = {0x87,0xB8,0xA2,0xB7,0xC1,0x0B,0x9F,0xAD,0xF8,0xC4,0x36,0x1E,0x23,0x86,0x59,0xE5};
//Decrypted Verification Data Should Be
static unsigned char decrypted_verification_data_should_be[8] = {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
//Decrypted Verification Data
static unsigned char decrypted_verification_data[16];
// Volume ID
static unsigned char volume_id[16] = {0x40,0x00,0x09,0x18,0x20,0x06,0x08,0x41,0x00,0x20,0x20,0x20,0x20,0x20,0x00,0x00};
//Decrypted Volume ID
static unsigned char decrypted_volumeid[16];
//Volume Unique Key
static unsigned char volume_unqiue_key[16];
// First decrypt the C-value with the processing key
oRijndael.MakeKey((char *)processing_key, CRijndael::sm_chain0, 16, 16);
oRijndael.DecryptBlock((char *)encrypted_c_value, (char *)decrypted_c_value);
// Then XOR it with with the uv (of the corresponding C-value)
for (j = 0; j < 16; j++)
{
if (j < 12)
{
media_key[j] = decrypted_c_value[j];
}
else
{
media_key[j] = decrypted_c_value[j]^uv[j-12];
}
}
// Then check if the resulting media key is correct using the verify media key record
oRijndael.MakeKey((char *)media_key, CRijndael::sm_chain0, 16, 16);
oRijndael.DecryptBlock((char *)encrypted_verification_data, (char *)decrypted_verification_data);
if (!memcmp(decrypted_verification_data_should_be, decrypted_verification_data, 8))
{
for (j = 0; j < 16; j++)
{
printf("%02X ", decrypted_verification_data[j]);
}
}
printf("\n");
// Then do a AES-G (basicly a decrypt and an XOR) on the media key + volumeID
oRijndael.MakeKey((char *)media_key, CRijndael::sm_chain0, 16, 16);
oRijndael.DecryptBlock((char *)volume_id, (char *)decrypted_volumeid);
for (j = 0; j < 16; j++)
{
volume_unqiue_key[j] = volume_id[j]^decrypted_volumeid[j];
}
printf("\n");
// This results in the Volume Unique Key
for (j = 0; j < 16; j++)
{
printf("%02X ", volume_unqiue_key[j]);
}
printf("\n");