Exemplo n.º 1
0
bool CDVDSession::GetTitleKey(int lba, BYTE* pKey)
{
    if (m_session == DVD_END_ALL_SESSIONS) {
        return false;
    }

    if (!ReadKey(DvdTitleKey, pKey, lba)) {
        return false;
    }

    if (!(pKey[0] | pKey[1] | pKey[2] | pKey[3] | pKey[4])) {
        return false;
    }

    pKey[5] = 0;

    CSStitlekey(pKey, m_DiscKey);

    return true;
}
Exemplo n.º 2
0
STDMETHODIMP CDeCSSInputPin::Set(REFGUID PropSet, ULONG Id, LPVOID pInstanceData, ULONG InstanceLength, LPVOID pPropertyData, ULONG DataLength)
{
    if (PropSet != AM_KSPROPSETID_CopyProt) {
        return E_NOTIMPL;
    }

    switch (Id) {
    case AM_PROPERTY_COPY_MACROVISION:
        break;
    case AM_PROPERTY_DVDCOPY_CHLG_KEY: { // 3. auth: receive drive nonce word, also store and encrypt the buskey made up of the two nonce words
        AM_DVDCOPY_CHLGKEY* pChlgKey = (AM_DVDCOPY_CHLGKEY*)pPropertyData;
        for (int i = 0; i < 10; i++) {
            m_Challenge[i] = pChlgKey->ChlgKey[9 - i];
        }

        CSSkey2(m_varient, m_Challenge, &m_Key[5]);

        CSSbuskey(m_varient, m_Key, m_KeyCheck);
    }
    break;
    case AM_PROPERTY_DVDCOPY_DISC_KEY: { // 5. receive the disckey
        AM_DVDCOPY_DISCKEY* pDiscKey = (AM_DVDCOPY_DISCKEY*)pPropertyData; // pDiscKey->DiscKey holds the disckey encrypted with itself and the 408 disckeys encrypted with the playerkeys

        bool fSuccess = false;

        for (int j = 0; j < g_nPlayerKeys; j++) {
            for (int k = 1; k < 409; k++) {
                BYTE DiscKey[6];
                for (int i = 0; i < 5; i++) {
                    DiscKey[i] = pDiscKey->DiscKey[k * 5 + i] ^ m_KeyCheck[4 - i];
                }
                DiscKey[5] = 0;

                CSSdisckey(DiscKey, g_PlayerKeys[j]);

                BYTE Hash[6];
                for (int i = 0; i < 5; i++) {
                    Hash[i] = pDiscKey->DiscKey[i] ^ m_KeyCheck[4 - i];
                }
                Hash[5] = 0;

                CSSdisckey(Hash, DiscKey);

                if (!memcmp(Hash, DiscKey, 6)) {
                    memcpy(m_DiscKey, DiscKey, 6);
                    j = g_nPlayerKeys;
                    fSuccess = true;
                    break;
                }
            }
        }

        if (!fSuccess) {
            return E_FAIL;
        }
    }
    break;
    case AM_PROPERTY_DVDCOPY_DVD_KEY1: { // 2. auth: receive our drive-encrypted nonce word and decrypt it for verification
        AM_DVDCOPY_BUSKEY* pKey1 = (AM_DVDCOPY_BUSKEY*)pPropertyData;
        for (int i = 0; i < 5; i++) {
            m_Key[i] =  pKey1->BusKey[4 - i];
        }

        m_varient = -1;

        for (int i = 31; i >= 0; i--) {
            CSSkey1(i, m_Challenge, m_KeyCheck);

            if (memcmp(m_KeyCheck, &m_Key[0], 5) == 0) {
                m_varient = i;
            }
        }
    }
    break;
    case AM_PROPERTY_DVDCOPY_REGION:
        break;
    case AM_PROPERTY_DVDCOPY_SET_COPY_STATE:
        break;
    case AM_PROPERTY_DVDCOPY_TITLE_KEY: { // 6. receive the title key and decrypt it with the disc key
        AM_DVDCOPY_TITLEKEY* pTitleKey = (AM_DVDCOPY_TITLEKEY*)pPropertyData;
        for (int i = 0; i < 5; i++) {
            m_TitleKey[i] = pTitleKey->TitleKey[i] ^ m_KeyCheck[4 - i];
        }
        m_TitleKey[5] = 0;
        CSStitlekey(m_TitleKey, m_DiscKey);
    }
    break;
    default:
        return E_PROP_ID_UNSUPPORTED;
    }

    return S_OK;
}